Skip to content

Commit 3050581

Browse files
Emily Janzerfacebook-github-bot
authored andcommitted
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
1 parent 18c0087 commit 3050581

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Libraries/Renderer/shims/ReactFabric.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ if (__DEV__) {
2323
ReactFabric = require('../implementations/ReactFabric-prod');
2424
}
2525

26-
BatchedBridge.registerCallableModule('ReactFabric', ReactFabric);
26+
if (global.RN$Bridgeless) {
27+
// TODO T47525605 Clean this up once stopSurface has been added
28+
global.RN$stopSurface =
29+
ReactFabric.stopSurface ?? ReactFabric.unmountComponentAtNode;
30+
} else {
31+
BatchedBridge.registerCallableModule('ReactFabric', ReactFabric);
32+
}
2733

2834
module.exports = (ReactFabric: ReactNativeType);

ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ public void onRequestEventBeat() {
182182
mEventDispatcher.dispatchAllEvents();
183183
}
184184

185+
public void stopSurface(int surfaceID) {
186+
mBinding.stopSurface(surfaceID);
187+
}
188+
185189
@Override
186190
public void initialize() {
187191
mEventDispatcher.registerEventEmitter(FABRIC, new FabricEventEmitter(this));

ReactCommon/fabric/uimanager/UIManagerBinding.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,17 @@ void UIManagerBinding::startSurface(
6969

7070
void UIManagerBinding::stopSurface(jsi::Runtime &runtime, SurfaceId surfaceId)
7171
const {
72-
auto module = getModule(runtime, "ReactFabric");
73-
auto method = module.getPropertyAsFunction(runtime, "unmountComponentAtNode");
72+
if (runtime.global().hasProperty(runtime, "RN$stopSurface")) {
73+
auto method =
74+
runtime.global().getPropertyAsFunction(runtime, "RN$stopSurface");
75+
method.call(runtime, {jsi::Value{surfaceId}});
76+
} else {
77+
auto module = getModule(runtime, "ReactFabric");
78+
auto method =
79+
module.getPropertyAsFunction(runtime, "unmountComponentAtNode");
7480

75-
method.callWithThis(runtime, module, {jsi::Value{surfaceId}});
81+
method.callWithThis(runtime, module, {jsi::Value{surfaceId}});
82+
}
7683
}
7784

7885
void UIManagerBinding::dispatchEvent(

0 commit comments

Comments
 (0)