From 16fb64a9ef97e7ff0b8fe718d310705fa5fe6066 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Tue, 7 Nov 2023 17:20:49 -0800 Subject: [PATCH] Adding FabricUIManager() getter & setter and setter for TurboModuleRegistry (#41302) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41302 Adding `setTurboModuleRegistry(TurboModuleRegistry turboModuleRegistry)`, `setFabricUIManager(UIManager fabricUIManager)`, `getFabricUIManager()` new APIs Changelog: [General][Added] Introduce APIs for FabricUIManager Reviewed By: philIip Differential Revision: D50832557 fbshipit-source-id: 9a27a5683f312fb93f09bb4d97a615988269876e --- .../react/bridge/CatalystInstance.java | 17 +++++++++++++++ .../react/bridge/CatalystInstanceImpl.java | 21 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.java index e138e6dfeac26d..5d0d4297742206 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.java @@ -10,9 +10,11 @@ import androidx.annotation.Nullable; import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.bridge.queue.ReactQueueConfiguration; +import com.facebook.react.common.annotations.DeprecatedInNewArchitecture; import com.facebook.react.common.annotations.VisibleForTesting; import com.facebook.react.internal.turbomodule.core.interfaces.CallInvokerHolder; import com.facebook.react.internal.turbomodule.core.interfaces.NativeMethodCallInvokerHolder; +import com.facebook.react.internal.turbomodule.core.interfaces.TurboModuleRegistry; import java.util.Collection; import java.util.List; @@ -134,4 +136,19 @@ public interface CatalystInstance * hasNativeModule, and getNativeModules can also return TurboModules. */ void setTurboModuleManager(JSIModule getter); + + @DeprecatedInNewArchitecture( + message = + "This method will be deprecated later as part of Stable APIs with bridge removal and not encouraged usage.") + void setTurboModuleRegistry(TurboModuleRegistry turboModuleRegistry); + + @DeprecatedInNewArchitecture( + message = + "This method will be deprecated later as part of Stable APIs with bridge removal and not encouraged usage.") + void setFabricUIManager(UIManager fabricUIManager); + + @DeprecatedInNewArchitecture( + message = + "This method will be deprecated later as part of Stable APIs with bridge removal and not encouraged usage.") + UIManager getFabricUIManager(); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java index 3cb8b1ea8171d5..be3c61b6dc3622 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java @@ -103,7 +103,8 @@ public String toString() { private @Nullable String mSourceURL; private JavaScriptContextHolder mJavaScriptContextHolder; - private volatile @Nullable TurboModuleRegistry mTurboModuleRegistry = null; + private @Nullable TurboModuleRegistry mTurboModuleRegistry; + private @Nullable UIManager mFabricUIManager; // C++ parts private final HybridData mHybridData; @@ -351,6 +352,9 @@ public void destroy() { () -> { mNativeModuleRegistry.notifyJSInstanceDestroy(); mJSIModuleRegistry.notifyJSInstanceDestroy(); + if (mFabricUIManager != null) { + mFabricUIManager.invalidate(); + } boolean wasIdle = (mPendingJSCalls.getAndSet(0) == 0); if (!mBridgeIdleListeners.isEmpty()) { for (NotThreadSafeBridgeIdleDebugListener listener : mBridgeIdleListeners) { @@ -570,6 +574,21 @@ public void setTurboModuleManager(JSIModule module) { mTurboModuleRegistry = (TurboModuleRegistry) module; } + @Override + public void setTurboModuleRegistry(TurboModuleRegistry turboModuleRegistry) { + mTurboModuleRegistry = turboModuleRegistry; + } + + @Override + public void setFabricUIManager(UIManager fabricUIManager) { + mFabricUIManager = fabricUIManager; + } + + @Override + public UIManager getFabricUIManager() { + return mFabricUIManager; + } + private void decrementPendingJSCalls() { int newPendingCalls = mPendingJSCalls.decrementAndGet(); // TODO(9604406): handle case of web workers injecting messages to main thread