BridgelessUIManager: Finish findSubviewIn

Summary:
This is an implementation of UIManagerModule.findSubviewIn, based on the [Fabric renderer](https://github.com/facebook/react-fbsource-import/blob/772935f7320f37a14ef06a9616dd43fa090d54a3/compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js#L28899-L28953).

UIManager.findSubviewIn(viewTag, point, callback)

The point is relative to viewTag's parent's (0, 0).

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D52642884

fbshipit-source-id: 775e98d23ff42d41c30644b82f5f67e788df4ee6
This commit is contained in:
Ramanpreet Nara
2024-01-26 08:42:02 -08:00
committed by Facebook GitHub Bot
parent 5f75e9b90d
commit 6c4ef54708
4 changed files with 69 additions and 1 deletions
@@ -336,7 +336,54 @@ const UIManagerJS: UIManagerJSInterface & {[string]: any} = {
height: number,
) => void,
): void => {
raiseSoftError('findSubviewIn');
if (reactTag == null) {
console.error(
`findSubviewIn() noop: Cannot be called with ${String(
reactTag,
)} reactTag`,
);
return;
}
const FabricUIManager = nullthrows(getFabricUIManager());
const shadowNode = FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag);
if (!shadowNode) {
console.error(
`findSubviewIn() noop: Cannot find view with reactTag ${reactTag}`,
);
return;
}
FabricUIManager.findNodeAtPoint(
shadowNode,
point[0],
point[1],
function (internalInstanceHandle) {
if (internalInstanceHandle == null) {
console.error('findSubviewIn(): Cannot find node at point');
return;
}
let instanceHandle: Object = internalInstanceHandle;
let node = instanceHandle.stateNode.node;
if (!node) {
console.error('findSubviewIn(): Cannot find node at point');
return;
}
let nativeViewTag = (instanceHandle.stateNode.canonical
.nativeTag: number);
FabricUIManager.measure(
node,
function (x, y, width, height, pageX, pageY) {
callback(nativeViewTag, pageX, pageY, width, height);
},
);
},
);
},
viewIsDescendantOf: (
reactTag: ?number,
@@ -64,6 +64,12 @@ export interface Spec {
commandName: string,
args: Array<mixed>,
) => void;
+findNodeAtPoint: (
node: Node,
locationX: number,
locationY: number,
callback: (instanceHandle: ?InternalInstanceHandle) => void,
) => void;
/**
* Support methods for the DOM-compatible APIs.
@@ -292,6 +292,15 @@ const FabricUIManagerMock: IFabricUIManagerMock = {
findShadowNodeByTag_DEPRECATED: jest.fn((reactTag: number): ?Node => {}),
findNodeAtPoint: jest.fn(
(
node: Node,
locationX: number,
locationY: number,
callback: (instanceHandle: ?InternalInstanceHandle) => void,
): void => {},
),
getBoundingClientRect: jest.fn(
(
node: Node,
@@ -6564,6 +6564,12 @@ export interface Spec {
commandName: string,
args: Array<mixed>
) => void;
+findNodeAtPoint: (
node: Node,
locationX: number,
locationY: number,
callback: (instanceHandle: ?InternalInstanceHandle) => void
) => void;
+getParentNode: (node: Node) => ?InternalInstanceHandle;
+getChildNodes: (node: Node) => $ReadOnlyArray<InternalInstanceHandle>;
+isConnected: (node: Node) => boolean;