Skip to content

Commit

Permalink
BridgelessUIManager: Finish findSubviewIn
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RSNara authored and facebook-github-bot committed Jan 26, 2024
1 parent 5f75e9b commit 6c4ef54
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6c4ef54

Please sign in to comment.