我是React Native的新手。我有一个带有ScrollView组件和其中几个自定义组件的应用程序。我想从ScrollView触发一个onPressOut事件,以便当用户滚动和释放时,ScrollView内的子组件更新其状态。但是,ScrollView文档不包含任何新闻事件:https : //facebook.github.io/react-native/docs/scrollview.html
我尝试过的其他方法:
2015-10-26 11:59:13.849 [错误] [tid:com.facebook.React.ShadowQueue] [RCTModuleMethod.m:60] RCTUIManager.measure的参数0(NSNumber)不能为空2015-10-26 11 :59:13.850 [错误] [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>
当我将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>
并在该类中定义一个处理程序:
onResponderRelease(){
//do stuff
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句