@samitouri / QOS-React-2 / commits / 78d2f2d301

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.

Valentin Shergin committed Feb 22, 2021 at 15:50 UTC 78d2f2d3015e7b4b3f0f7d8ddd07204952c5f8a9
3 files changed +19 -4
packages/react-native-renderer/src/ReactFabricGlobalResponderHandler.js
+17 -4
@@ -12,11 +12,24 @@ import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateI
12
13 const ReactFabricGlobalResponderHandler = {
14 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 + }
26 } 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 + }
33 }
34 },
35 };
packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager.js
+1
@@ -176,6 +176,7 @@ const RCTFabricUIManager = {
176 );
177 success(1, 1, 100, 100);
178 }),
179 + setIsJSResponder: jest.fn(),
180 };
181
182 global.nativeFabricUIManager = RCTFabricUIManager;
scripts/flow/react-native-host-hooks.js
+1
@@ -179,6 +179,7 @@ declare var nativeFabricUIManager: {
179 locationY: number,
180 callback: (Fiber) => void,
181 ) => void,
182 + setIsJSResponder: (node: Node, isJsResponder: boolean) => void,
183 ...
184 };
185