React Native: Getting the position of an element

前端 未结 6 562
太阳男子
太阳男子 2020-11-28 03:08

I am styling an Image component with flexbox to be in the center of the screen which works pretty well. Now I want a second Image component to be d

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 03:38

    This seems to have changed in the latest version of React Native when using refs to calculate.

    Declare refs this way.

       {
        this._image = image
      }}>
    

    And find the value this way.

      _measure = () => {
        this._image._component.measure((width, height, px, py, fx, fy) => {
          const location = {
            fx: fx,
            fy: fy,
            px: px,
            py: py,
            width: width,
            height: height
          }
          console.log(location)
        })
      }
    

提交回复
热议问题