You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Navigation 6.x中使用screenOptions配置抽屉样式失效的问题求助

Fixing Drawer Navigation Styles in React Navigation 6.x

Hey there! I totally get the confusion with the changes in React Navigation 6.x—let's get your drawer styles working properly.

The key issue here is that drawer-specific style options aren't placed directly at the top level of screenOptions anymore. Instead, you need to nest them under the drawer property within screenOptions. Let's adjust your code accordingly:

<NavigationContainer>
  <Drawer.Navigator
    initialRouteName="Home"
    screenOptions={{
      drawer: {
        activeTintColor: "blue",
        itemStyle: { marginTop: 20 },
        labelStyle: { fontSize: 30 },
      },
      drawerStyle: { backgroundColor: "purple" }
    }}
  >
    <Drawer.Screen name="Home" component={Home} />
    <Drawer.Screen name="Users" component={Users} />
  </Drawer.Navigator>
</NavigationContainer>

Let me break down the changes:

  • activeTintColor, itemStyle, labelStyle: These control individual item styles, so they belong inside the drawer object under screenOptions.
  • drawerStyle: This controls the overall container style of the drawer (like background color), and it sits directly under screenOptions (not inside the drawer sub-object).

If you want to customize things even further (like adding custom content or more advanced styling), you could also use the drawerContent prop on Drawer.Navigator, but for your current needs, the above adjustment should get all your styles working as expected.

内容的提问来源于stack exchange,提问作者user16625649

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 02:52:40