gpt4 book ai didi

react-native - 如何在 React Native 的动画结束时调用函数

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

我想在我的 native 项目中的动画结束时调用函数(或设置状态)。
我该怎么做?
请帮我。

我的代码:

import React,{component} from 'react';
import {Animated, View} from 'react-native';
class Animation extends Component {
constaructor(){
super()
this.AnimationValue= new Animated.Value(0),
}
componentDidMount() {
Animated.timing(
this.AnimationValue,
{

toValue: 1,
duration: 4000,
}
).start();
}

render() {
const marginLeft = this.AnimationValue.interpolate({
inputRange: [0, 1],
outputRange: ['0', '300']
});
return (
<Animated.View style={{marginLeft}} >
// ... my code
</Animated.View>
);
}
}

最佳答案

这是 start() 中的回调.

Animated.timing(
this.AnimationValue,
{
toValue: 1,
duration: 4000,
}
).start(hereGoesTheFunctionReference);

关于react-native - 如何在 React Native 的动画结束时调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48099015/

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