diff --git a/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/Common/cpp/NativeModules/NativeReanimatedModule.cpp index e5a6aa8c5af..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) { @@ -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..3fde9e4a717 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; @@ -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/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; 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); 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/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/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..4dba868b2ec 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; @@ -142,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); 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]]);