From d1d936a834444fb86307cd174b5c051e3fcdaf19 Mon Sep 17 00:00:00 2001 From: Jakub Grzywacz Date: Wed, 20 Nov 2024 10:42:39 +0100 Subject: [PATCH] fix: resolve transforms on new architecture (#2542) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 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 | ✅ | --- apple/RNSVGNode.mm | 10 ++++++++++ apple/Utils/RNSVGFabricConversions.h | 5 ++++- apple/ViewManagers/RNSVGNodeManager.mm | 1 - 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apple/RNSVGNode.mm b/apple/RNSVGNode.mm index 444f54179..6dfa3a125 100644 --- a/apple/RNSVGNode.mm +++ b/apple/RNSVGNode.mm @@ -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)) { diff --git a/apple/Utils/RNSVGFabricConversions.h b/apple/Utils/RNSVGFabricConversions.h index cf625ac40..ffdb06997 100644 --- a/apple/Utils/RNSVGFabricConversions.h +++ b/apple/Utils/RNSVGFabricConversions.h @@ -55,6 +55,8 @@ static id RNSVGConvertFollyDynamicToId(const folly::dynamic &dyn) } } +static const facebook::react::LayoutMetrics MinimalLayoutMetrics = {{{0, 0}, {1, 1}}}; + template void setCommonNodeProps(const T &nodeProps, RNSVGNode *node) { @@ -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; diff --git a/apple/ViewManagers/RNSVGNodeManager.mm b/apple/ViewManagers/RNSVGNodeManager.mm index 0535eebce..7a483687c 100644 --- a/apple/ViewManagers/RNSVGNodeManager.mm +++ b/apple/ViewManagers/RNSVGNodeManager.mm @@ -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)