测量react-native ref的高度(ListView)

时间:2016-08-18 21:52:30

标签: react-native react-native-listview react-native-scrollview nativemethodsmixin

如果只有ref,如何衡量反应原生元素的高度?

我看到NativeMethodsMixin,但目前尚不清楚如何实施它。

我尝试将其包含为:

import { NativeMethodsMixin } from 'react-native';
class Foo extends Component {
  mixins: [NativeMethodsMixin]
  measure(ref) {
    console.log(NativeMethodsMixin.measure(ref));
  }
  ...
}

但该应用抱怨NativeMethodsMixin未定义。

如果我走RCTUIManager路线:

import { NativeModules } from 'react-native';
const RCTUIManager = NativeModules.UIManager;
class Foo extends Component {
  measure(ref) {
    const height = RCTUIManager.measure(ref, (x, y, width, height, pageX, pageY) => height));
    console.log(height);
  }
  ...
}

然后我收到错误:Uncaught TypeError: Converting circular structure to JSON

我只想获得ref的高度。我错过了什么?

1 个答案:

答案 0 :(得分:0)

你可以这样做:

    this.refs[your ref key].measure((fx, fy, width, height, px, py) => {
          this.state.origins.push({
            x: px,
            y: py,
            width,
            height,
          });
        });

此链接可能有用:click here