Skip to content

Commit

Permalink
BridgelessUIManager: Implement viewIsDescendantOf (#42209)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #42209

Implement UIManager.viewIsDescendentOf

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D52449786

fbshipit-source-id: b607b29da935f468b00303ba20e3fe92db5291bd
  • Loading branch information
RSNara authored and facebook-github-bot committed Jan 10, 2024
1 parent 65ddea8 commit 822bf52
Showing 1 changed file with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,53 @@ const UIManagerJS: UIManagerJSInterface & {[string]: any} = {
ancestorReactTag: ?number,
callback: (result: Array<boolean>) => void,
): void => {
raiseSoftError('viewIsDescendantOf');
if (reactTag == null) {
console.error(
`viewIsDescendantOf() noop: Cannot be called with ${String(
reactTag,
)} reactTag`,
);
return;
}

const FabricUIManager = nullthrows(getFabricUIManager());
const shadowNode = FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag);
if (!shadowNode) {
console.error(
`viewIsDescendantOf() noop: Cannot find view with reactTag ${reactTag}`,
);
return;
}

if (ancestorReactTag == null) {
console.error(
`viewIsDescendantOf() noop: Cannot be called with ${String(
ancestorReactTag,
)} ancestorReactTag`,
);
return;
}

const ancestorShadowNode =
FabricUIManager.findShadowNodeByTag_DEPRECATED(ancestorReactTag);
if (!ancestorShadowNode) {
console.error(
`viewIsDescendantOf() noop: Cannot find view with ancestorReactTag ${ancestorReactTag}`,
);
return;
}

// Keep this in sync with ReadOnlyNode.js
const DOCUMENT_POSITION_CONTAINED_BY = 16;

let result = FabricUIManager.compareDocumentPosition(
ancestorShadowNode,
shadowNode,
);

let isAncestor = (result & DOCUMENT_POSITION_CONTAINED_BY) !== 0;

callback([isAncestor]);
},
configureNextLayoutAnimation: (
config: Object,
Expand Down

0 comments on commit 822bf52

Please sign in to comment.