Skip to content

Commit 6c4ef54

Browse files
RSNarafacebook-github-bot
authored andcommitted
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
1 parent 5f75e9b commit 6c4ef54

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

packages/react-native/Libraries/ReactNative/BridgelessUIManager.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,54 @@ const UIManagerJS: UIManagerJSInterface & {[string]: any} = {
336336
height: number,
337337
) => void,
338338
): void => {
339-
raiseSoftError('findSubviewIn');
339+
if (reactTag == null) {
340+
console.error(
341+
`findSubviewIn() noop: Cannot be called with ${String(
342+
reactTag,
343+
)} reactTag`,
344+
);
345+
return;
346+
}
347+
348+
const FabricUIManager = nullthrows(getFabricUIManager());
349+
const shadowNode = FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag);
350+
351+
if (!shadowNode) {
352+
console.error(
353+
`findSubviewIn() noop: Cannot find view with reactTag ${reactTag}`,
354+
);
355+
return;
356+
}
357+
358+
FabricUIManager.findNodeAtPoint(
359+
shadowNode,
360+
point[0],
361+
point[1],
362+
function (internalInstanceHandle) {
363+
if (internalInstanceHandle == null) {
364+
console.error('findSubviewIn(): Cannot find node at point');
365+
return;
366+
}
367+
368+
let instanceHandle: Object = internalInstanceHandle;
369+
let node = instanceHandle.stateNode.node;
370+
371+
if (!node) {
372+
console.error('findSubviewIn(): Cannot find node at point');
373+
return;
374+
}
375+
376+
let nativeViewTag = (instanceHandle.stateNode.canonical
377+
.nativeTag: number);
378+
379+
FabricUIManager.measure(
380+
node,
381+
function (x, y, width, height, pageX, pageY) {
382+
callback(nativeViewTag, pageX, pageY, width, height);
383+
},
384+
);
385+
},
386+
);
340387
},
341388
viewIsDescendantOf: (
342389
reactTag: ?number,

packages/react-native/Libraries/ReactNative/FabricUIManager.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export interface Spec {
6464
commandName: string,
6565
args: Array<mixed>,
6666
) => void;
67+
+findNodeAtPoint: (
68+
node: Node,
69+
locationX: number,
70+
locationY: number,
71+
callback: (instanceHandle: ?InternalInstanceHandle) => void,
72+
) => void;
6773

6874
/**
6975
* Support methods for the DOM-compatible APIs.

packages/react-native/Libraries/ReactNative/__mocks__/FabricUIManager.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,15 @@ const FabricUIManagerMock: IFabricUIManagerMock = {
292292

293293
findShadowNodeByTag_DEPRECATED: jest.fn((reactTag: number): ?Node => {}),
294294

295+
findNodeAtPoint: jest.fn(
296+
(
297+
node: Node,
298+
locationX: number,
299+
locationY: number,
300+
callback: (instanceHandle: ?InternalInstanceHandle) => void,
301+
): void => {},
302+
),
303+
295304
getBoundingClientRect: jest.fn(
296305
(
297306
node: Node,

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6564,6 +6564,12 @@ export interface Spec {
65646564
commandName: string,
65656565
args: Array<mixed>
65666566
) => void;
6567+
+findNodeAtPoint: (
6568+
node: Node,
6569+
locationX: number,
6570+
locationY: number,
6571+
callback: (instanceHandle: ?InternalInstanceHandle) => void
6572+
) => void;
65676573
+getParentNode: (node: Node) => ?InternalInstanceHandle;
65686574
+getChildNodes: (node: Node) => $ReadOnlyArray<InternalInstanceHandle>;
65696575
+isConnected: (node: Node) => boolean;

0 commit comments

Comments
 (0)