From cec99a50351a558f40666e06b5010b57f757896c Mon Sep 17 00:00:00 2001 From: Jakub Grzywacz Date: Wed, 31 Jul 2024 16:27:35 +0200 Subject: [PATCH] fix: mac os crashes (#2385) # Summary Fix some crashes on MacOS * patch `reanimated` * update fabric type * invert axis in `FeOffset` --- apple/Filters/RNSVGFeMerge.mm | 8 +- apple/Filters/RNSVGFeOffset.mm | 11 +- .../react-native-reanimated+3.9.0.patch | 116 ++++++++++++++++++ 3 files changed, 128 insertions(+), 7 deletions(-) diff --git a/apple/Filters/RNSVGFeMerge.mm b/apple/Filters/RNSVGFeMerge.mm index d3948b96..d32495fb 100644 --- a/apple/Filters/RNSVGFeMerge.mm +++ b/apple/Filters/RNSVGFeMerge.mm @@ -34,16 +34,12 @@ using namespace facebook::react; const auto &newProps = static_cast(*props); if (newProps.nodes.size() > 0) { - NSMutableArray *nodesArray = [NSMutableArray new]; + NSMutableArray *nodesArray = [NSMutableArray new]; for (auto node : newProps.nodes) { - id json = RNSVGConvertFollyDynamicToId(node); - if ([json isKindOfClass:[NSString class]]) { - [nodesArray addObject:[json stringValue]]; - } + [nodesArray addObject:[NSString stringWithCString:node.c_str() encoding:NSUTF8StringEncoding]]; } self.nodes = nodesArray; } - setCommonFilterProps(newProps, self); _props = std::static_pointer_cast(props); } diff --git a/apple/Filters/RNSVGFeOffset.mm b/apple/Filters/RNSVGFeOffset.mm index a550b6c1..987c8f73 100644 --- a/apple/Filters/RNSVGFeOffset.mm +++ b/apple/Filters/RNSVGFeOffset.mm @@ -1,4 +1,7 @@ #import "RNSVGFeOffset.h" +#if TARGET_OS_OSX +#import "RNSVGRenderUtils.h" +#endif #ifdef RCT_NEW_ARCH_ENABLED #import @@ -106,8 +109,14 @@ using namespace facebook::react; // reset ctm translation CGAffineTransform contextTransform = CGAffineTransformConcat(ctm, CGAffineTransformMakeTranslation(-ctm.tx, -ctm.ty)); - +#if !TARGET_OS_OSX // [macOS] CGPoint translate = CGPointMake(dx, dy); +#else + CGPoint translate = CGPointMake(dx, -dy); + CGFloat scale = [RNSVGRenderUtils getScreenScale]; + CGAffineTransform screenScaleCTM = CGAffineTransformMake(scale, 0, 0, scale, 0, 0); + translate = CGPointApplyAffineTransform(translate, screenScaleCTM); +#endif translate = CGPointApplyAffineTransform(translate, contextTransform); CGAffineTransform transform = CGAffineTransformMakeTranslation(translate.x, translate.y); diff --git a/fabric-macos-example/patches/react-native-reanimated+3.9.0.patch b/fabric-macos-example/patches/react-native-reanimated+3.9.0.patch index 79281a24..d567779c 100644 --- a/fabric-macos-example/patches/react-native-reanimated+3.9.0.patch +++ b/fabric-macos-example/patches/react-native-reanimated+3.9.0.patch @@ -14,3 +14,119 @@ index a1ace04..58d0303 100644 namespace reanimated { NativeReanimatedModule::NativeReanimatedModule( +diff --git a/node_modules/react-native-reanimated/Common/cpp/SharedItems/Shareables.cpp b/node_modules/react-native-reanimated/Common/cpp/SharedItems/Shareables.cpp +index a0e002b..761cc03 100644 +--- a/node_modules/react-native-reanimated/Common/cpp/SharedItems/Shareables.cpp ++++ b/node_modules/react-native-reanimated/Common/cpp/SharedItems/Shareables.cpp +@@ -78,10 +78,22 @@ jsi::Value makeShareableClone( + } else { + if (shouldRetainRemote.isBool() && shouldRetainRemote.getBool()) { + shareable = std::make_shared>( +- rt, object, nativeStateSource); ++ rt, ++ object ++#if SUPPORTS_NATIVE_STATE ++ , ++ nativeStateSource ++#endif // SUPPORTS_NATIVE_STATE ++ ); + } else { +- shareable = +- std::make_shared(rt, object, nativeStateSource); ++ shareable = std::make_shared( ++ rt, ++ object ++#if SUPPORTS_NATIVE_STATE ++ , ++ nativeStateSource ++#endif // SUPPORTS_NATIVE_STATE ++ ); + } + } + } else if (value.isString()) { +@@ -200,13 +212,16 @@ ShareableObject::ShareableObject(jsi::Runtime &rt, const jsi::Object &object) + auto value = extractShareableOrThrow(rt, object.getProperty(rt, key)); + data_.emplace_back(key.utf8(rt), value); + } ++#if SUPPORTS_NATIVE_STATE + #if REACT_NATIVE_MINOR_VERSION >= 71 + if (object.hasNativeState(rt)) { + nativeState_ = object.getNativeState(rt); + } + #endif ++#endif // SUPPORTS_NATIVE_STATE + } + ++#if SUPPORTS_NATIVE_STATE + ShareableObject::ShareableObject( + jsi::Runtime &rt, + const jsi::Object &object, +@@ -219,18 +234,20 @@ ShareableObject::ShareableObject( + } + #endif + } ++#endif // SUPPORTS_NATIVE_STATE + + jsi::Value ShareableObject::toJSValue(jsi::Runtime &rt) { + auto obj = jsi::Object(rt); + for (size_t i = 0, size = data_.size(); i < size; i++) { +- obj.setProperty( +- rt, data_[i].first.c_str(), data_[i].second->getJSValue(rt)); ++ obj.setProperty(rt, data_[i].first.c_str(), data_[i].second->toJSValue(rt)); + } ++#if SUPPORTS_NATIVE_STATE + #if REACT_NATIVE_MINOR_VERSION >= 71 + if (nativeState_ != nullptr) { + obj.setNativeState(rt, nativeState_); + } + #endif ++#endif // SUPPORTS_NATIVE_STATE + return obj; + } + +diff --git a/node_modules/react-native-reanimated/Common/cpp/SharedItems/Shareables.h b/node_modules/react-native-reanimated/Common/cpp/SharedItems/Shareables.h +index e61bc58..52c7a9e 100644 +--- a/node_modules/react-native-reanimated/Common/cpp/SharedItems/Shareables.h ++++ b/node_modules/react-native-reanimated/Common/cpp/SharedItems/Shareables.h +@@ -62,11 +62,9 @@ inline void cleanupIfRuntimeExists( + } + + class Shareable { +- protected: +- virtual jsi::Value toJSValue(jsi::Runtime &rt) = 0; +- + public: + virtual ~Shareable(); ++ virtual jsi::Value toJSValue(jsi::Runtime &rt) = 0; + + enum ValueType { + UndefinedType, +@@ -183,18 +181,28 @@ class ShareableObject : public Shareable { + public: + ShareableObject(jsi::Runtime &rt, const jsi::Object &object); + ++#if defined(USE_HERMES) || REACT_NATIVE_MINOR_VERSION >= 74 ++#define SUPPORTS_NATIVE_STATE 1 ++#else ++#define SUPPORTS_NATIVE_STATE 0 ++#endif ++ ++#if SUPPORTS_NATIVE_STATE + ShareableObject( + jsi::Runtime &rt, + const jsi::Object &object, + const jsi::Value &nativeStateSource); ++#endif // SUPPORTS_NATIVE_STATE + + jsi::Value toJSValue(jsi::Runtime &rt) override; + + protected: + std::vector>> data_; ++#if SUPPORTS_NATIVE_STATE + #if REACT_NATIVE_MINOR_VERSION >= 71 + std::shared_ptr nativeState_; + #endif ++#endif // SUPPORTS_NATIVE_STATE + }; + + class ShareableHostObject : public Shareable {