我目前正在自学使用 React Native 制作应用程序。我正在使用 React Navigation 在按下按钮时在屏幕之间导航。我可以很好地浏览屏幕。但是,在一个导航中,我还想重置stackNavigator. 我已经查看了重置stackNavigatorusingNavigationActions.reset()方法的解决方案,但我无法让它为 Button 工作。只是为了重新讨论,我一直在尝试使用按钮导航到新屏幕并重置stackNavigator. 这是我的代码:
import React from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';
import { NavigationActions, StackActions, createStackNavigator } from 'react-navigation'; // Version can be specified in package.json
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
<Button
title="Join Group"
onPress={() => this.props.navigation.push('JoinGroup')}
/>
<Button
title="Create Group"
onPress={() => this.props.navigation.push('CreateGroup')} …Run Code Online (Sandbox Code Playgroud)