From c4a08c73883e3096410b60fe1d4cc7f1e7865e73 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 23 Mar 2021 11:10:14 +0100 Subject: [PATCH 1/9] Update UIResponder+Reanimated.mm --- ios/native/UIResponder+Reanimated.mm | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/ios/native/UIResponder+Reanimated.mm b/ios/native/UIResponder+Reanimated.mm index ab53a530de7..bb6230d3c98 100644 --- a/ios/native/UIResponder+Reanimated.mm +++ b/ios/native/UIResponder+Reanimated.mm @@ -7,12 +7,19 @@ #import #import -#if RNVERSION >= 64 +#if __has_include() #import +#else +#define RCTJSIExecutorRuntimeInstaller(x) x #endif -#if RNVERSION < 63 +#if __has_include() +#import +#define NEW_CALL_INVOKER +#elif __has_include() #import +#else +#error JS-CallInvoker import could not be found! #endif #if __has_include() @@ -38,33 +45,29 @@ @implementation UIResponder (Reanimated) RCTEventDispatcher *eventDispatcher = [REAEventDispatcher new]; [eventDispatcher setBridge:bridge]; [bridge updateModuleWithInstance:eventDispatcher]; - _bridge_reanimated = bridge; + _bridge_reanimated = bridge; __weak __typeof(self) weakSelf = self; - + const auto executor = [weakSelf, bridge](facebook::jsi::Runtime &runtime) { if (!bridge) { return; } __typeof(self) strongSelf = weakSelf; if (strongSelf) { -#if RNVERSION >= 63 - auto reanimatedModule = reanimated::createReanimatedModule(bridge.jsCallInvoker); +#ifdef NEW_CALL_INVOKER + auto callInvoker = bridge.jsCallInvoker; #else auto callInvoker = std::make_shared(bridge.reactInstance); - auto reanimatedModule = reanimated::createReanimatedModule(callInvoker); #endif + auto reanimatedModule = reanimated::createReanimatedModule(callInvoker); runtime.global().setProperty(runtime, jsi::PropNameID::forAscii(runtime, "__reanimatedModuleProxy"), jsi::Object::createFromHostObject(runtime, reanimatedModule)); } }; - -#if RNVERSION >= 64 + // installs globals such as console, nativePerformanceNow, etc. return std::make_unique(RCTJSIExecutorRuntimeInstaller(executor)); -#else - return std::make_unique(executor); -#endif } @end From 8a5b3e366fff152c78609c8a58c20b92ad420935 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 23 Mar 2021 11:12:38 +0100 Subject: [PATCH 2/9] Use std::make_shared for Scheduler --- Example/ios/Podfile.lock | 14 ++++++++++---- android/src/main/cpp/NativeProxy.cpp | 6 +++--- ios/native/NativeProxy.mm | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Example/ios/Podfile.lock b/Example/ios/Podfile.lock index 12bfc304c32..4234772cbe9 100644 --- a/Example/ios/Podfile.lock +++ b/Example/ios/Podfile.lock @@ -9,6 +9,10 @@ PODS: - React-Core (= 0.64.0-rc.2) - React-jsi (= 0.64.0-rc.2) - ReactCommon/turbomodule/core (= 0.64.0-rc.2) + - Folly (2016.09.26.00): + - boost-for-react-native + - DoubleConversion + - glog - glog (0.3.5) - RCT-Folly (2020.01.13.00): - boost-for-react-native @@ -283,12 +287,12 @@ PODS: - React - RNGestureHandler (1.10.1): - React-Core - - RNReanimated (2.0.0-rc.3): + - RNReanimated (2.0.0): - DoubleConversion - FBLazyVector - FBReactNativeSpec + - Folly - glog - - RCT-Folly - RCTRequired - RCTTypeSafety - React @@ -360,6 +364,7 @@ DEPENDENCIES: SPEC REPOS: trunk: - boost-for-react-native + - Folly EXTERNAL SOURCES: DoubleConversion: @@ -435,7 +440,8 @@ SPEC CHECKSUMS: boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c DoubleConversion: cf9b38bf0b2d048436d9a82ad2abe1404f11e7de FBLazyVector: b21700af840f633338ac968a36da9aa3a8268887 - FBReactNativeSpec: ac5ae8902727ea99deddd51bc998500c64a27275 + FBReactNativeSpec: 042442754c4377344b9c14ef2186aa2c1e6f7208 + Folly: 211775e49d8da0ca658aebc8eab89d642935755c glog: 73c2498ac6884b13ede40eda8228cb1eee9d9d62 RCT-Folly: ec7a233ccc97cc556cf7237f0db1ff65b986f27c RCTRequired: fa44b153ba69cb9dd6cec5084b86719e3be7c90b @@ -463,7 +469,7 @@ SPEC CHECKSUMS: ReactCommon: c8ae344df0376e043f2899a5badb60709d24821e RNCMaskedView: 5a8ec07677aa885546a0d98da336457e2bea557f RNGestureHandler: 5e58135436aacc1c5d29b75547d3d2b9430d052c - RNReanimated: 2111076cba59d4ea29d8a10b4310d20bab2d3b7f + RNReanimated: 9dce67e20b65f1813ab5eaae17e4fc1adf932e2f RNScreens: b6c9607e6fe47c1b6e2f1910d2acd46dd7ecea3a RNSVG: ce9d996113475209013317e48b05c21ee988d42e Yoga: 17d4f4db4e2efbaa7c3bc316ce4f762d02c4023d diff --git a/android/src/main/cpp/NativeProxy.cpp b/android/src/main/cpp/NativeProxy.cpp index b7552a063ec..a22bc83e83f 100644 --- a/android/src/main/cpp/NativeProxy.cpp +++ b/android/src/main/cpp/NativeProxy.cpp @@ -60,10 +60,10 @@ void NativeProxy::installJSIBindings() }; auto requestRender = [this, getCurrentTime](std::function onRender, jsi::Runtime &rt) { - //doNoUse -> NodesManager passes here a timestamp from choreographer which is useless for us + //doNoUse -> NodesManager passes here a timestamp from choreographer which is useless for us //as we use diffrent timer to better handle events. The lambda is translated to NodeManager.OnAnimationFrame //and treated just like reanimated 1 frame callbacks which make use of the timestamp. - auto wrappedOnRender = [getCurrentTime, &rt, onRender](double doNotUse) { + auto wrappedOnRender = [getCurrentTime, &rt, onRender](double doNotUse) { double frameTimestamp = getCurrentTime(); rt.global().setProperty(rt, "_frameTimestamp", frameTimestamp); onRender(frameTimestamp); @@ -92,7 +92,7 @@ void NativeProxy::installJSIBindings() std::unique_ptr animatedRuntime = facebook::hermes::makeHermesRuntime(); - std::shared_ptr errorHandler = std::shared_ptr(new AndroidErrorHandler(scheduler_)); + std::shared_ptr errorHandler = std::make_shared(scheduler_); PlatformDepMethodsHolder platformDepMethodsHolder = { requestRender, diff --git a/ios/native/NativeProxy.mm b/ios/native/NativeProxy.mm index 9618fd0f56e..90ecb97c63e 100644 --- a/ios/native/NativeProxy.mm +++ b/ios/native/NativeProxy.mm @@ -111,13 +111,14 @@ static id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &v return val; }; - std::shared_ptr scheduler(new REAIOSScheduler(jsInvoker)); #if __has_include() std::unique_ptr animatedRuntime = facebook::hermes::makeHermesRuntime(); #else std::unique_ptr animatedRuntime = facebook::jsc::makeJSCRuntime(); #endif + + std::shared_ptr scheduler = std::make_shared(jsInvoker); std::shared_ptr errorHandler = std::make_shared(scheduler); std::shared_ptr module; From 2955e81e13dcd8077c3c1d981d94033a479ff122 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 23 Mar 2021 11:12:41 +0100 Subject: [PATCH 3/9] Indent --- ios/native/NativeProxy.mm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ios/native/NativeProxy.mm b/ios/native/NativeProxy.mm index 90ecb97c63e..4dba868b2ec 100644 --- a/ios/native/NativeProxy.mm +++ b/ios/native/NativeProxy.mm @@ -143,13 +143,13 @@ static id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &v getCurrentTime, }; -module = std::make_shared(jsInvoker, - scheduler, - std::move(animatedRuntime), - errorHandler, - propObtainer, - platformDepMethodsHolder - ); + module = std::make_shared(jsInvoker, + scheduler, + std::move(animatedRuntime), + errorHandler, + propObtainer, + platformDepMethodsHolder + ); scheduler->setModule(module); From ddd3cfc373db0d10c4de59e486316b753e17225e Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 23 Mar 2021 11:13:11 +0100 Subject: [PATCH 4/9] private: --- Common/cpp/headers/Registries/WorkletsCache.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Common/cpp/headers/Registries/WorkletsCache.h b/Common/cpp/headers/Registries/WorkletsCache.h index 0ede04ce1c9..d700c7934b5 100644 --- a/Common/cpp/headers/Registries/WorkletsCache.h +++ b/Common/cpp/headers/Registries/WorkletsCache.h @@ -13,6 +13,7 @@ using namespace facebook; class FrozenObject; class WorkletsCache { +private: std::unordered_map> worklets; public: std::shared_ptr getFunction(jsi::Runtime & rt, std::shared_ptr frozenObj); From 8274b52528575561b6b4e6c179a6bbdfc7c60e29 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 23 Mar 2021 11:14:01 +0100 Subject: [PATCH 5/9] Re-indent NativeReanimatedModule --- .../NativeModules/NativeReanimatedModule.h | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/Common/cpp/headers/NativeModules/NativeReanimatedModule.h b/Common/cpp/headers/NativeModules/NativeReanimatedModule.h index 258903a397c..0ab7ca5c006 100644 --- a/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +++ b/Common/cpp/headers/NativeModules/NativeReanimatedModule.h @@ -25,49 +25,49 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec friend ShareableValue; friend MutableValue; - public: - NativeReanimatedModule(std::shared_ptr jsInvoker, - std::shared_ptr scheduler, - std::unique_ptr rt, - std::shared_ptr errorHandler, - std::function propObtainer, - PlatformDepMethodsHolder platformDepMethodsHolder); - - virtual ~NativeReanimatedModule(); - - void installCoreFunctions(jsi::Runtime &rt, const jsi::Value &valueSetter) override; - - jsi::Value makeShareable(jsi::Runtime &rt, const jsi::Value &value) override; - jsi::Value makeMutable(jsi::Runtime &rt, const jsi::Value &value) override; - jsi::Value makeRemote(jsi::Runtime &rt, const jsi::Value &value) override; - - jsi::Value startMapper(jsi::Runtime &rt, const jsi::Value &worklet, const jsi::Value &inputs, const jsi::Value &outputs) override; - void stopMapper(jsi::Runtime &rt, const jsi::Value &mapperId) override; - - jsi::Value registerEventHandler(jsi::Runtime &rt, const jsi::Value &eventHash, const jsi::Value &worklet) override; - void unregisterEventHandler(jsi::Runtime &rt, const jsi::Value ®istrationId) override; - - jsi::Value getViewProp(jsi::Runtime &rt, const jsi::Value &viewTag, const jsi::Value &propName, const jsi::Value &callback) override; - - void onRender(double timestampMs); - void onEvent(std::string eventName, std::string eventAsString); - bool isAnyHandlerWaitingForEvent(std::string eventName); - - void maybeRequestRender(); - - bool isUIRuntime(jsi::Runtime &rt); - bool isHostRuntime(jsi::Runtime &rt); - public: - std::unique_ptr runtime; - private: - std::shared_ptr mapperRegistry; - std::shared_ptr eventHandlerRegistry; - std::function requestRender; - std::shared_ptr dummyEvent; - std::vector frameCallbacks; - bool renderRequested = false; - std::function propObtainer; - public: +public: + NativeReanimatedModule(std::shared_ptr jsInvoker, + std::shared_ptr scheduler, + std::unique_ptr rt, + std::shared_ptr errorHandler, + std::function propObtainer, + PlatformDepMethodsHolder platformDepMethodsHolder); + + virtual ~NativeReanimatedModule(); + + void installCoreFunctions(jsi::Runtime &rt, const jsi::Value &valueSetter) override; + + jsi::Value makeShareable(jsi::Runtime &rt, const jsi::Value &value) override; + jsi::Value makeMutable(jsi::Runtime &rt, const jsi::Value &value) override; + jsi::Value makeRemote(jsi::Runtime &rt, const jsi::Value &value) override; + + jsi::Value startMapper(jsi::Runtime &rt, const jsi::Value &worklet, const jsi::Value &inputs, const jsi::Value &outputs) override; + void stopMapper(jsi::Runtime &rt, const jsi::Value &mapperId) override; + + jsi::Value registerEventHandler(jsi::Runtime &rt, const jsi::Value &eventHash, const jsi::Value &worklet) override; + void unregisterEventHandler(jsi::Runtime &rt, const jsi::Value ®istrationId) override; + + jsi::Value getViewProp(jsi::Runtime &rt, const jsi::Value &viewTag, const jsi::Value &propName, const jsi::Value &callback) override; + + void onRender(double timestampMs); + void onEvent(std::string eventName, std::string eventAsString); + bool isAnyHandlerWaitingForEvent(std::string eventName); + + void maybeRequestRender(); + + bool isUIRuntime(jsi::Runtime &rt); + bool isHostRuntime(jsi::Runtime &rt); +public: + std::unique_ptr runtime; +private: + std::shared_ptr mapperRegistry; + std::shared_ptr eventHandlerRegistry; + std::function requestRender; + std::shared_ptr dummyEvent; + std::vector frameCallbacks; + bool renderRequested = false; + std::function propObtainer; +public: std::shared_ptr errorHandler; std::shared_ptr workletsCache; std::shared_ptr valueSetter; From 1cec07a053d9c49f5fa12ff56f5a4b35e5d05355 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 23 Mar 2021 11:17:06 +0100 Subject: [PATCH 6/9] new -> make_unique/make_shared --- .../NativeModules/NativeReanimatedModule.cpp | 2 +- Common/cpp/Registries/WorkletsCache.cpp | 2 +- Common/cpp/SharedItems/ShareableValue.cpp | 48 +++++++++---------- android/src/main/cpp/AndroidLogger.cpp | 4 +- ios/native/REAIOSLogger.mm | 2 +- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/Common/cpp/NativeModules/NativeReanimatedModule.cpp index e5a6aa8c5af..6f5d99557a7 100644 --- a/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -174,7 +174,7 @@ jsi::Value NativeReanimatedModule::getViewProp(jsi::Runtime &rt, const jsi::Valu const int viewTagInt = (int)viewTag.asNumber(); std::string propNameStr = propName.asString(rt).utf8(rt); jsi::Function fun = callback.getObject(rt).asFunction(rt); - std::shared_ptr funPtr(new jsi::Function(std::move(fun))); + std::shared_ptr funPtr = std::make_shared(std::move(fun)); scheduler->scheduleOnUI([&rt, viewTagInt, funPtr, this, propNameStr]() { const jsi::String propNameValue = jsi::String::createFromUtf8(rt, propNameStr); diff --git a/Common/cpp/Registries/WorkletsCache.cpp b/Common/cpp/Registries/WorkletsCache.cpp index 9e3de641f04..0567e5fd0bc 100644 --- a/Common/cpp/Registries/WorkletsCache.cpp +++ b/Common/cpp/Registries/WorkletsCache.cpp @@ -22,7 +22,7 @@ std::shared_ptr WorkletsCache::getFunction(jsi::Runtime &rt, std: rt, ValueWrapper::asString(frozenObj->map["asString"]->valueContainer) ); - std::shared_ptr funPtr(new jsi::Function(std::move(fun))); + std::shared_ptr funPtr = std::make_shared(std::move(fun)); worklets[workletHash] = funPtr; } return worklets[workletHash]; diff --git a/Common/cpp/SharedItems/ShareableValue.cpp b/Common/cpp/SharedItems/ShareableValue.cpp index 481c8ec499c..5121a63581a 100644 --- a/Common/cpp/SharedItems/ShareableValue.cpp +++ b/Common/cpp/SharedItems/ShareableValue.cpp @@ -17,7 +17,7 @@ std::string CALLBACK_ERROR_SUFFIX = R"( Possible solutions are: a) If you want to synchronously execute this method, mark it as a Worklet b) If you want to execute this method on the JS thread, wrap it using runOnJS )"; - + void addHiddenProperty(jsi::Runtime &rt, jsi::Value &&value, jsi::Object &obj, @@ -72,7 +72,7 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType } } } - + if (objectType == ValueType::MutableValueType) { type = ValueType::MutableValueType; valueContainer = std::make_unique( @@ -98,7 +98,7 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType // not a worklet, we treat this as a host function type = ValueType::HostFunctionType; containsHostFunction = true; - + //Check if it's a hostFunction wrapper jsi::Value primalFunction = object.getProperty(rt, PRIMAL_FUNCTION); if (!primalFunction.isUndefined()) { @@ -109,11 +109,11 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType valueContainer = std::make_unique( std::make_shared(std::make_shared(object.asFunction(rt)), rt)); } - + } else { // a worklet type = ValueType::WorkletFunctionType; - + valueContainer = std::make_unique(std::make_shared(rt, object, module)); auto& frozenObject = ValueWrapper::asFrozenObject(valueContainer); containsHostFunction |= frozenObject->containsHostFunction; @@ -170,7 +170,7 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType } std::shared_ptr ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, NativeReanimatedModule *module, ValueType valueType) { - auto sv = std::shared_ptr(new ShareableValue(module, module->scheduler)); + auto sv = std::make_shared(module, module->scheduler); sv->adapt(rt, value, valueType); return sv; } @@ -182,7 +182,7 @@ jsi::Value ShareableValue::getValue(jsi::Runtime &rt) { auto ref = getWeakRef(rt); remoteValue = ref; } - + if (remoteValue.lock()->isUndefined()) { (*remoteValue.lock()) = jsi::Value(rt, toJSValue(rt)); } @@ -253,22 +253,22 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) { auto& hostRuntime = hostFunctionWrapper->value->hostRuntime; if (hostRuntime == &rt) { // function is accessed from the same runtime it was crated, we just return same function obj - + return jsi::Value(rt, *hostFunctionWrapper->value->getPureFunction().get()); } else { // function is accessed from a different runtime, we wrap function in host func that'd enqueue // call on an appropriate thread - + auto module = this->module; auto hostFunction = hostFunctionWrapper->value; - + auto warnFunction = [module, hostFunction]( jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count ) -> jsi::Value { - + jsi::Value jsThis = rt.global().getProperty(rt, "jsThis"); std::string workletLocation = jsThis.asObject(rt).getProperty(rt, "__location").toString(rt).utf8(rt); std::string exceptionMessage = "Tried to synchronously call "; @@ -282,10 +282,10 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) { exceptionMessage += CALLBACK_ERROR_SUFFIX; module->errorHandler->setError(exceptionMessage); module->errorHandler->raise(); - + return jsi::Value::undefined(); }; - + auto clb = [module, hostFunction, hostRuntime]( jsi::Runtime &rt, const jsi::Value &thisValue, @@ -294,26 +294,26 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) { ) -> jsi::Value { // TODO: we should find thread based on runtime such that we could also call UI methods // from RN and not only RN methods from UI - + std::vector> params; for (int i = 0; i < count; ++i) { params.push_back(ShareableValue::adapt(rt, args[i], module)); } - + std::function job = [hostFunction, hostRuntime, params] { jsi::Value * args = new jsi::Value[params.size()]; for (int i = 0; i < params.size(); ++i) { args[i] = params[i]->getValue(*hostRuntime); } - + jsi::Value returnedValue = hostFunction->getPureFunction().get()->call(*hostRuntime, static_cast(args), (size_t)params.size()); - + delete [] args; // ToDo use returned value to return promise }; - + module->scheduler->scheduleOnJS(job); return jsi::Value::undefined(); }; @@ -383,27 +383,27 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) { for (int i = 0; i < count; ++i) { params.push_back(ShareableValue::adapt(rt, args[i], module)); } - + module->scheduler->scheduleOnUI([=] { jsi::Runtime &rt = *module->runtime.get(); auto jsThis = createFrozenWrapper(rt, frozenObject).getObject(rt); auto code = jsThis.getProperty(rt, "asString").asString(rt).utf8(rt); std::shared_ptr funPtr(module->workletsCache->getFunction(rt, frozenObject)); - + jsi::Value * args = new jsi::Value[params.size()]; for (int i = 0; i < params.size(); ++i) { args[i] = params[i]->getValue(rt); } - + jsi::Value returnedValue; - + jsi::Value oldJSThis = rt.global().getProperty(rt, "jsThis"); rt.global().setProperty(rt, "jsThis", jsThis); //set jsThis try { returnedValue = funPtr->call(rt, static_cast(args), (size_t)params.size()); - + } catch(std::exception &e) { std::string str = e.what(); module->errorHandler->setError(str); @@ -419,7 +419,7 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) { module->errorHandler->raise(); } rt.global().setProperty(rt, "jsThis", oldJSThis); //clean jsThis - + delete [] args; // ToDo use returned value to return promise }); diff --git a/android/src/main/cpp/AndroidLogger.cpp b/android/src/main/cpp/AndroidLogger.cpp index 27a704a87f9..4e979443521 100644 --- a/android/src/main/cpp/AndroidLogger.cpp +++ b/android/src/main/cpp/AndroidLogger.cpp @@ -6,7 +6,7 @@ namespace reanimated { -std::unique_ptr Logger::instance = std::unique_ptr(new AndroidLogger()); +std::unique_ptr Logger::instance = std::make_unique(); void AndroidLogger::log(const char* str) { __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "%s", str); @@ -24,4 +24,4 @@ void AndroidLogger::log(bool b) { __android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "%s", b ? "true" : "false"); } -} \ No newline at end of file +} diff --git a/ios/native/REAIOSLogger.mm b/ios/native/REAIOSLogger.mm index c65fb4546e3..1fa1af59418 100644 --- a/ios/native/REAIOSLogger.mm +++ b/ios/native/REAIOSLogger.mm @@ -3,7 +3,7 @@ namespace reanimated { -std::unique_ptr Logger::instance = std::unique_ptr(new REAIOSLogger()); +std::unique_ptr Logger::instance = std::make_unique(); void REAIOSLogger::log(const char* str) { NSLog(@"%@", [NSString stringWithCString:str encoding:[NSString defaultCStringEncoding]]); From 4762801bcae24ce77864bfb1bebeafefb3417f15 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 23 Mar 2021 11:18:54 +0100 Subject: [PATCH 7/9] new -> std::make_shared (NativeReanimatedModule ctor) --- Common/cpp/NativeModules/NativeReanimatedModule.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/Common/cpp/NativeModules/NativeReanimatedModule.cpp index 6f5d99557a7..5b9d3f8fd76 100644 --- a/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -63,12 +63,12 @@ NativeReanimatedModule::NativeReanimatedModule(std::shared_ptr jsIn std::function propObtainer, PlatformDepMethodsHolder platformDepMethodsHolder) : NativeReanimatedModuleSpec(jsInvoker), runtime(std::move(rt)), - mapperRegistry(new MapperRegistry()), - eventHandlerRegistry(new EventHandlerRegistry()), + mapperRegistry(std::make_shared()), + eventHandlerRegistry(std::make_shared()), requestRender(platformDepMethodsHolder.requestRender), propObtainer(propObtainer), errorHandler(errorHandler), - workletsCache(new WorkletsCache()), + workletsCache(std::make_shared()), scheduler(scheduler) { auto requestAnimationFrame = [=](FrameCallback callback) { From 5dde5dd2600de6d4541c7b26a87ca424e7e4ed5d Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 23 Mar 2021 11:28:59 +0100 Subject: [PATCH 8/9] Fix private ctor call in make_shared --- Common/cpp/SharedItems/ShareableValue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/cpp/SharedItems/ShareableValue.cpp b/Common/cpp/SharedItems/ShareableValue.cpp index 5121a63581a..3fde9e4a717 100644 --- a/Common/cpp/SharedItems/ShareableValue.cpp +++ b/Common/cpp/SharedItems/ShareableValue.cpp @@ -170,7 +170,7 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType } std::shared_ptr ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, NativeReanimatedModule *module, ValueType valueType) { - auto sv = std::make_shared(module, module->scheduler); + auto sv = std::shared_ptr(new ShareableValue(module, module->scheduler)); sv->adapt(rt, value, valueType); return sv; } From aa334c5d7412a325c5db68a15f520710bafbd82a Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 23 Mar 2021 13:25:52 +0100 Subject: [PATCH 9/9] Revert "Update UIResponder+Reanimated.mm" This reverts commit c4a08c73883e3096410b60fe1d4cc7f1e7865e73. --- ios/native/UIResponder+Reanimated.mm | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/ios/native/UIResponder+Reanimated.mm b/ios/native/UIResponder+Reanimated.mm index bb6230d3c98..ab53a530de7 100644 --- a/ios/native/UIResponder+Reanimated.mm +++ b/ios/native/UIResponder+Reanimated.mm @@ -7,19 +7,12 @@ #import #import -#if __has_include() +#if RNVERSION >= 64 #import -#else -#define RCTJSIExecutorRuntimeInstaller(x) x #endif -#if __has_include() -#import -#define NEW_CALL_INVOKER -#elif __has_include() +#if RNVERSION < 63 #import -#else -#error JS-CallInvoker import could not be found! #endif #if __has_include() @@ -45,29 +38,33 @@ @implementation UIResponder (Reanimated) RCTEventDispatcher *eventDispatcher = [REAEventDispatcher new]; [eventDispatcher setBridge:bridge]; [bridge updateModuleWithInstance:eventDispatcher]; - _bridge_reanimated = bridge; + _bridge_reanimated = bridge; __weak __typeof(self) weakSelf = self; - + const auto executor = [weakSelf, bridge](facebook::jsi::Runtime &runtime) { if (!bridge) { return; } __typeof(self) strongSelf = weakSelf; if (strongSelf) { -#ifdef NEW_CALL_INVOKER - auto callInvoker = bridge.jsCallInvoker; +#if RNVERSION >= 63 + auto reanimatedModule = reanimated::createReanimatedModule(bridge.jsCallInvoker); #else auto callInvoker = std::make_shared(bridge.reactInstance); -#endif auto reanimatedModule = reanimated::createReanimatedModule(callInvoker); +#endif runtime.global().setProperty(runtime, jsi::PropNameID::forAscii(runtime, "__reanimatedModuleProxy"), jsi::Object::createFromHostObject(runtime, reanimatedModule)); } }; - + +#if RNVERSION >= 64 // installs globals such as console, nativePerformanceNow, etc. return std::make_unique(RCTJSIExecutorRuntimeInstaller(executor)); +#else + return std::make_unique(executor); +#endif } @end