9

我想测量我的ScrollView.

因此,我使用measurefrom NativeMethodsMixin

import NativeMethodsMixin from 'NativeMethodsMixin'

我不太确定从这里去哪里,与此问题相关的大多数 SO 帖子似乎都已过时。

我知道我需要为ref我创建一个ScrollView(我做了并调用_scrollView了它,我可以使用它来访问它this.refs._scrollView)。

问题是,我不能像这样this.refs._scrollView传入measure

NativeMethodsMixin.measure(this.refs._scrollView, (data) => {
  console.log('measure: ', data)
})

然后我收到以下错误:

ExceptionsManager.js:61 findNodeHandle(...): Argument is not a component (type: object, keys: measure,measureInWindow,measureLayout,setNativeProps,focus,blur,componentWillMount,componentWillReceiveProps)

然后我尝试检索实际的节点句柄findNodeHandle,并将其传递measure到此github 问题中讨论的内容:

const handle = React.findNodeHandle(this.refs._scrollView)
NativeMethodsMixin.measure(handle, (data) => {
  console.log('measure: ', data)
})

但这会导致相同的错误。有任何想法吗?

4

2 回答 2

24

ScrollView 定义了一个名为onContentSizeChange的道具:

<ScrollView
  onContentSizeChange={(width, height) => {
    console.log(width, height);
  }}>
  {content}
</ScrollView>
于 2016-04-20T07:03:18.597 回答
6
NativeMethodsMixin.measure.call(elementToMeasure, (x, y, width, height) => {
  ...
});
于 2016-05-25T17:56:06.633 回答