Skip to content

Commit

Permalink
Fabric-compatible implementation of JSReponder feature (#20768)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shergin committed Feb 22, 2021
1 parent cfd8c1b commit 78d2f2d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Expand Up @@ -12,11 +12,24 @@ import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateI

const ReactFabricGlobalResponderHandler = {
onChange: function(from: any, to: any, blockNativeResponder: boolean) {
if (to !== null) {
const tag = to.stateNode.canonical._nativeTag;
UIManager.setJSResponder(tag, blockNativeResponder);
const fromOrTo = from || to;
const isFabric = !!fromOrTo.stateNode.canonical._internalInstanceHandle;

if (isFabric) {
if (from) {
nativeFabricUIManager.setIsJSResponder(from.stateNode.node, false);
}

if (to) {
nativeFabricUIManager.setIsJSResponder(to.stateNode.node, true);
}
} else {
UIManager.clearJSResponder();
if (to !== null) {
const tag = to.stateNode.canonical._nativeTag;
UIManager.setJSResponder(tag, blockNativeResponder);
} else {
UIManager.clearJSResponder();
}
}
},
};
Expand Down
Expand Up @@ -176,6 +176,7 @@ const RCTFabricUIManager = {
);
success(1, 1, 100, 100);
}),
setIsJSResponder: jest.fn(),
};

global.nativeFabricUIManager = RCTFabricUIManager;
1 change: 1 addition & 0 deletions scripts/flow/react-native-host-hooks.js
Expand Up @@ -179,6 +179,7 @@ declare var nativeFabricUIManager: {
locationY: number,
callback: (Fiber) => void,
) => void,
setIsJSResponder: (node: Node, isJsResponder: boolean) => void,
...
};

Expand Down

0 comments on commit 78d2f2d

Please sign in to comment.