-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Adds the ability to use UIManager to check if a node is an ancestor #7876
Conversation
@alvaromb updated the pull request. |
Probably I should change the name of the function from |
I’m not really the right person to judge the functional changes of this PR, but my one point of feedback is that your motivation doesn’t really outline why you want to be able to do this, which makes it harder to understand if this is the right solution. Your code example also doesn’t illustrate a real-world use-case. |
} | ||
if (!ancestor) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe combine these into a single if (view && ancestor) { … }
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do that. I've just followed the style of the RCTMeasureLayout
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s totally fair. I’m just providing some general code feedback, following existing styles is definitely a good choice 👍
While I left some general code feedback (just to be somewhat useful :)), I’ll stress again that this is just that, I’m not the one to decide if this is going to be accepted. |
Sorry if the example isn't clear. Will try to explain why I need this. Lets say we have a bunch of screens with TextInput.State.currentlyFocusedField() This will return a tag number which represents the node of the input focused. With However, the problem arises when you have more than one The solution I came for this specific case was to export a functionality that, in the end, is already present in the I hope to have shed some light into the motivations of the PR, and thanks @alloy for your suggestions. |
Any updates on this? |
I'll find some time today to perform the pending changes. |
Wow, just came to that issue, and the solution is already on the way! 👍 |
I've added the detailed suggestions and rebased against master. |
- Change method name "viewIsAncestorOf" as "viewIsDescendantOf" according to PR facebook/react-native#7876
Any update on this? |
@alvarom any update on this PR? |
I can update the PR @JosephkimOS, but I don't have any feedback from the Facebook team yet. Let's see if @mkonicek or @vjeux can help us here 😃 |
Any updates on this? |
@facebook-github-bot shipit |
Thanks for importing. |
Summary: Sometimes is handy to check if a React node is a descendant of another node or not. For instance, I want to check if the focused `TextInput` is descendant of an specific `ScrollView`: ```js const currentlyFocusedField = TextInput.State.currentlyFocusedField() UIManager.viewIsAncestorOf( currentlyFocusedField, this.getInnerViewNode(), (isAncestor) => { if (isAncestor) { console.log('The focused field is a descendant of this ScrollView!') } } ) ``` This function uses the same strategy as the `measureLayout` method to check if one node is an ancestor of other node. As the `measureLayout` method, this is performed outside the main thread. By now I've only implemented the iOS version and its tests, but if this function is going to be merged I'll implement the Android version too. I have objc experience but no Java or Android, so I prefer to validate this functionality before jumping into developing the Android part. Closes facebook#7876 Differential Revision: D3662045 Pulled By: javache fbshipit-source-id: b9668e8ea94fd01db76651f16243926cf9c2566f
Yeah! Shipit! :) Thanks for doing this guys. What version or RN will we see this code in? |
This should be in react-native 0.32 |
finally! |
Thanks @javache! I'm going to dig into Android code to send a PR with the same functionality. |
Summary: Sometimes is handy to check if a React node is a descendant of another node or not. For instance, I want to check if the focused `TextInput` is descendant of an specific `ScrollView`: ```js const currentlyFocusedField = TextInput.State.currentlyFocusedField() UIManager.viewIsAncestorOf( currentlyFocusedField, this.getInnerViewNode(), (isAncestor) => { if (isAncestor) { console.log('The focused field is a descendant of this ScrollView!') } } ) ``` This function uses the same strategy as the `measureLayout` method to check if one node is an ancestor of other node. As the `measureLayout` method, this is performed outside the main thread. By now I've only implemented the iOS version and its tests, but if this function is going to be merged I'll implement the Android version too. I have objc experience but no Java or Android, so I prefer to validate this functionality before jumping into developing the Android part. Closes facebook/react-native#7876 Differential Revision: D3662045 Pulled By: javache fbshipit-source-id: b9668e8ea94fd01db76651f16243926cf9c2566f
TextInput keep crush when goes to next page. i really need this issue to be fix. when is 0.32 roll out!? |
32-rc is out.. |
@cbcye that screenshot does not belong to this issue. This PR was accepted and should land into RN 0.32 or 0.33. |
Summary: Sometimes is handy to check if a React node is a descendant of another node or not. For instance, I want to check if the focused `TextInput` is descendant of an specific `ScrollView`: ```js const currentlyFocusedField = TextInput.State.currentlyFocusedField() UIManager.viewIsAncestorOf( currentlyFocusedField, this.getInnerViewNode(), (isAncestor) => { if (isAncestor) { console.log('The focused field is a descendant of this ScrollView!') } } ) ``` This function uses the same strategy as the `measureLayout` method to check if one node is an ancestor of other node. As the `measureLayout` method, this is performed outside the main thread. By now I've only implemented the iOS version and its tests, but if this function is going to be merged I'll implement the Android version too. I have objc experience but no Java or Android, so I prefer to validate this functionality before jumping into developing the Android part. Closes facebook#7876 Differential Revision: D3662045 Pulled By: javache fbshipit-source-id: b9668e8ea94fd01db76651f16243926cf9c2566f
@alvaromb i upgrade to RN 0.34 but still occur this problem. |
@cbcye remove the |
@atlas1119 I think that this hasn't landed in Android yet #13129 |
Motivation
Sometimes is handy to check if a React node is a descendant of another node or not. For instance, I want to check if the focused
TextInput
is descendant of an specificScrollView
:This function uses the same strategy as the
measureLayout
method to check if one node is an ancestor of other node. As themeasureLayout
method, this is performed outside the main thread.By now I've only implemented the iOS version and its tests, but if this function is going to be merged I'll implement the Android version too. I have objc experience but no Java or Android, so I prefer to validate this functionality before jumping into developing the Android part.