从堆栈导航器中删除屏幕 [英] Remove screen from stack navigator

查看:34
本文介绍了从堆栈导航器中删除屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I’ve observed Back button logic works seeing the sequence of screens in the stack. I’ve a Drawer navigator placed inside stack navigator.

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

On top of the stack I’ve Splash screen. On Dashboard when I press back button it takes me to splash screen.

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

How can I remove splash screen from stack after entering in the app, So when I press back button Dashboard it will EXIT the app instead of taking to SPLASH SCREEN.

/* @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>;

推荐答案

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

One solution would be to reset the stack inside the splash screen component and redirect the user to the screen that you prefer:

import { NavigationActions } from 'react-navigation'

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

对于较新版本的 react-navigation :

For newer versions of react-navigation :

import { StackActions, NavigationActions } from 'react-navigation';

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

官方文档链接

这篇关于从堆栈导航器中删除屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆