Skip to content

Commit 78d2f2d

Browse files
authored
Fabric-compatible implementation of JSReponder feature (#20768)
With this change, if a node is a Fabric node, we route the setJSResponder call to FabricUIManager. Native counterpart is already landed. Tested internally as D26241364.
1 parent cfd8c1b commit 78d2f2d

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

packages/react-native-renderer/src/ReactFabricGlobalResponderHandler.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,24 @@ import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateI
1212

1313
const ReactFabricGlobalResponderHandler = {
1414
onChange: function(from: any, to: any, blockNativeResponder: boolean) {
15-
if (to !== null) {
16-
const tag = to.stateNode.canonical._nativeTag;
17-
UIManager.setJSResponder(tag, blockNativeResponder);
15+
const fromOrTo = from || to;
16+
const isFabric = !!fromOrTo.stateNode.canonical._internalInstanceHandle;
17+
18+
if (isFabric) {
19+
if (from) {
20+
nativeFabricUIManager.setIsJSResponder(from.stateNode.node, false);
21+
}
22+
23+
if (to) {
24+
nativeFabricUIManager.setIsJSResponder(to.stateNode.node, true);
25+
}
1826
} else {
19-
UIManager.clearJSResponder();
27+
if (to !== null) {
28+
const tag = to.stateNode.canonical._nativeTag;
29+
UIManager.setJSResponder(tag, blockNativeResponder);
30+
} else {
31+
UIManager.clearJSResponder();
32+
}
2033
}
2134
},
2235
};

packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager.js

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ const RCTFabricUIManager = {
176176
);
177177
success(1, 1, 100, 100);
178178
}),
179+
setIsJSResponder: jest.fn(),
179180
};
180181

181182
global.nativeFabricUIManager = RCTFabricUIManager;

scripts/flow/react-native-host-hooks.js

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ declare var nativeFabricUIManager: {
179179
locationY: number,
180180
callback: (Fiber) => void,
181181
) => void,
182+
setIsJSResponder: (node: Node, isJsResponder: boolean) => void,
182183
...
183184
};
184185

0 commit comments

Comments
 (0)