diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index a1d9b2ded..50d2c05ed 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -152,7 +152,6 @@ struct RCTInstanceCallback : public InstanceCallback { @implementation RCTCxxBridge { - BOOL _wasBatchActive; BOOL _didInvalidate; BOOL _moduleRegistryCreated; @@ -1348,7 +1347,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR - (BOOL)isBatchActive { - return _wasBatchActive; + return _reactInstance ? _reactInstance->isBatchActive() : NO; } - (void *)runtime diff --git a/ReactCommon/cxxreact/Instance.cpp b/ReactCommon/cxxreact/Instance.cpp index a49f1d60d..23723fbbe 100644 --- a/ReactCommon/cxxreact/Instance.cpp +++ b/ReactCommon/cxxreact/Instance.cpp @@ -149,6 +149,10 @@ void *Instance::getJavaScriptContext() { bool Instance::isInspectable() { return nativeToJsBridge_ ? nativeToJsBridge_->isInspectable() : false; } + +bool Instance::isBatchActive() { + return nativeToJsBridge_ ? nativeToJsBridge_->isBatchActive() : false; +} void Instance::callJSFunction(std::string &&module, std::string &&method, folly::dynamic &¶ms) { diff --git a/ReactCommon/cxxreact/Instance.h b/ReactCommon/cxxreact/Instance.h index 654fa929e..72a5a7ee8 100644 --- a/ReactCommon/cxxreact/Instance.h +++ b/ReactCommon/cxxreact/Instance.h @@ -58,6 +58,7 @@ public: std::unique_ptr jsonValue); void *getJavaScriptContext(); bool isInspectable(); + bool isBatchActive(); void callJSFunction(std::string &&module, std::string &&method, folly::dynamic &¶ms); void callJSCallback(uint64_t callbackId, folly::dynamic &¶ms); diff --git a/ReactCommon/cxxreact/NativeToJsBridge.cpp b/ReactCommon/cxxreact/NativeToJsBridge.cpp index a9b7161df..4cb428d97 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.cpp +++ b/ReactCommon/cxxreact/NativeToJsBridge.cpp @@ -37,6 +37,10 @@ public: std::shared_ptr getModuleRegistry() override { return m_registry; } + + bool isBatchActive() { + return m_batchHadNativeModuleCalls; + } void callNativeModules( JSExecutor& executor, folly::dynamic&& calls, bool isEndOfBatch) override { @@ -222,6 +226,10 @@ void* NativeToJsBridge::getJavaScriptContext() { bool NativeToJsBridge::isInspectable() { return m_executor->isInspectable(); } + +bool NativeToJsBridge::isBatchActive() { + return m_delegate->isBatchActive(); +} void NativeToJsBridge::handleMemoryPressure(int pressureLevel) { runOnExecutorQueue([=] (JSExecutor* executor) { diff --git a/ReactCommon/cxxreact/NativeToJsBridge.h b/ReactCommon/cxxreact/NativeToJsBridge.h index 8c99d89ac..cc30054ac 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.h +++ b/ReactCommon/cxxreact/NativeToJsBridge.h @@ -75,6 +75,7 @@ public: void setGlobalVariable(std::string propName, std::unique_ptr jsonValue); void* getJavaScriptContext(); bool isInspectable(); + bool isBatchActive(); void handleMemoryPressure(int pressureLevel);