React native 简单地不运行本地动画

React native 简单地不运行本地动画,react-native,react-native-android,React Native,React Native Android,我与React Native的问题似乎涉及整个项目。任何使用动画API的东西都不会运行。我正在运行React Native 0.49.2, 似乎什么都不起作用,我已经尝试了好几个人的代码,但什么都没有发生。对我来说,问题似乎是每当我调用“Animated.timening().start();”时,它实际上从未启动。下面是一些简短的示例代码: class Splash extends React.Component { constructor(props){ super(props

我与React Native的问题似乎涉及整个项目。任何使用动画API的东西都不会运行。我正在运行React Native 0.49.2, 似乎什么都不起作用,我已经尝试了好几个人的代码,但什么都没有发生。对我来说,问题似乎是每当我调用“Animated.timening().start();”时,它实际上从未启动。下面是一些简短的示例代码:

class Splash extends React.Component {

  constructor(props){
    super(props);

    this.state = {
      ShowSetup: true,
      fadeAnim: new Animated.Value(0),  // Initial value for opacity: 0
    };

  }

  componentDidMount(){
    this.Animator()
  }

  Animator(){
    console.log("ANIMATOR RUNNING!")
    Animated.timing(                  // Animate over time
     this.state.fadeAnim,            // The animated value to drive
     {
       toValue: 1,                   // Animate to opacity: 1 (opaque)
       duration: 10000,              // Make it take a while
     }
   ).start();                        // Starts the animation


  }


  render() {
    let { fadeAnim } = this.state;
    return (
      <View style={{flex: 1, backgroundColor: 'blue'}}>

      <Animated.View                 // Special animatable View
       style={{
         opacity: fadeAnim,         // Bind opacity to animated value
       }}
     >
       <Text>Fade In</Text>
     </Animated.View>
      </View>
    );
  }
}
类Splash扩展了React.Component{
建造师(道具){
超级(道具);
此.state={
ShowSetup:true,
fadeAnim:new Animated.Value(0),//不透明度的初始值:0
};
}
componentDidMount(){
这个是
}
动画师(){
log(“动画师正在运行!”)
动画。计时(//随时间设置动画
this.state.fadeAnim,//要驱动的动画值
{
toValue:1,//动画设置为不透明度:1(不透明)
持续时间:10000,//让它花点时间
}
).start();//启动动画
}
render(){
设{fadeAnim}=this.state;
返回(
淡入
);
}
}
无论您等待多长时间,该值都不会显示。已经成为我的一大难题,因为我不知道还能做什么

试试这个:

  <View style={{flex: 1, backgroundColor: 'blue'}}>

    <Animated.View                    // Special animatable View
     style={{
       opacity: this.state.fadeAnim,  // Bind opacity to animated value
     }}
    >
      <Text>Fade In</Text>
    </Animated.View>
  </View>
试试这个:

  <View style={{flex: 1, backgroundColor: 'blue'}}>

    <Animated.View                    // Special animatable View
     style={{
       opacity: this.state.fadeAnim,  // Bind opacity to animated value
     }}
    >
      <Text>Fade In</Text>
    </Animated.View>
  </View>

不要忘了在组件安装中使用分号,这非常重要!!另外,我认为您需要在构造函数中绑定Animator,或者在函数声明中绑定Animator,这样您就有了选择。这似乎不是问题所在。。我似乎无法理解这一点我想知道这是否与反应导航有关你曾经理解过这一点吗?我也没有看到任何动画开始,我想知道这是否是因为我也在使用react导航。不要忘了ComponentDidMount中的分号,非常重要!!另外,我认为您需要在构造函数中绑定Animator,或者在函数声明中绑定Animator,这样您就有了选择。这似乎不是问题所在。。我似乎无法理解这一点我想知道这是否与反应导航有关你曾经理解过这一点吗?我也没有看到任何动画开始,不知道是不是因为我也在使用react-navigation。不走运,我也在使用react-navigation。。因此,我开始怀疑这是否是原因之一。当我尝试运行此程序时,会出现一个“停止跟踪未定义”错误…请确保根据需要调整代码。您的代码应该如下所示:const timing=Animated.timing;parallel([计时(this.state.fadeAnim,{toValue:1,duration:700,delay:700,})]).start();不走运,我也在使用React导航。。因此,我开始怀疑这是否是原因之一。当我尝试运行此程序时,会出现一个“停止跟踪未定义”错误…请确保根据需要调整代码。您的代码应该如下所示:const timing=Animated.timing;parallel([计时(this.state.fadeAnim,{toValue:1,duration:700,delay:700,})]).start();