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

React native 如何在react native中的动画结束时调用函数,react-native,React Native,我想在react原生项目的动画结束时调用函数(或设置状态)。 我怎么做? 请帮帮我 我的代码: import React,{component} from 'react'; import {Animated, View} from 'react-native'; class Animation extends Component { constaructor(){ super() this.AnimationValue= new Animated.Value(0),

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

我的代码:

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>
    );
  }
}
import React,{component}来自'React';
从“react native”导入{Animated,View};
类动画扩展组件{
恒量{
超级()
this.AnimationValue=新的Animated.Value(0),
}
componentDidMount(){
时间(
这个.AnimationValue,
{
toValue:1,
持续时间:4000,
}
).start();
}
render(){
const marginLeft=this.AnimationValue.interpolate({
输入范围:[0,1],
输出范围:['0','300']
});
返回(
//…我的代码
);
}
}

这是
start()中的回调

.start(callback)
在动画开始时启动

改用箭头函数,例如
.start(()=>…)

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