简体   繁体   English

React Native如何在同一个动画事件中传递两个事件?

[英]React Native how to pass two events in the same animated event?

I have two actions passed through setParams 我有两个动作通过setParams传递

componentWillMount() {
                  this.props.navigation.setParams({
                    animatedValue: this._animatedValue.interpolate({
                    inputRange: [0, 800],
                    outputRange: [0, -70],
                    extrapolate: 'clamp'
                  }),
                  colorRange: this.x.interpolate({
                    inputRange: [0, 5,10,15,20,25,30,35,40,49,56],
                    outputRange: ['rgba(0, 0, 0,0)', 'rgba(255, 0, 0,0.1)', 'rgba(255, 0, 0,0.2)', 'rgba(255, 0, 0,0.3)', 'rgba(255, 0, 0,0.4)', 'rgba(255, 0, 0,0.5)', 'rgba(255, 0, 0,0.6)', 'rgba(255, 0, 0,0.7)', 'rgba(255, 0, 0,0.8)', 'rgba(255, 0, 0,0.9)' ,'rgba(255, 0, 0,1)'],
                    extrapolate: 'clamp'
                  })
                });
                }

and in my only use one animated event. 在我唯一使用一个动画事件。 How can I use both events when I scroll in vertically 当我垂直滚动时,如何使用这两个事件

<ScrollView onScroll={ Animated.event([{nativeEvent: {contentOffset: {y: this._animatedValue }}}] )} scrollEventThrottle={16} >

Since Animated.event accepts as many arguments you want and you pass a nativeEvent or a custom listener to it, let's try this: 由于Animated.event接受你想要的任何参数,并且你将nativeEvent或自定义监听器传递给它,让我们试试这个:

<ScrollView onScroll={ Animated.event(
  [{nativeEvent: {contentOffset: {y: this._animatedValue }}}],
  { listener: this._customListener },
)} scrollEventThrottle={16}>

And have your listener like: 让你的听众喜欢:

_customListener(e) {
  // do whatever you want using this.colorRange
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM