我正在使用 refs 为 View 设置动画,但是 refs 抛出了一个未定义的错误。但是,如果我注释掉我访问 ref、加载页面、取消注释代码并重新加载页面的尝试,则动画效果很好。
我的代码:
export const AccountScreen = ({ navigation }) => {
return (
<SafeAreaView style={{ backgroundColor:'#FFFFFF', flex: 1 }}>
<Animatable.View style={styles.container} ref={ref => {this.containerRef = ref}}>
</Animatable.View>
</SafeAreaView>
)
};
launchOpenAnimation()
function launchOpenAnimation () {
this.containerRef.animate(appearContainerAnimation); //If I comment this out, reload, and un-comment, it works
}
我能做些什么来解决这个问题?似乎在launchOpenAnimation()
执行 my 时没有定义 ref ,而是在之后定义了它,因此如果我将其注释掉、重新加载、取消注释并再次重新加载,代码就会工作。