繁体   English   中英

React-native Flatlist 自动滚动

[英]React-native Flatlist auto scroll

我在 react native 中有一个平面列表,其中包含展开和折叠的项目(就像下拉菜单一样),所以每当单击项目展开时,如果项目内容在屏幕中溢出。我想滚动项目以便它的内容完全可见。 我该如何实施?

  • 在这种情况下, scrollToIndex将不起作用,对于scrollToOffset ,我如何确定被点击项目在屏幕上的位置?

您可以使用measure获取元素的偏移量,然后使用scrollToOffset

<Component ref="myComponent />
// Print component dimensions to console
this.refs.myComponent.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)
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM