Skip to content

Commit

Permalink
Remove outdated code for unsupported React Native versions (#5979)
Browse files Browse the repository at this point in the history
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

This PR removes old code for unsupported React Native versions as well
as updates the minimal supported version for old and new architecture.
Reanimated 3.9.0+ supports only React Native 0.71+ (or 0.74+ when new
architecture is enabled).

## Test plan

<!-- Provide a minimal but complete code snippet that can be used to
test out this change along with instructions how to run it and a
description of the expected behavior. -->
  • Loading branch information
tomekzaw committed May 10, 2024
1 parent 9667e8b commit 325bd18
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 633 deletions.
18 changes: 0 additions & 18 deletions Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp
Expand Up @@ -45,19 +45,9 @@ class HermesExecutorRuntimeAdapter : public RuntimeAdapter {
thread_->quitSynchronous();
}

#if REACT_NATIVE_MINOR_VERSION >= 71
facebook::hermes::HermesRuntime &getRuntime() override {
return hermesRuntime_;
}
#else
facebook::jsi::Runtime &getRuntime() override {
return hermesRuntime_;
}

facebook::hermes::debugger::Debugger &getDebugger() override {
return hermesRuntime_.getDebugger();
}
#endif // REACT_NATIVE_MINOR_VERSION

// This is not empty in the original implementation, but we decided to tickle
// the runtime by running a small piece of code on every frame as using this
Expand All @@ -83,11 +73,7 @@ ReanimatedHermesRuntime::ReanimatedHermesRuntime(
#if HERMES_ENABLE_DEBUGGER
auto adapter =
std::make_unique<HermesExecutorRuntimeAdapter>(*runtime_, jsQueue);
#if REACT_NATIVE_MINOR_VERSION >= 71
debugToken_ = chrome::enableDebugging(std::move(adapter), name);
#else
chrome::enableDebugging(std::move(adapter), name);
#endif // REACT_NATIVE_MINOR_VERSION
#else
// This is required by iOS, because there is an assertion in the destructor
// that the thread was indeed `quit` before
Expand Down Expand Up @@ -127,11 +113,7 @@ ReanimatedHermesRuntime::ReanimatedHermesRuntime(
ReanimatedHermesRuntime::~ReanimatedHermesRuntime() {
#if HERMES_ENABLE_DEBUGGER
// We have to disable debugging before the runtime is destroyed.
#if REACT_NATIVE_MINOR_VERSION >= 71
chrome::disableDebugging(debugToken_);
#else
chrome::disableDebugging(*runtime_);
#endif // REACT_NATIVE_MINOR_VERSION
#endif // HERMES_ENABLE_DEBUGGER
}

Expand Down
2 changes: 0 additions & 2 deletions Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h
Expand Up @@ -138,9 +138,7 @@ class ReanimatedHermesRuntime
std::unique_ptr<facebook::hermes::HermesRuntime> runtime_;
ReanimatedReentrancyCheck reentrancyCheck_;
#if HERMES_ENABLE_DEBUGGER
#if REACT_NATIVE_MINOR_VERSION >= 71
chrome::DebugSessionToken debugToken_;
#endif // REACT_NATIVE_MINOR_VERSION >= 71
#endif // HERMES_ENABLE_DEBUGGER
};

Expand Down
4 changes: 0 additions & 4 deletions Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp
Expand Up @@ -11,11 +11,7 @@
#elif JS_RUNTIME_V8
#include <v8runtime/V8RuntimeFactory.h>
#else
#if REACT_NATIVE_MINOR_VERSION >= 71
#include <jsc/JSCRuntime.h>
#else
#include <jsi/JSCRuntime.h>
#endif // REACT_NATIVE_MINOR_VERSION
#endif // JS_RUNTIME

namespace reanimated {
Expand Down
10 changes: 0 additions & 10 deletions Common/cpp/SharedItems/Shareables.cpp
Expand Up @@ -94,10 +94,8 @@ jsi::Value makeShareableClone(
shareable = std::make_shared<ShareableScalar>(value.getBool());
} else if (value.isNumber()) {
shareable = std::make_shared<ShareableScalar>(value.getNumber());
#if REACT_NATIVE_MINOR_VERSION >= 71
} else if (value.isBigInt()) {
shareable = std::make_shared<ShareableBigInt>(rt, value.getBigInt(rt));
#endif
} else if (value.isSymbol()) {
// TODO: this is only a placeholder implementation, here we replace symbols
// with strings in order to make certain objects to be captured. There isn't
Expand Down Expand Up @@ -200,24 +198,20 @@ 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 REACT_NATIVE_MINOR_VERSION >= 71
if (object.hasNativeState(rt)) {
nativeState_ = object.getNativeState(rt);
}
#endif
}

ShareableObject::ShareableObject(
jsi::Runtime &rt,
const jsi::Object &object,
const jsi::Value &nativeStateSource)
: ShareableObject(rt, object) {
#if REACT_NATIVE_MINOR_VERSION >= 71
if (nativeStateSource.isObject() &&
nativeStateSource.asObject(rt).hasNativeState(rt)) {
nativeState_ = nativeStateSource.asObject(rt).getNativeState(rt);
}
#endif
}

jsi::Value ShareableObject::toJSValue(jsi::Runtime &rt) {
Expand All @@ -226,11 +220,9 @@ jsi::Value ShareableObject::toJSValue(jsi::Runtime &rt) {
obj.setProperty(
rt, data_[i].first.c_str(), data_[i].second->getJSValue(rt));
}
#if REACT_NATIVE_MINOR_VERSION >= 71
if (nativeState_ != nullptr) {
obj.setNativeState(rt, nativeState_);
}
#endif
return obj;
}

Expand Down Expand Up @@ -297,13 +289,11 @@ jsi::Value ShareableString::toJSValue(jsi::Runtime &rt) {
return jsi::String::createFromUtf8(rt, data_);
}

#if REACT_NATIVE_MINOR_VERSION >= 71
jsi::Value ShareableBigInt::toJSValue(jsi::Runtime &rt) {
return rt.global()
.getPropertyAsFunction(rt, "BigInt")
.call(rt, jsi::String::createFromUtf8(rt, string_));
}
#endif

jsi::Value ShareableScalar::toJSValue(jsi::Runtime &) {
switch (valueType_) {
Expand Down
4 changes: 0 additions & 4 deletions Common/cpp/SharedItems/Shareables.h
Expand Up @@ -192,9 +192,7 @@ class ShareableObject : public Shareable {

protected:
std::vector<std::pair<std::string, std::shared_ptr<Shareable>>> data_;
#if REACT_NATIVE_MINOR_VERSION >= 71
std::shared_ptr<jsi::NativeState> nativeState_;
#endif
};

class ShareableHostObject : public Shareable {
Expand Down Expand Up @@ -322,7 +320,6 @@ class ShareableString : public Shareable {
const std::string data_;
};

#if REACT_NATIVE_MINOR_VERSION >= 71
class ShareableBigInt : public Shareable {
public:
explicit ShareableBigInt(jsi::Runtime &rt, const jsi::BigInt &bigint)
Expand All @@ -333,7 +330,6 @@ class ShareableBigInt : public Shareable {
protected:
const std::string string_;
};
#endif

class ShareableScalar : public Shareable {
public:
Expand Down
2 changes: 0 additions & 2 deletions Common/cpp/Tools/JSISerializer.cpp
Expand Up @@ -275,11 +275,9 @@ std::string JSISerializer::stringifyJSIValueRecursively(
if (value.isSymbol()) {
return value.getSymbol(rt_).toString(rt_);
}
#if REACT_NATIVE_MINOR_VERSION >= 71
if (value.isBigInt()) {
return value.getBigInt(rt_).toString(rt_).utf8(rt_) + 'n';
}
#endif
if (value.isUndefined()) {
return "undefined";
}
Expand Down

0 comments on commit 325bd18

Please sign in to comment.