Skip to content

Commit 17c38d0

Browse files
committed
Fabric-compatible implementation of JSReponder feature
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 6c526c5 commit 17c38d0

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,33 @@ 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(
21+
from.stateNode.node,
22+
false
23+
);
24+
}
25+
26+
if (to) {
27+
nativeFabricUIManager.setIsJSResponder(
28+
to.stateNode.node,
29+
true
30+
);
31+
}
1832
} else {
19-
UIManager.clearJSResponder();
33+
if (to !== null) {
34+
const tag = to.stateNode.canonical._nativeTag;
35+
UIManager.setJSResponder(
36+
tag,
37+
blockNativeResponder
38+
);
39+
} else {
40+
UIManager.clearJSResponder();
41+
}
2042
}
2143
},
2244
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export type NativeMethods = {
8888
onFail?: () => void,
8989
): void,
9090
setNativeProps(nativeProps: Object): void,
91+
setIsJSResponder(node: any, isJSResponder: boolean): void,
9192
...
9293
};
9394

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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)