Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add viewIsDescendantOf for UIManager on Android #13129

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,23 @@ public final int getTotalNativeChildren() {
return mTotalNativeChildren;
}

public boolean isDescendantOf(ReactShadowNode ancestorNode) {
ReactShadowNode parentNode = getParent();

boolean isDescendant = false;

while (parentNode != null) {
if (parentNode == ancestorNode) {
isDescendant = true;
break;
} else {
parentNode = parentNode.getParent();
}
}

return isDescendant;
}

/**
* Returns the offset within the native children owned by all layout-only nodes in the subtree
* rooted at this node for the given child. Put another way, this returns the number of native
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,22 @@ public void findSubviewIn(int reactTag, float targetX, float targetY, Callback c
mOperationsQueue.enqueueFindTargetForTouch(reactTag, targetX, targetY, callback);
}

/**
* Check if the first shadow node is the descendant of the second shadow node
*/
public void viewIsDescendantOf(
final int reactTag,
final int ancestorReactTag,
final Callback callback) {
ReactShadowNode node = mShadowNodeRegistry.getNode(reactTag);
ReactShadowNode ancestorNode = mShadowNodeRegistry.getNode(ancestorReactTag);
if (node == null || ancestorNode == null) {
callback.invoke(false);
return;
}
callback.invoke(node.isDescendantOf(ancestorNode));
}

/**
* Determines the location on screen, width, and height of the given view relative to the root
* view and returns the values via an async callback.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,17 @@ public void findSubviewIn(
callback);
}

/**
* Check if the first shadow node is the descendant of the second shadow node
*/
@ReactMethod
public void viewIsDescendantOf(
final int reactTag,
final int ancestorReactTag,
final Callback callback) {
mUIImplementation.viewIsDescendantOf(reactTag, ancestorReactTag, callback);
}

/**
* Registers a new Animation that can then be added to a View using {@link #addAnimation}.
*/
Expand Down