How to get drawer over the header in react navigation?

后端 未结 2 1664
孤街浪徒
孤街浪徒 2021-02-20 01:15

I am using react navigation. I want to show drawer over the header of the screen. Currently my header is not hiding below drawer when I open the drawer.

2条回答
  •  天涯浪人
    2021-02-20 01:57

    1. You should create a new StackNavigator for your CategoryScreen and ProductScreen
    2. You set the header on CategoryScreen and ProductScreen navigation options

    Here is what i meant

    // wrap your screen inside the drawer into StackNavigator
    const CategoryNavigator = createStackNavigator({
      CategoryList: {
        screen: CategoryScreen,
        navigationOptions: {
          title: "Category",
          header: // any custom header here
        }
      },
    });
    
    const drawerScreens = createDrawerNavigator({
      Category: CategoryNavigator,
      Products: ProductNavigator,
    }, {
      initialRouteName: 'Category'
    })
    
    
    export default AppStack = createStackNavigator({
      drawer: {
        screen: drawerScreens,
      },
      cart: {
        screen: CartScreen
      }
    }, {
      initialRouteName: 'drawer',
    });

    This is the result

    Following will make a floating header which similar with your screenshot

    Set the header mode to float (you don't need to wrap CategoryScreen and ProductScreen into StackNavigator)

    export default AppStack = createStackNavigator({
      drawer: {
        screen: drawerScreens,
      },
      cart: {
        screen: CartScreen
      }
    }, {
      headerMode: 'float', // set this header mode to float so you can share the header
      initialRouteName: 'drawer',
    });

    This is the result if you change the header mode to float

提交回复
热议问题