-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Question: Is it possible to get the screen position of an element / component? #1374
Comments
I believe what you are looking for is var RCTUIManager = require('NativeModules').UIManager;
//The following code executes inside one of your component's methods, post render
var view = this.refs['ref']; // Where view is a ref obtained through <View ref='ref'/>
var handle = React.findNodeHandle(view);
RCTUIManager.measure(handle, (x, y, width, height, pageX, pageY) => {
//Do stuff with the values
}) |
I believe you are right. Thank you :) |
But how to add the popular menu dynamic? |
I'm sorry, I'm afraid I didn't understand the question. You want to add a menu on the position of an element? |
Hi @iostalk. I am implementing the menu by using @brentvatne's modal plugin then passing a complete collection of stylds into it (take a look at the modalstyle included in the the source).. you can then pass in the screen coordinates (derived from @JohnyDays code) that you'd like the modal window to show based on the size of your modal / touchable object. |
The solution to use |
@a-koka
or this way
|
Thanks to hey99xx for his help in #12966 Collapsable property is explained at https://facebook.github.io/react-native/docs/view.html#collapsable
However, some of UIManager functions such as measure expect to find a native view; and when it can't it returns undefined values instead of throwing an error. Really it would be better to throw an error. React unfortunately is not intelligent to know you would be measuring the view in the first place. |
In my case, I need to measure the x and y coordinate on the click of an element which is inside a scroll view. So it gives me different px and py everytime I click on the element. also, the value differs based on the scrolling |
@rajsuvariya did you able to get the position of an element even inside a scrollview? |
@gitlovenotwar No I was not able to get the position inside scroll view. But I had only one component inside scrollview so I removed scrollview and now I have only listview which gives me exact position of elemtn |
@JohnyDays how can i get the position of cursor in ScrollView containing TextInput? |
use case:
I would like to add a small popUp menu at the location of a button on the page. THe button would be inside a list view though so isn't in a fixed position.
Thanks, and keep up the good work! :) 👍
The text was updated successfully, but these errors were encountered: