mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-05 22:56:11 +00:00
fix: mac os crashes (#2385)
# Summary Fix some crashes on MacOS * patch `reanimated` * update fabric type * invert axis in `FeOffset`
This commit is contained in:
@@ -34,16 +34,12 @@ using namespace facebook::react;
|
||||
const auto &newProps = static_cast<const RNSVGFeMergeProps &>(*props);
|
||||
|
||||
if (newProps.nodes.size() > 0) {
|
||||
NSMutableArray *nodesArray = [NSMutableArray new];
|
||||
NSMutableArray<NSString *> *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<RNSVGFeMergeProps const>(props);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#import "RNSVGFeOffset.h"
|
||||
#if TARGET_OS_OSX
|
||||
#import "RNSVGRenderUtils.h"
|
||||
#endif
|
||||
|
||||
#ifdef RCT_NEW_ARCH_ENABLED
|
||||
#import <React/RCTConversions.h>
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<RetainingShareable<ShareableObject>>(
|
||||
- rt, object, nativeStateSource);
|
||||
+ rt,
|
||||
+ object
|
||||
+#if SUPPORTS_NATIVE_STATE
|
||||
+ ,
|
||||
+ nativeStateSource
|
||||
+#endif // SUPPORTS_NATIVE_STATE
|
||||
+ );
|
||||
} else {
|
||||
- shareable =
|
||||
- std::make_shared<ShareableObject>(rt, object, nativeStateSource);
|
||||
+ shareable = std::make_shared<ShareableObject>(
|
||||
+ 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<std::pair<std::string, std::shared_ptr<Shareable>>> data_;
|
||||
+#if SUPPORTS_NATIVE_STATE
|
||||
#if REACT_NATIVE_MINOR_VERSION >= 71
|
||||
std::shared_ptr<jsi::NativeState> nativeState_;
|
||||
#endif
|
||||
+#endif // SUPPORTS_NATIVE_STATE
|
||||
};
|
||||
|
||||
class ShareableHostObject : public Shareable {
|
||||
|
||||
Reference in New Issue
Block a user