Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs react native reanimated动画只启用一次_Reactjs_React Native_React Native Reanimated - Fatal编程技术网

Reactjs react native reanimated动画只启用一次

Reactjs react native reanimated动画只启用一次,reactjs,react-native,react-native-reanimated,Reactjs,React Native,React Native Reanimated,我正在使用reanimated在一个模态中创建一个自定义警报,它可以正常工作,但在该模态可见且内容更新后,动画仅在开始时工作一次,但动画无法工作 这是我的密码 componentDidUpdate() { // stopClock(clock); if (this.state.visible) { block([ timing(this.val, { toValue: 1, duration: 100,

我正在使用reanimated在一个模态中创建一个自定义警报,它可以正常工作,但在该模态可见且内容更新后,动画仅在开始时工作一次,但动画无法工作

这是我的密码

componentDidUpdate() {
    // stopClock(clock);
    if (this.state.visible) {
      block([
        timing(this.val, {
          toValue: 1,
          duration: 100,
          easing: Easing.inOut(Easing.ease),
        }).start(),
        spring(this.scale, {
          toValue: 1,
          damping: 12,
          mass: 0.6,
          stiffness: 150.6,
          overshootClamping: false,
          restSpeedThreshold: 0.1001,
          restDisplacementThreshold: 0.001,
        }).start(),
      ]);
    } else {
      block([
        timing(this.val, {
          toValue: 0,
          duration: 0,
          easing: Easing.inOut(Easing.ease),
        }).start(),
        spring(this.scale, {
          toValue: 0,
          damping: 12,
          mass: 0.6,
          stiffness: 150.6,
          overshootClamping: false,
          restSpeedThreshold: 0.001,
          restDisplacementThreshold: 0.001,
        }).start(),
      ]);
    }
  }

在运行动画之前,必须将动画值添加为零,如:-

componentDidUpdate() {
    // stopClock(clock);
   //Setting animations values as zero
    this.val.setValue(0);
    this.scale.setValue(0);
    if (this.state.visible) {
      block([
        timing(this.val, {
          toValue: 1,
          duration: 100,
          easing: Easing.inOut(Easing.ease),
        }).start(),
        spring(this.scale, {
          toValue: 1,
          damping: 12,
          mass: 0.6,
          stiffness: 150.6,
          overshootClamping: false,
          restSpeedThreshold: 0.1001,
          restDisplacementThreshold: 0.001,
        }).start(),
      ]);
    } else {
      block([
        timing(this.val, {
          toValue: 0,
          duration: 0,
          easing: Easing.inOut(Easing.ease),
        }).start(),
        spring(this.scale, {
          toValue: 0,
          damping: 12,
          mass: 0.6,
          stiffness: 150.6,
          overshootClamping: false,
          restSpeedThreshold: 0.001,
          restDisplacementThreshold: 0.001,
        }).start(),
      ]);
    }
  }