ReactNative get the absolute position of a view relative to the screen

后端 未结 2 1440
太阳男子
太阳男子 2021-02-20 08:46

with react native.

I can get the position and size with onLayout, but I want to get the absolute position of a view relative to the screen

please! t

2条回答
  •  甜味超标
    2021-02-20 09:22

    you can use measure(callback) it Determines the location on screen, width, and height of the given view and returns the values via an async callback.

    a better example can be found here React Native: Getting the position of an element

     { this.marker = ref }}
      onLayout={({nativeEvent}) => {
        if (this.marker) {
          this.marker.measure((x, y, width, height, pageX, pageY) => {
                    console.log(x, y, width, height, pageX, pageY);
           })
        }
      }}
     >
    

提交回复
热议问题