javascript - 反应导航幻灯片动画后退按钮错误
问题描述
我收到此错误:
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
in Card (at CardContainer.tsx:206)
in CardContainer (at CardStack.tsx:623)
in RNSScreen (at createAnimatedComponent.js:217)
in AnimatedComponent (at createAnimatedComponent.js:278)
in AnimatedComponentWrapper (at src/index.native.tsx:147)
in Screen (at Screens.tsx:74)
in MaybeScreen (at CardStack.tsx:616)
这是我的导航器:
const DefaultStackNavigation = () => {
return(
<NavigationContainer fallback={<View style={{backgroundColor: "#0C0C0C", height: "100%", width: "100%", flex: 1}} />}>
<Stack.Navigator screenOptions={{headerShown: false, gestureEnabled: true, gestureDirection: "horizontal", cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS, cardStyle: {backgroundColor: "transparent", flex: 1, height: "100%", width: "100%"}}} independent={false}>
<Stack.Screen name="HomeTabs" component={HomeScreen} />
<Stack.Screen name="ChatScreen" component={ChatScreen} />
<Stack.Screen name="Settings" component={SettingsScreen} />
</Stack.Navigator>
</NavigationContainer>
);
};
因为我有gestureEnabled
=true
我可以向右滑动屏幕返回。但是现在有一个问题:
我希望用户选择他/她想要滑动返回还是单击返回按钮。如果我向右滑动屏幕,我不会收到错误消息,我可以使用该应用程序。但是,如果我单击navigation.goBack()
ChatScreen 中的按钮,我会收到错误消息(本文开头)。如果我启用标题并单击 goBack 按钮,我也不会收到此错误。如何防止 React Native 以这种方式运行?
编辑
这是我的后退按钮:
<View style={styles.backArrowContainer}>
<TouchableOpacity style={{height: 60, width: 60, justifyContent: "center", alignItems: "center"}} onPress={() => navigation.goBack()}>
<BackArrow />
</TouchableOpacity>
</View>
解决方案
推荐阅读
- c# - 具有重复 ID 的集合展平为一行
- python - 当不满足 target_accept 时,pymc3 有没有办法引发异常?
- windows - SQLPLUS 无法在 Windows 命令提示符下连接
- mysql - 如何在状态高于x的mysql中显示完整的进程列表?
- python - 如何使用标签在地图上可视化networkx图?
- python - Python 帮助:着色和加粗
- asynchronous - 异步任务调用同步和异步函数
- java - 如何在 Java 中使用图像作为对象?
- sqlite - Sqlite - 从 CSV 导入
- php - PHP number_format():将数字四舍五入,然后格式化为货币