How to get dimensions and position of root elements in React Native

I use a framework called react-native-svgto draw SVG elements in my own edited form.

My goal is that when I click on a view (I use PanResponderin the global view to get this), the element that is closest to switches.

I have everything I need except one: I need to know the position of my svg elements, as well as their size, to find the one that was closest to the tap event.

Now I tried most of the available things, I would say:

  • onLayout: these svg elements are not representations and therefore do not call the onLayout callback.
  • this.refs.elem.measure: are the same as onLayoutthey are not representations, therefore the function is measureundefined.
  • UIManager.measure(ReactNative.findNodeHandle(this.refs.elem), callback): returns 0 for all values ​​except the Svg component of reaction-native-svg, but not for all others: G, Path, Line, etc.

So I was wondering if there is some other solution or if I am doomed. :) Do I have to change something in response-native-svg that would allow me to find these values ​​or is there any solution for me ?

Thank!

+4
source share
1 answer

Finally, I had to add some functions for reaction-native-svg so that I could get the size of the various elements.

This is not very well done, but I can return to it for a cleaner solution and send PR then.

Thank.

+1
source

Source: https://habr.com/ru/post/1659131/


All Articles