我试图从特定的视图中获取一些度量值,以查看视图的位置。在此之后,我想实现一个scrollto函数。
我使用以下代码作为句柄:
_handleItemClicked = (index) => () => {
this.sectionItem[index].measure( (fx, fy, width, height, px, py) => {
console.log('Component width is: ' + width)
console.log('Component height is: ' + height)
console.log('X offset to frame: ' + fx)
console.log('Y offset to frame: ' + fy)
console.log('X offset to page: ' + px)
console.log('Y offset to page: ' + py)
})
}
我用这段代码来创建视图
renderItem = ({item, index, section}) => (
<TouchableNativeFeedback ref={view => { this.sectionItem[index] = view; }} onPress={this._handleItemClicked(index)}>
<View style={styles.itemrow} >
<View style={{width:80,marginLeft:10,height:30}}><Text style={{textAlign:'right',color:'#000',opacity:0.9,fontSize:18,marginTop:4}}>{item.title}</Text></View>
</View>
</View>
</TouchableNativeFeedback>
);
我尝试了一些其他的方法,但是到目前为止还没有成功。我总是以一些错误结束。这次它是undefined,不是一个对象。
期待答案。
1条答案
按热度按时间p1tboqfb1#
试试这个:
我猜它试图在范围内找到sectionItem,但无法找到,给你一个未定义的错误。
如果你像上面那样做,它会把一个带索引的ref放在this中。