Jac*_*ish 3 scrollview ios react-native
我是React Native 的新手。我有一个带有ScrollView组件和几个自定义组件的应用程序。我想从 ScrollView 触发一个 onPressOut 事件,以便当用户滚动和释放时,ScrollView 内的子组件更新它们的状态。但是,ScrollView 文档不包括任何新闻事件:https : //facebook.github.io/react-native/docs/scrollview.html
我尝试过的其他事情:
2015-10-26 11:59:13.849 [error][tid:com.facebook.React.ShadowQueue][RCTModuleMethod.m:60] RCTUIManager.measure 的参数 0 (NSNumber) 不能为空 2015-10-26 11 :59:13.850 [error][tid:com.facebook.React.ShadowQueue][RCTModuleMethod.m:60] 无法处理 RCTUIManager.measure 的参数 0 ()。中止方法调用。
不知道这意味着什么......有什么想法吗?谢谢!
这是我的代码:
<View ref="theWrapperView" style={styles.theWrapperView}>
<ScrollView
onScroll={this.onScroll.bind(this)}
onMomentumScrollEnd={this.onScrollAnimationEnd.bind(this)}
style={styles.scrollView}
contentContainerStyle={styles.scrollViewContentContainer}
showsHorizontalScrollIndicator={true}
scrollEventThrottle={10}
pagingEnabled={true}
horizontal={true}
automaticallyAdjustContentInsets={false}
snapToAlignment={'center'}
snapToInterval={20}
zoomScale={1.5}
centerContent = {true}
>
{cards}
</ScrollView>
</View>
Run Code Online (Sandbox Code Playgroud)
当我将 View 元素更改为 TouchableWithoutFeedback 元素时,我收到了错误消息。
我在调查 React Native 源代码后发现了这一点:https : //github.com/facebook/react-native/blob/master/Libraries/Components/ScrollResponder.js
事实证明,实际上还有许多其他事件可以通过 ScrollResponder mixin 使用,但在线文档中没有提到这些事件。不需要包含 mixin 来访问这些事件,因为它们已经是 ScrollView 组件的一部分。对我有用的是 onResponderRelease,它会在您释放 ScrollView 时触发,如下所示:
<View ref="theWrapperView" style={styles.theWrapperView}>
<ScrollView
onScroll={this.onScroll.bind(this)}
onMomentumScrollEnd={this.onScrollAnimationEnd.bind(this)}
onResponderRelease = {this.onResponderReleaseHandler.bind(this)}
>
{cards}
</ScrollView>
</View>
Run Code Online (Sandbox Code Playgroud)
并在类中定义一个处理程序:
onResponderRelease(){
//do stuff
}
Run Code Online (Sandbox Code Playgroud)