在DrawerNavigator中隐藏标题(react-navigation)

问题描述 投票:2回答:6

惠...

我目前正在玩反应导航并试图解决当抽屉打开时标题没有隐藏的问题...

enter image description here

我希望任何人都可以分享如何解决这个错误的标题..我在StackNavigator中附加了DrawerNavigator的代码集成。

const Home = DrawerNavigator({
  HomeMenu: { screen: HomeMenu },
  Messages: { screen: Messages },
  Notifications: { screen: Notifications },
  Badges: { screen: Badges },
  Leaderboard: { screen: Leaderboard },
  Profile: { screen: Profile },
  Logout: { screen: Logout }
});

const MainActivity = StackNavigator({
  Home: { screen: Home }
})

先感谢您!

javascript react-native react-navigation
6个回答
3
投票

您可以隐藏标题,如: -

const Home = DrawerNavigator({
  HomeMenu: { screen: HomeMenu,
    navigationOptions: {
          header:false, //hide header if not needed so whole screen slide  

    },
},
  Messages: { screen: Messages },
  Notifications: { screen: Notifications },
  Badges: { screen: Badges },
  Leaderboard: { screen: Leaderboard },
  Profile: { screen: Profile },
  Logout: { screen: Logout }
});

const MainActivity = StackNavigator({
  Home: { screen: Home }
})

2
投票

我有同样的问题(TabNav嵌套在DrawerNav中)并找到了一个我想分享的超级简单修复!这个问题在here的回购中讨论了react-navigation。我实现的修复(在你想要隐藏的屏幕上):

MAIN: {
  screen: MainTabs,
  navigationOptions: {
    drawerLabel: () => null // to hide this header
},

},

略有不同的版本:

static navigationOptions = {
drawerLabel: () => null

}

希望这可以帮助!


1
投票

在DrawerNavigator中使用StackNavigator并将headerMode: 'none'设置为root StackNavigator

const MenuStackNavigator = StackNavigator({
  Dashboard: { 
    screen: Dashboard, 
    navigationOptions: {
      title: 'Dashboard',
    }
  },
});
const PagesStackNavigator = StackNavigator({...});

const DrawerNavigator = DrawerNavigator({
  MenuStack: { 
    screen: MenuStackNavigator,
    navigationOptions: {
      drawer: () => ({
        label: 'MenuStackNavigator',
      })
    },
  },
  Pages: { 
    screen: PagesStackNavigator,
    navigationOptions: {
      drawer: () => ({
        label: 'PagesStackNavigator',
      })
    },
  }
});

const AppNavigator = StackNavigator({
  Drawer: { screen: DrawerNavigator },
}, {
  headerMode: 'none',
});

0
投票

我找到了方法,我只需要反过来做..将DrawerNavigator作为根导航器并将StackNavigator放入其中..然后打开抽屉时将没有标题


0
投票

我也在玩这个问题,发现StackNavigator必须嵌套在Drawer中,但是这个解决方案有很多问题,比如同步抽屉和卡片堆栈中的活动菜单状态。

// Manifest of possible screens

const MenuButton = ({ navigation }) => (
    <View>
        <TouchableOpacity onPress={() => navigation.navigate('DrawerOpen')}>
            <Icon name="bars" style={{color: 'white', padding: 10, marginLeft:10, fontSize: 20}}/>
        </TouchableOpacity>
    </View>
);

const Nav = StackNavigator({
  StoriesScreen: {
    screen: StoriesScreen,
    navigationOptions: { title: 'Stories' }
  },
  LaunchScreen: { screen: LaunchScreen },
  LoginScreen: {
    screen: LoginScreen,
    navigationOptions: { title: 'Login' }
  }
}, {
  navigationOptions: {
    header: navigation => ({
      style: styles.header,
      left: <MenuButton navigation={navigation} />,
    }),
  }
})

const PrimaryNav = DrawerNavigator({
  StoriesScreen: {
    screen: Nav,
    navigationOptions: { title: 'Stories' }
  },
  LaunchScreen: { screen: LaunchScreen },
  LoginScreen: {
    screen: LoginScreen,
    navigationOptions: { title: 'Login' }
  }
})

0
投票

我也有同样的问题,并通过在主StackNavigator中添加“headerMode”:none来解决。

例:

const AppMainStack = DrawerNavigator({
  ActivitiesScreen: {screen: ActivitiesScreen},
}, {
  drawerPosition: 'right',
});

const AppNavigator = StackNavigator({
  StartScreen: {screen: StartScreen},
  EnterCodeScreen: {screen: EnterCodeScreen},
  CreateAccountScreen: {screen: CreateAccountScreen},
  ProfileSetupScreen: {screen: ProfileSetupScreen},
  SignInScreen: {screen: AppMainStack},
}, {
  headerMode: 'none',
});
© www.soinside.com 2019 - 2024. All rights reserved.