0

I need to find out position of item in the list view (like rectForRowAtIndexPath does for UITableView), how it is possible?

aksonov
  • 853
  • 6
  • 21

2 Answers2

1

I believe that this will work:

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