diff --git a/packages/react-native-reanimated/Common/cpp/SharedItems/Shareables.cpp b/packages/react-native-reanimated/Common/cpp/SharedItems/Shareables.cpp index ae3a6109bf56..edde6ff9aafc 100644 --- a/packages/react-native-reanimated/Common/cpp/SharedItems/Shareables.cpp +++ b/packages/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()) { @@ -198,11 +210,14 @@ 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 (object.hasNativeState(rt)) { nativeState_ = object.getNativeState(rt); } +#endif // SUPPORTS_NATIVE_STATE } +#if SUPPORTS_NATIVE_STATE ShareableObject::ShareableObject( jsi::Runtime &rt, const jsi::Object &object, @@ -213,16 +228,18 @@ ShareableObject::ShareableObject( nativeState_ = nativeStateSource.asObject(rt).getNativeState(rt); } } +#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->toJSValue(rt)); + obj.setProperty(rt, data_[i].first.c_str(), data_[i].second->toJSValue(rt)); } +#if SUPPORTS_NATIVE_STATE if (nativeState_ != nullptr) { obj.setNativeState(rt, nativeState_); } +#endif // SUPPORTS_NATIVE_STATE return obj; } diff --git a/packages/react-native-reanimated/Common/cpp/SharedItems/Shareables.h b/packages/react-native-reanimated/Common/cpp/SharedItems/Shareables.h index 18deb29693dc..f94ec731a34e 100644 --- a/packages/react-native-reanimated/Common/cpp/SharedItems/Shareables.h +++ b/packages/react-native-reanimated/Common/cpp/SharedItems/Shareables.h @@ -178,16 +178,26 @@ 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 std::shared_ptr nativeState_; +#endif // SUPPORTS_NATIVE_STATE }; class ShareableHostObject : public Shareable { diff --git a/packages/react-native-reanimated/scripts/cpplint.sh b/packages/react-native-reanimated/scripts/cpplint.sh index c77ac25bbc02..682b6037835d 100755 --- a/packages/react-native-reanimated/scripts/cpplint.sh +++ b/packages/react-native-reanimated/scripts/cpplint.sh @@ -1,7 +1,7 @@ #!/bin/bash if which cpplint >/dev/null; then - cpplint --linelength=230 --filter=-legal/copyright,-readability/todo,-build/namespaces,-whitespace/comments,-build/c++11,-runtime/references --quiet --recursive Common/cpp android/src/main/cpp + cpplint --linelength=230 --filter=-legal/copyright,-readability/todo,-build/namespaces,-whitespace/comments,-whitespace/parens,-build/c++11,-runtime/references --quiet --recursive Common/cpp android/src/main/cpp else echo "error: cpplint not installed, download from https://github.com/cpplint/cpplint" 1>&2 exit 1