gpt4 book ai didi

reactjs - Animate.spring 完成后调用函数

转载 作者:行者123 更新时间:2023-12-03 14:04:21 25 4
gpt4 key购买 nike

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

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

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

最佳答案

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

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

关于reactjs - Animate.spring 完成后调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43704237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com