React Native:动画在android上无法正常工作

Yas*_*sir 1 react-native react-animated

我一直试图修复过去2天的问题,它在iOS上运行正常

constructor(){
  super();

  this.animation = new Animated.Value(0)

  this.state = {
    expanded: false,
  };
}
toggle(){
  let initialValue = this.state.expanded? 1 : 0 ,
     finalValue = this.state.expanded? 0 : 1

  this.setState({
     expanded: !this.state.expanded,
  });

  this.animation.setValue(initialValue)
  Animated.timing(
    this.animation,
    {
      toValue: finalValue,
    }
  ).start();
}

render(){
  return(
    <Animated.View style={{{flex: 1, marginTop: 28, paddingLeft: 25, transform: [{ scale: this.animation }, {perspective: 1000 }]}}}>
     ....
    </Animated.View>

  );
}
Run Code Online (Sandbox Code Playgroud)

这个组件是子组件,在父组件中使用如下:<FeedBack ref={ref => this.feedback = ref}/>没有任何条件要检查显示与否(因为构造函数中的动画比例设置为零,所以不需要)

toggle()当按下按钮时,从父进程调用该方法.

现在this works fine on iOS,当组件加载时,在按下按钮(然后缩放)之前视图不存在.但是android当组件加载时,视图已经存在.当我按下按钮时,动画视图会消失并重新出现(使用动画缩放),随后的切换工作正常.android中的问题是,即使initialValue比例为零,视图在第一次加载时仍然存在.

Rya*_*ull 23

这已经成为一个问题,react-native在Android方面已经有一段时间了(感叹).似乎将值设置为0剥离它的特征,基本上将其视为null然后在动画到之后恢复使用其实际值> 0

解决方法是设置动画 this.animation = new Animated.Value(0.01);

您可以在此处关注此问题