React Native Lottie - 动画结束反转

Sam*_*ney 2 loops native reactjs lottie

语境

我是 lottie-react-native 的新手,并设法实现了我的第一个动画:

constructor(props) {
    super(props);
    this.state = {
        progress: new Animated.Value(0),
        loop: true
    }
}
componentDidMount() {
    this.animation.play();
}
render() {
const { progress, loop } = this.state;
return (
    <View style={{display:'flex',height:'auto', alignItems: 'center',justifyContent:'center'}}>
    <LottieView
    ref={animation => {
        this.animation = animation;
      }}
    speed={1}
    autoPlay
    source={NOACTIVITY}
    progress={progress}
    loop={loop}
    height={300}
    width={300}
    style={{margin:0,}}
  />
  </View>
)
Run Code Online (Sandbox Code Playgroud)

}

问题

我现在正在尝试使用此动画创建一个循环,向前播放,然后向后播放,然后再次开始该过程。

我做了一些研究并得出结论,这必须使用动画值和时间来完成?我发现了许多向前和向后播放但不一起播放的示例(在 react native docs 中!)。

这可以在组件安装时完成吗?或者它必须是一个单独的功能?

提前致谢!

Sam*_*ney 5

我想出的解决方案是在循环中使用一个序列,如下所示:

AnimateFunction = () => {
    Animated.loop(
        Animated.sequence([
            Animated.timing(
                this.state.progress,
                {
                  toValue: 1,
                  duration: (5000),
                  //easing: Easing.linear()
                }
              ),
              Animated.timing(
                this.state.progress,
                {
                  toValue: 0,
                  duration: (5000),
                  //easing: Easing.linear()
                }
              )
        ])

    ).start();
  }
Run Code Online (Sandbox Code Playgroud)

我发现当应用程序从 0 重新启动时,添加缓动会使动画跳跃一点,因此现在将其注释掉。