在 ScrollView 中获取 View Y 位置时出错

问题描述

如果您知道,请帮助我在 React Native ScrollView 中获取视图 Y 位置。 在这个组件中,我使用 onLayout 回调 handleLayout 在 ScrollView 中获取 View 的 Y 位置并将每个人的位置添加到数组中,然后我 console.log 我的数组,并接收一些特殊的东西(截图)。在某些情况下,contactJumpArr[i + 1]

  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,14)}>
                    {key}
                  </Text>
                  <ContactsList data={groupedContactsList[key]} />
                </View>
              );
            })
          ) : (
            <ContactsList data={renderData} />
          )}
        </ScrollView>
        <View>

result of contactJumpArr console.log

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)