0

我有一个抽屉嵌套在堆栈内。无法使用它实现后退按钮。谁能提供一个干净的解决方案来解决这个问题=(

我想在 iOS 和 android 上显示返回按钮,使用硬件返回按钮导航到最后一个屏幕。

抽屉导航器

/* @flow */

import React from "react";
import { DrawerNavigator } from "react-navigation";

import Home from "./components/home/";
import SplashPage from "./components/splashscreen/";
import SideBar from "./components/sidebar";
import Contact from "./components/Contact/";



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



export default Drawer;

堆栈导航器

/* @flow */

import React from "react";

import { Platform } from "react-native";
import { Root } from "native-base";
import { StackNavigator} from "react-navigation";
import Drawer from "./Drawer";
import Contact from "./components/Contact"
import Register from "./components/Register"
import Home from "./components/home/";

const AppNavigator = StackNavigator(
    {
        Drawer: {screen: Drawer},
       Home: { screen: Home },
        Register: {screen: Register},
    },
    {
        initialRouteName: "Home",
           headerMode: Platform.OS == "android" ? "none" : "float",
        header: (navigation) => ({
            left: (
                <Button
                  title="Back"
                  onPress={ () => navigation.goBack() }  
                />
              )
          })
    }
);

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

1 回答 1

0

像这样null调用goBack函数时用作参数:

navigation.goBack(null)
于 2018-06-30T12:44:06.617 回答