我正在使用react-native-navigation,并尝试创建一个不像TabNavigator那样卸载先前打开的屏幕的DrawerNavigator。因为我的屏幕之一包含一个Webview,并且我不希望每次更换屏幕时都重新加载它。
这是App.js中的一些示例代码。
const Drawer = DrawerNavigator(
{
Home: { screen: Home },
PageWithWebview: { screen: PageWithWebview},
Settings: { screen: Settings },
},
{
initialRouteName: "Home",
contentComponent: props => <SideBar user={global.user} />
}
);
const AppNavigator = StackNavigator(
{
Drawer: { screen: Drawer },
},
{
initialRouteName: "Drawer",
headerMode: "none"
}
);
export default () =>
<Root>
<AppNavigator/>
</Root>;
并且在补充工具栏组件中,我有一些按钮可以根据所选内容导航到其他路线。
onPress={() => this.props.navigation.navigate(selected, { userDetails: global.user })}
在更高版本的react native导航中,他们为DrawerNavigator添加了[[unmountInactiveScreens属性
unmountInactiveScreens
离开屏幕时是否应卸下屏幕。卸载屏幕将重置屏幕中的任何本地状态以及屏幕中嵌套导航器的状态。默认为false。