【发布时间】:2023-04-09 02:10:01
【问题描述】:
在 Android 5.1 的物理设备上运行 RN v0.40.0。我正在尝试为文本设置动画以淡入显示并以下列方式向上滑动:
export default class Example extends PureComponent {
constructor(props) {
super(props);
this.translate = new Animated.Value(-15);
this.fade = new Animated.Value(0);
}
componentWillReceiveProps() {
setTimeout(() => {
Animated.timing(this.translate, {
toValue: 0,
duration: 800,
easing: Easing.inOut(Easing.ease),
}).start();
Animated.timing(this.fade, {
toValue: 1,
duration: 800,
easing: Easing.inOut(Easing.ease),
}
).start();
}, 150);
}
render() {
return (
<View>
<Animated.View
style={{
transform: [
{translateY: this.translate},
],
opacity: this.fade
}}
>
<Text>
{this.props.text}
</Text>
</Animated.View>
</View>
);
}
在我从开发菜单重新加载 JS 包并转到该视图后,应用程序崩溃且没有错误日志,有时显示 Application ... stopped working,有时不显示。如果我再次从 android 菜单启动应用程序,它会正常加载,仅第一次崩溃。这肯定与动画有关,因为在我介绍动画之前我没有崩溃。没有日志,没有线索,请给我一些建议,这可能是什么,我应该尝试什么以及我应该检查什么。谢谢。
顺便说一句,在那个带有动画的视图上,我有一个非常重的背景图像(~400k),这可能是个问题吗?
UPD:我已将其范围缩小到当我尝试使用setTimeout 或Animation.parallel 并行运行动画时它会崩溃。可能是什么问题?
【问题讨论】:
-
您找到解决方案了吗?现在面临同样的问题。使用并行动画在 android 上崩溃。
-
@ErikHaiderForsén 面临同样的问题。最近好像又出现了。您找到问题的根源了吗?
标签: android animation react-native crash