I need to find out position of item in the list view (like rectForRowAtIndexPath does for UITableView), how it is possible?
Asked
Active
Viewed 350 times
2 Answers
1
I believe that this will work:
make sure each item has unique ref prop (more about ref props in React documentation: https://facebook.github.io/react/docs/more-about-refs.html)
in your code whenever you need call "measure" method on this.refs.your_reference. Make sure it is in componentDidMount(), however there might be a need to (Warning! Hacks!) to call it via setTimeout method as described here React-Native : measure a View

Community
- 1
- 1

Jarek Potiuk
- 19,317
- 2
- 60
- 61
-
Could you give code example? Even with setTimeout it doesn't work ("undefined is not an object (evaluating this.refs.itm0.measure), probably because refs are not available at that time? – aksonov Jun 26 '15 at 20:22
1
I use the built in onLayout function for a view. For instance:
<View onLayout={this.handleLayout}/>
Then your function will have:
handleLayout: function(event){
var {x, y, width, height} = event.nativeEvent.layout;
console.log('x pos:' + x + ' / y pos:' + y + ' / width:' + width + ' / height:' + height);
},
Hope this helps!

yamill
- 64
- 6
-
Strange, it doesn't work well for several sections - it returns x,y _relative_ position to this parent view. Do you know how to receive absolute x,y ? – aksonov Jul 02 '15 at 10:52
-
From what I know this will only read the parent view. Not sure if there is another method for that. – yamill Jul 02 '15 at 14:09