From f82a0265e22088140802ae3c1dd0ce7d2bdffe8b Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Mon, 26 Sep 2022 16:15:59 +0200 Subject: [PATCH] feat: update props field so rea works correctly (#1880) PR adding update of _props after updateProps method in order for e.g. react-native-reanimated to pick correct props when running updates. Coauthored by @tomekzaw. It is needed since RCTMountingManager reads this field as oldProps: facebook/react-native@10e47b8/React/Fabric/Mounting/RCTMountingManager.mm#L306 --- .../horcrux/svg/RenderableViewManager.java | 22 ++++++++++++------- apple/Elements/RNSVGClipPath.mm | 1 + apple/Elements/RNSVGForeignObject.mm | 1 + apple/Elements/RNSVGGroup.mm | 1 + apple/Elements/RNSVGImage.mm | 1 + apple/Elements/RNSVGLinearGradient.mm | 1 + apple/Elements/RNSVGMarker.mm | 1 + apple/Elements/RNSVGMask.mm | 1 + apple/Elements/RNSVGPath.mm | 1 + apple/Elements/RNSVGPattern.mm | 1 + apple/Elements/RNSVGRadialGradient.mm | 1 + apple/Elements/RNSVGSvgView.mm | 1 + apple/Elements/RNSVGSymbol.mm | 1 + apple/Elements/RNSVGUse.mm | 1 + apple/Shapes/RNSVGCircle.mm | 1 + apple/Shapes/RNSVGEllipse.mm | 1 + apple/Shapes/RNSVGLine.mm | 1 + apple/Shapes/RNSVGRect.mm | 1 + apple/Text/RNSVGTSpan.mm | 1 + apple/Text/RNSVGText.mm | 1 + apple/Text/RNSVGTextPath.mm | 1 + 21 files changed, 34 insertions(+), 8 deletions(-) diff --git a/android/src/main/java/com/horcrux/svg/RenderableViewManager.java b/android/src/main/java/com/horcrux/svg/RenderableViewManager.java index 879603ea..72180eeb 100644 --- a/android/src/main/java/com/horcrux/svg/RenderableViewManager.java +++ b/android/src/main/java/com/horcrux/svg/RenderableViewManager.java @@ -488,20 +488,26 @@ class VirtualViewManager extends ViewGroupManager(props); setCommonNodeProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Elements/RNSVGForeignObject.mm b/apple/Elements/RNSVGForeignObject.mm index 23166e0d..efe93dc7 100644 --- a/apple/Elements/RNSVGForeignObject.mm +++ b/apple/Elements/RNSVGForeignObject.mm @@ -57,6 +57,7 @@ using namespace facebook::react; } setCommonGroupProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Elements/RNSVGGroup.mm b/apple/Elements/RNSVGGroup.mm index 5afb43c2..880b0671 100644 --- a/apple/Elements/RNSVGGroup.mm +++ b/apple/Elements/RNSVGGroup.mm @@ -46,6 +46,7 @@ using namespace facebook::react; const auto &newProps = *std::static_pointer_cast(props); setCommonGroupProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Elements/RNSVGImage.mm b/apple/Elements/RNSVGImage.mm index f16a7a53..ca06d772 100644 --- a/apple/Elements/RNSVGImage.mm +++ b/apple/Elements/RNSVGImage.mm @@ -93,6 +93,7 @@ using namespace facebook::react; self.meetOrSlice = intToRNSVGVBMOS(newProps.meetOrSlice); setCommonRenderableProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Elements/RNSVGLinearGradient.mm b/apple/Elements/RNSVGLinearGradient.mm index 01315068..0d72e198 100644 --- a/apple/Elements/RNSVGLinearGradient.mm +++ b/apple/Elements/RNSVGLinearGradient.mm @@ -65,6 +65,7 @@ using namespace facebook::react; } setCommonNodeProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Elements/RNSVGMarker.mm b/apple/Elements/RNSVGMarker.mm index 8fa4ff0e..3d7d38e9 100644 --- a/apple/Elements/RNSVGMarker.mm +++ b/apple/Elements/RNSVGMarker.mm @@ -59,6 +59,7 @@ using namespace facebook::react; self.meetOrSlice = intToRNSVGVBMOS(newProps.meetOrSlice); setCommonGroupProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Elements/RNSVGMask.mm b/apple/Elements/RNSVGMask.mm index ba185802..7c58b13b 100644 --- a/apple/Elements/RNSVGMask.mm +++ b/apple/Elements/RNSVGMask.mm @@ -64,6 +64,7 @@ using namespace facebook::react; } setCommonGroupProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Elements/RNSVGPath.mm b/apple/Elements/RNSVGPath.mm index fbe8a6e7..6e829341 100644 --- a/apple/Elements/RNSVGPath.mm +++ b/apple/Elements/RNSVGPath.mm @@ -45,6 +45,7 @@ using namespace facebook::react; self.d = [[RNSVGPathParser alloc] initWithPathString:RCTNSStringFromString(newProps.d)]; setCommonRenderableProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Elements/RNSVGPattern.mm b/apple/Elements/RNSVGPattern.mm index 0ba9efcc..3bd7a053 100644 --- a/apple/Elements/RNSVGPattern.mm +++ b/apple/Elements/RNSVGPattern.mm @@ -70,6 +70,7 @@ using namespace facebook::react; self.meetOrSlice = intToRNSVGVBMOS(newProps.meetOrSlice); setCommonGroupProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Elements/RNSVGRadialGradient.mm b/apple/Elements/RNSVGRadialGradient.mm index f4eca2ff..3865aa54 100644 --- a/apple/Elements/RNSVGRadialGradient.mm +++ b/apple/Elements/RNSVGRadialGradient.mm @@ -65,6 +65,7 @@ using namespace facebook::react; } setCommonNodeProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Elements/RNSVGSvgView.mm b/apple/Elements/RNSVGSvgView.mm index 7089f8ba..67cc1336 100644 --- a/apple/Elements/RNSVGSvgView.mm +++ b/apple/Elements/RNSVGSvgView.mm @@ -78,6 +78,7 @@ using namespace facebook::react; if (RCTUIColorFromSharedColor(newProps.color)) { self.tintColor = RCTUIColorFromSharedColor(newProps.color); } + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Elements/RNSVGSymbol.mm b/apple/Elements/RNSVGSymbol.mm index 182f8ad8..4fef56d6 100644 --- a/apple/Elements/RNSVGSymbol.mm +++ b/apple/Elements/RNSVGSymbol.mm @@ -49,6 +49,7 @@ using namespace facebook::react; self.meetOrSlice = intToRNSVGVBMOS(newProps.meetOrSlice); setCommonGroupProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Elements/RNSVGUse.mm b/apple/Elements/RNSVGUse.mm index 1d816deb..15b3d496 100644 --- a/apple/Elements/RNSVGUse.mm +++ b/apple/Elements/RNSVGUse.mm @@ -53,6 +53,7 @@ using namespace facebook::react; self.href = RCTNSStringFromStringNilIfEmpty(newProps.href); setCommonRenderableProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Shapes/RNSVGCircle.mm b/apple/Shapes/RNSVGCircle.mm index 39a0ed46..3040ae9d 100644 --- a/apple/Shapes/RNSVGCircle.mm +++ b/apple/Shapes/RNSVGCircle.mm @@ -47,6 +47,7 @@ using namespace facebook::react; self.r = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.r)]; setCommonRenderableProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Shapes/RNSVGEllipse.mm b/apple/Shapes/RNSVGEllipse.mm index 245ba42a..3b627e3a 100644 --- a/apple/Shapes/RNSVGEllipse.mm +++ b/apple/Shapes/RNSVGEllipse.mm @@ -48,6 +48,7 @@ using namespace facebook::react; self.ry = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.ry)]; setCommonRenderableProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Shapes/RNSVGLine.mm b/apple/Shapes/RNSVGLine.mm index 3a2cc691..542ed047 100644 --- a/apple/Shapes/RNSVGLine.mm +++ b/apple/Shapes/RNSVGLine.mm @@ -48,6 +48,7 @@ using namespace facebook::react; self.y2 = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y2)]; setCommonRenderableProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Shapes/RNSVGRect.mm b/apple/Shapes/RNSVGRect.mm index b740e250..7ee4e0ba 100644 --- a/apple/Shapes/RNSVGRect.mm +++ b/apple/Shapes/RNSVGRect.mm @@ -54,6 +54,7 @@ using namespace facebook::react; self.ry = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.ry)]; setCommonRenderableProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Text/RNSVGTSpan.mm b/apple/Text/RNSVGTSpan.mm index e1b2a8bb..64722dfb 100644 --- a/apple/Text/RNSVGTSpan.mm +++ b/apple/Text/RNSVGTSpan.mm @@ -63,6 +63,7 @@ using namespace facebook::react; self.content = RCTNSStringFromStringNilIfEmpty(newProps.content); setCommonTextProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Text/RNSVGText.mm b/apple/Text/RNSVGText.mm index c8fc2131..5f789149 100644 --- a/apple/Text/RNSVGText.mm +++ b/apple/Text/RNSVGText.mm @@ -52,6 +52,7 @@ using namespace facebook::react; const auto &newProps = *std::static_pointer_cast(props); setCommonTextProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle diff --git a/apple/Text/RNSVGTextPath.mm b/apple/Text/RNSVGTextPath.mm index c75fbd07..443d07a4 100644 --- a/apple/Text/RNSVGTextPath.mm +++ b/apple/Text/RNSVGTextPath.mm @@ -49,6 +49,7 @@ using namespace facebook::react; self.startOffset = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.startOffset)]; setCommonTextProps(newProps, self); + _props = std::static_pointer_cast(props); } - (void)prepareForRecycle