【问题标题】:Measure height of react-native ref (ListView)测量 react-native ref (ListView) 的高度
【发布时间】:2016-08-18 21:52:29
【问题描述】:

如果只有 ref,如何测量 react-native 元素的高度?

我看到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 的高度。我错过了什么?

【问题讨论】:

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


【解决方案1】:

你可以这样做:

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

此链接可能有帮助:click here

【讨论】:

    猜你喜欢
    • 2020-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    • 2018-08-15
    • 1970-01-01
    相关资源
    最近更新 更多