Skip to content

Commit

Permalink
fix: resolve transforms on new architecture (#2542)
Browse files Browse the repository at this point in the history
# Summary

Add `resolveTransforms` on `updateProps` to get correct matrix. It will
improve animating transformations, as Animated/Reanimated skips JS
`processTransform` and passes transformations directly.

## Test Plan

Animate `transform` prop in react-native style.

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |    ✅      |
| MacOS   |    ✅      |
  • Loading branch information
jakex7 authored Nov 20, 2024
1 parent 74b77a6 commit d1d936a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions apple/RNSVGNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ - (void)setMatrix:(CGAffineTransform)matrix
}
}

- (void)setTransforms:(CGAffineTransform)transforms
{
if (CGAffineTransformEqualToTransform(transforms, _transforms)) {
return;
}

_transforms = transforms;
[self invalidate];
}

- (void)setClientRect:(CGRect)clientRect
{
if (CGRectEqualToRect(_clientRect, clientRect)) {
Expand Down
5 changes: 4 additions & 1 deletion apple/Utils/RNSVGFabricConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ static id RNSVGConvertFollyDynamicToId(const folly::dynamic &dyn)
}
}

static const facebook::react::LayoutMetrics MinimalLayoutMetrics = {{{0, 0}, {1, 1}}};

template <typename T>
void setCommonNodeProps(const T &nodeProps, RNSVGNode *node)
{
Expand All @@ -69,7 +71,8 @@ void setCommonNodeProps(const T &nodeProps, RNSVGNode *node)
nodeProps.matrix.at(4),
nodeProps.matrix.at(5));
}
CATransform3D transform3d = RCTCATransform3DFromTransformMatrix(nodeProps.transform);
auto newTransform = nodeProps.resolveTransform(MinimalLayoutMetrics);
CATransform3D transform3d = RCTCATransform3DFromTransformMatrix(newTransform);
CGAffineTransform transform = CATransform3DGetAffineTransform(transform3d);
node.invTransform = CGAffineTransformInvert(transform);
node.transforms = transform;
Expand Down
1 change: 0 additions & 1 deletion apple/ViewManagers/RNSVGNodeManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ - (RNSVGPlatformView *)view
CGAffineTransform transform = CATransform3DGetAffineTransform(transform3d);
view.invTransform = CGAffineTransformInvert(transform);
view.transforms = transform;
[view invalidate];
}
RCT_EXPORT_VIEW_PROPERTY(mask, NSString)
RCT_EXPORT_VIEW_PROPERTY(markerStart, NSString)
Expand Down

0 comments on commit d1d936a

Please sign in to comment.