Animate.spring 完成后调用函数 [英] Calling function after Animate.spring has finished

查看:39
本文介绍了Animate.spring 完成后调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用动画是为了让弹出窗口从右侧进入.我为此使用以下代码 -

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.

推荐答案

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

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

这篇关于Animate.spring 完成后调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆