Skip to content

Commit

Permalink
Fabric-compatible implementation of JSReponder feature
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 9, 2021
1 parent 6c526c5 commit 69d32b2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,33 @@ 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 69d32b2

Please sign in to comment.