From 305058178e144d4709606ea42d0edb9d864b33c5 Mon Sep 17 00:00:00 2001 From: Emily Janzer Date: Thu, 18 Jul 2019 14:10:16 -0700 Subject: [PATCH] Create binding for unmountComponentAtNode in bridgeless mode Summary: Right now we register ReactFabric as a callable module with the bridge so that we can call `ReactFabric.unmountComponentAtNode` in `ReactInstanceManager.detachViewFromInstance`. In bridgeless mode we don't have callable modules, so I'm just setting a global variable that can be called from C++ instead. Using this in a new `unmount` method in FabricUIManager. Reviewed By: shergin, mdvacca Differential Revision: D16273720 fbshipit-source-id: 95edb16da6566113a58babda3ebdf0fc4e39f8b0 --- Libraries/Renderer/shims/ReactFabric.js | 8 +++++++- .../com/facebook/react/fabric/FabricUIManager.java | 4 ++++ ReactCommon/fabric/uimanager/UIManagerBinding.cpp | 13 ++++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Libraries/Renderer/shims/ReactFabric.js b/Libraries/Renderer/shims/ReactFabric.js index 8f6a708fd20..acadc77985e 100644 --- a/Libraries/Renderer/shims/ReactFabric.js +++ b/Libraries/Renderer/shims/ReactFabric.js @@ -23,6 +23,12 @@ if (__DEV__) { ReactFabric = require('../implementations/ReactFabric-prod'); } -BatchedBridge.registerCallableModule('ReactFabric', ReactFabric); +if (global.RN$Bridgeless) { + // TODO T47525605 Clean this up once stopSurface has been added + global.RN$stopSurface = + ReactFabric.stopSurface ?? ReactFabric.unmountComponentAtNode; +} else { + BatchedBridge.registerCallableModule('ReactFabric', ReactFabric); +} module.exports = (ReactFabric: ReactNativeType); diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 61cd22c47c1..80ed2732cc9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -182,6 +182,10 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { mEventDispatcher.dispatchAllEvents(); } + public void stopSurface(int surfaceID) { + mBinding.stopSurface(surfaceID); + } + @Override public void initialize() { mEventDispatcher.registerEventEmitter(FABRIC, new FabricEventEmitter(this)); diff --git a/ReactCommon/fabric/uimanager/UIManagerBinding.cpp b/ReactCommon/fabric/uimanager/UIManagerBinding.cpp index ac72b2437be..ed06ab2bef1 100644 --- a/ReactCommon/fabric/uimanager/UIManagerBinding.cpp +++ b/ReactCommon/fabric/uimanager/UIManagerBinding.cpp @@ -69,10 +69,17 @@ void UIManagerBinding::startSurface( void UIManagerBinding::stopSurface(jsi::Runtime &runtime, SurfaceId surfaceId) const { - auto module = getModule(runtime, "ReactFabric"); - auto method = module.getPropertyAsFunction(runtime, "unmountComponentAtNode"); + if (runtime.global().hasProperty(runtime, "RN$stopSurface")) { + auto method = + runtime.global().getPropertyAsFunction(runtime, "RN$stopSurface"); + method.call(runtime, {jsi::Value{surfaceId}}); + } else { + auto module = getModule(runtime, "ReactFabric"); + auto method = + module.getPropertyAsFunction(runtime, "unmountComponentAtNode"); - method.callWithThis(runtime, module, {jsi::Value{surfaceId}}); + method.callWithThis(runtime, module, {jsi::Value{surfaceId}}); + } } void UIManagerBinding::dispatchEvent(