美文网首页
react-native 获取View动态高度

react-native 获取View动态高度

作者: 朱传武 | 来源:发表于2021-11-23 15:51 被阅读0次

    直接上代码

    const ref = useRef<View | null>(null);
    
    <View
            ref={ref}
            style={[t.pB8]}
            onLayout={(event) => {
              if (ref) {
                ref?.current?.measure((x, y, width, height, pageX, pageY) => {
                  console.log(x, y, width, height, pageX, pageY);
                });
              }
            }}
          >
    

    控制台打印结果


    image.png

    其中onLayout只能拿到x、y、width、height,拿不到PageY,而pageY才是相对于屏幕的坐标

    相关文章

      网友评论

          本文标题:react-native 获取View动态高度

          本文链接:https://www.haomeiwen.com/subject/eomwtrtx.html