Animate.spring完成后调用函数

Rya*_*ull 3 reactjs react-native react-native-ios

我正在使用动画,以便弹出窗口从右侧进入.我正在使用以下代码 -

  var toValue = 200;

  if(this.state.fileMenu){
    toValue = 0;
  }

  Animated.spring(
    this.state.bounceValue,
    {
      toValue: toValue,
      velocity: 3,
      tension: 2,
      friction: 5,
    }
  ).start();
  //I want to call a function here after the animation is finished.

  this.setState({fileMenu: !this.state.fileMenu});
Run Code Online (Sandbox Code Playgroud)

代码工作得很好,看起来很棒,但是,我现在想要只在动画完成时调用一个函数,并且严格只调用一次.只是想知道我怎么能这样做?不确定这是否是一个非常简单的问题.

nir*_*sky 5

start 采用回调函数,该函数在动画结束后执行一次:

 Animated.spring(
    this.state.bounceValue,
    {
      toValue: toValue,
      velocity: 3,
      tension: 2,
      friction: 5,
    }
  ).start(() => doSmething());
Run Code Online (Sandbox Code Playgroud)