如何测量页面中列表视图行的位置

How to measure a list view row location in a page

我正在使用 React Native Listview 组件。

如何测量一行的坐标? 我需要知道我在更复杂的视图中执行的动画的这些坐标。

我从 NativeMethodsMixin 找到了方法 measure,但我无法使用它。我收到以下错误:measure is not a function

如何在需要时使用测量函数获取一行的坐标?

最小起点:

class MyComponent extends Component { 
   constructor() { 
     super(); 
     const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); 
     this.rows = []
     this.state = { dataSource: ds.cloneWithRows(['row 1', 'row 2'])}; 
   } 
   render() { 
    return ( 
       <ListView dataSource={this.state.dataSource} renderRow={
            (rowData) => 
                 <TouchableWithoutFeedback
                    ref={(row) => {
                       this.rows[rowData] = row
                    }}
                    onPress={(event) => {
                       this.rows[rowData].measure(
                          (x, y, width, height, pageX, pageY) => {})
                    }}>
                    <Text>{rowData}</Text>
                 </TouchableWithoutFeedback>
       } /> 
    ); 
  } 
}

我认为无法测量 TouchableWithoutFeedback。这是一个问题吗?我不确定这是否是预期的行为。

我通过将 TouchableWithoutFeedback 包装在视图中并测量视图来让它工作!