获取React Native ScrollView缩放或缩放尺寸

Emm*_*ams 5 javascript react-native react-native-ios

有没有办法引用缩放的ScrollView的当前尺寸或比例?该文档提到了zoomScale,但是返回为undefined.

到目前为止我已尝试过以下内容:

onScrollUpdate() {
    console.log(this.refs.pageScrollView.zoomScale); // returns undefined
    RCTUIManager.measure(findNodeHandle(this.refs.pageScrollView), (x, y, width, height, pageX, pageY) => {
    console.log(width); // returns initial size, but not scaled - this number change when zooming
  });
 }
<ScrollView
    ref='pageScrollView'
    onScroll={this.onScrollUpdate.bind(this)}
    minimumZoomScale={0.95}
    maximumZoomScale={2}
    showsHorizontalScrollIndicator={false}
    showsVerticalScrollIndicator={false}
    scrollEventThrottle={2}
  >
Run Code Online (Sandbox Code Playgroud)

编辑:我找到了答案,所以这可能有助于其他人.onScroll事件接收包含zoomScale数量的nativeEvent:

onScrollUpdate(event) {
    console.log(event.nativeEvent.zoomScale)  // returns accurate zoomscale
}
Run Code Online (Sandbox Code Playgroud)

sta*_*all 0

解决方案来自@EmmaWilliams的问题帖子。

onScroll 事件接收一个包含 ZoomScale 数量的 nativeEvent:

onScrollUpdate(event) {
    console.log(event.nativeEvent.zoomScale)  // returns accurate zoomscale
}
Run Code Online (Sandbox Code Playgroud)