如果您知道,请帮助我在 React Native ScrollView 中获取视图 Y 位置。 在这个组件中,我使用 onLayout 回调 handleLayout 在 ScrollView 中获取 View 的 Y 位置并将每个人的位置添加到数组中,然后我 console.log 我的数组,并接收一些特殊的东西(截图)。在某些情况下,contactJumpArr[i + 1] < contactJumpArr[i]。如何获得适当的布局 y 位置?我需要在 ScrollView 中实现滚动到特定视图。谢谢解答!
const handleLayout = (event) => {
const { layout } = event.nativeEvent;
setContactJumpArr([...contactJumpArr, layout.y]);
};
<View style={{flex:1, flexDirection:'row'}}>
<ScrollView ref={contactRef}>
{!queriedContactList.length && groupedContactsList ? (
Object.keys(groupedContactsList).map((key) => {
return (
<View onLayout={handleLayout}>
<Text font={17} bold color={Colors.BLUE_DARK} style={padding(0, 14, 0, 14)}>
{key}
</Text>
<ContactsList data={groupedContactsList[key]} />
</View>
);
})
) : (
<ContactsList data={renderData} />
)}
</ScrollView>
<View>