用Android反应本机动画崩溃

时间:2020-04-01 04:12:28

标签: react-native react-native-android

对此问题感到非常沮丧。

我正在设计一款需要动画的游戏。一切都可以在Expo中的Web部件上正常使用。组件如下:

return (  <TouchableWithoutFeedback onPress={selectTarget}>
      <Animated.View
        style={{
          width: 50,
          height: 50,
          backgroundColor: 'yellow',
          zIndex: 2,
          position: 'absolute',
          alignItems: 'center',
          justifyContent: 'center',
          **transform: [
            { translateX: moveAnimation.x },
            { translateY: moveAnimation.y },
          ],**
          elevation: 2,
          left: 0, 
          top: 0,
        }}>
        <Image style={[imageStyle]} source={imagesAssets[color]} />
      </Animated.View>
    </TouchableWithoutFeedback> );

但是它在Android(与iOS兼容)上崩溃了,错误如下: 更新由RCTView管理的视图的“转换”时出错

如果我注释掉转换位,它运行良好。

由于性能问题,我在动画配置中添加了useDeviceDriver:true,因此必须使用transform。

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

最终找到了问题的原因:

moveAnimation计算过程中出了点问题,未定义的值会使应用崩溃,而不是将其视为0。