简体   繁体   English

反应原生panResponder动画

[英]React native panResponder Animation

I have a lottie component, which should run with a new animated value each time when you swipe a screen. 我有一个Lottie组件,每当您滑动屏幕时,它都应该以新的动画值运行。 Now it's increase an animated value to 0.3 when swipe from left to right and decrease to 0 if swipe opposite direction. 现在,当从左向右滑动时,将动画值增加到0.3;如果向相反方向滑动,则将动画值减小到0。

What I'm trying to do, is when you swipe a screen again, value should become 0.6. 我想做的是,当您再次滑动屏幕时,值应变为0.6。 and on third swipe 0.9. 并在第三次滑动0.9。

Could you give me an idea how to do it? 你能给我个主意吗?

 onPanResponderMove: (evt, gesture) => {
const { dx } = gesture;
if (dx > 30) {
   Animated.timing(this.state.scrollX, {
      toValue: 0.3,
      duration: 500,
    }).start();
  } else {
    Animated.timing(this.state.scrollX, {
      toValue: 0,
    }).start();
  }
}
render(){
  return(
    <View>
    <LottieView
          style={styles.lottie}
          source={require('../../assets/lottie/auth_animation.json')}
          progress={this.state.scrollX}
        />
    </View>
  )
}

Store the value for toValue outside the onPanResponderMove function. 将toValue的值存储在onPanResponderMove函数之外。 On each swipe increase it with 0.3 for the next swipe. 每次滑动时,将其增加0.3,以进行下一次滑动。

toValue = 0;
onPanResponderMove: (evt, gesture) => {
    const { dx } = gesture;
    if (dx > 30) {
        toValue += 0.3;
        Animated.timing(this.state.scrollX, {
            toValue,
            duration: 500,
        }).start();
    } else {
        Animated.timing(this.state.scrollX, {
            toValue: 0,
        }).start();
    }
}

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

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