Calling function after Animate.spring has finished

China☆狼群 提交于 2019-12-12 15:09:23

问题


i am using an animation in order for a pop-up to come in from the right side. I'm using the following code for this -

  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});

The code works perfectly, and it looks great, however, I am now wanting to call a function only when the animation has completely finished, and strictly only once. Just wondering how i can do this? Not sure if this is a really simple question.


回答1:


start takes a callback function, the function is executed once after the animation finishes:

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


来源:https://stackoverflow.com/questions/43704237/calling-function-after-animate-spring-has-finished

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!