Skip to content

Commit

Permalink
Fix "Not implemented" exception with macros (#6137)
Browse files Browse the repository at this point in the history
Supersedes 🚽 #6028

Fixes #5974
  • Loading branch information
tjzel authored Jul 1, 2024
1 parent 21cc137 commit 90fe8d3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<std::string, std::shared_ptr<Shareable>>> data_;
#if SUPPORTS_NATIVE_STATE
std::shared_ptr<jsi::NativeState> nativeState_;
#endif // SUPPORTS_NATIVE_STATE
};

class ShareableHostObject : public Shareable {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-reanimated/scripts/cpplint.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 90fe8d3

Please sign in to comment.