react-native - React Native - 在 Material 顶部选项卡导航器中嵌套堆栈导航器时标题中的额外空间

标签 react-native react-navigation

在此应用程序中,我使用 react-navigation 提供的具有以下层次结构的导航器。

BottomTabNavigator
    |
    + StackNavigator
    |
    + MaterialTopTabNavigator (PageTopTabNav)
    |     |
    |     + StackNavigator (StackNavA)
    |     |
    |     + StackNavigator
    |     |
    |     + StackNavigator
    |
    + StackNavigator

在下面的屏幕截图中,红色框出的区域不可配置,摆脱它的唯一方法是在我的 StackNavigator 中设置 header: null

const StackNavA = createStackNavigator({
  LandingA: { screen: ScreenLandingA },
  Details: { screen: ScreenDetails }
}, {
  defaultNavigationOptions: {
    header: null
  }
});

但是,我想显示导航栏,以便将后退按钮保留在适当的位置,以允许用户返回到上一页。

StackNavA 导出如下。

export default class ScreenA extends React.Component {
  static router = StackNavA.router;

  render() {
    return (
      <StackNavA navigation={this.props.navigation} />
    );
  }
}

它正在被另一个文件中的 MaterialTopTabNavigator 使用。

const PageTopTabNav = createMaterialTopTabNavigator({
  A: { screen: ScreenA },
  B: { screen: ScreenB },
  C: { screen: ScreenC }
}, {
  initialRouteName: "A",
  tabBarOptions: {
    activeTintColor: "white",
    inactiveTintColor: "#CCCCCC",
    labelStyle: {
      fontSize: 16,
      fontWeight: "bold"
    },
    indicatorStyle: {
      height: 0
    },
    style: {
      backgroundColor: "teal",
      borderBottomWidth: 0.5,
      borderBottomColor: "gray"
    }
  },
  backBehavior: "none"
});

PageTopTabNavSafeAreaView 组件包装导出,以防止与 iOS 设备中的状态栏重叠。

export default class BrowseScreen extends React.Component {
  static router = PageTopTabNav.router;

  render() {
    return (
      <SafeAreaView style={{ flex: 1, backgroundColor: "teal" }}>
        <PageTopTabNav navigation={this.props.navigation} />
      </SafeAreaView>
    );
  }
}

是否可以去掉红色框的区域,同时保留 StackNavA 中的导航栏?

area-in-question

最佳答案

使用 headerMode: none 配置参数将其消失。

export default StackNavigator({
    LoginScreen: { screen: Login.component }
}, {
    initialRouteName: 'LoginScreen',
    headerMode: 'none' <------------- This
})

关于react-native - React Native - 在 Material 顶部选项卡导航器中嵌套堆栈导航器时标题中的额外空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56871551/

相关文章:

react-native-calendars 跳转到选定月份

javascript - 运行 react-native run-android 时任务 ':app:transformClassesWithDexForDebug' 执行失败

react-native - 使用 React Native Navigation 导航到下一个组件时完成当前组件?

android - 如何在 React Navigation 中添加抽屉内部堆栈导航

react-native - react native :Module RCTEventEmitter is not a registered callable module (calling receiveTouches)

android - React native android 转换真的很慢

react-native - 如何获得当前关注的输入的位置?

javascript - 在 FireStore 中过滤集合组查询

reactjs - React Native - 如何在每个屏幕中保留 TabNavigator

reactjs - 为什么 ComponentDidMount 中的异步工作会导致导航时出现视觉滞后,除非等待简单的超时?