gpt4 book ai didi

react-native - 从堆栈导航器中删除屏幕

转载 作者:行者123 更新时间:2023-12-04 05:36:26 36 4
gpt4 key购买 nike

我观察到后退按钮逻辑可以看到堆栈中的屏幕序列。我在堆栈导航器中放置了一个抽屉导航器。

在堆栈顶部,我有启动画面。在仪表板上,当我按下后退按钮时,我会进入闪屏。

进入应用程序后如何从堆栈中删除启动画面,因此当我按下后退按钮仪表板时,它将退出应用程序而不是进入启动画面。

/* @flow */

import React from "react";
import { Platform, Text } from "react-native";
import { Root } from "native-base";
import { StackNavigator, DrawerNavigator} from "react-navigation";
import Register from "./components/Register";
import Available from "./components/Available";
import Splash from "./components/splash/“;
import SideBar from "./components/sidebar";
import Discover from "./components/Discover/";
import Dashboard from "./components/Dashboard/";
import Contact from "./components/Contact"



const Drawer = DrawerNavigator(
{
Dashboard: { screen: Dashboard },
Discover: { screen: Discover },
Contact: { screen: Contact},
},
{
navigationOptions: {
gesturesEnabled: false,
},
initialRouteName: "Dashboard",
contentOptions: {
activeTintColor: "#e91e63"
},
drawerPosition: 'right',
contentComponent: props => <SideBar {...props} />
}
);


const AppNavigator = StackNavigator(
{
Splash: { screen: Splash },
Drawer: { screen: Drawer },
Available: { screen: Available },
Register: { screen: Register },
},
{
// initialRouteName: “Splash”,
headerMode: "none",
}
);

export default () =>
<Root>
<AppNavigator />
</Root>;

最佳答案

一种解决方案是重置初始屏幕组件内的堆栈并将用户重定向到您喜欢的屏幕:

import { NavigationActions } from 'react-navigation'

const resetAction = NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'Drawer'})
]
})
this.props.navigation.dispatch(resetAction)

对于较新版本的 react-navigation :
import { StackActions, NavigationActions } from 'react-navigation';

const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Profile' })],
});
this.props.navigation.dispatch(resetAction);

Link to the official documentation

关于react-native - 从堆栈导航器中删除屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48021546/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com