react-navigation - 我们如何在带有bottomTabNavigator的react导航V3中使用滑动

标签 react-navigation

我正在使用 react navigation V3,我想在我的 bottomTabNavigator 中使用滑动。
我不能这样做,因为 createBottomTabNavigator 尚不支持它,并且 createBottomNavigator 实际上已被弃用。
这很烦人,因为在 react navigation V2 中我们可以轻松完成。
只需 createMaterialTopTabNavigator 支持滑动,但我想要底部导航器而不是顶部导航器

最佳答案

如果你看看 documentationcreateMaterialTopTabNavigator您可以在 TabNavigatorConfig 中看到可以使用 tabBarPosition 设置标签栏的位置

Position of the tab bar, can be 'top' or 'bottom', default is top



所以如果你使用 createMaterialTopTabNavigator而不是 createMaterialBottomTabNavigator并设置 tabBarPosition: 'bottom'在你的配置中你应该得到一个 createMaterialTopTabNavigator但在底部。

这是它在代码中的样子
import Screen1 from './Screen1';
import Screen2 from './Screen2';
import { createMaterialTopTabNavigator, createAppContainer } from 'react-navigation';

const screens = {
  Screen1: {
    screen: Screen1
  },
  Screen2: {
    screen: Screen2
  }
}

const config = {
  headerMode: 'none',
  initialRouteName: 'Screen1',
  tabBarPosition: 'bottom' // <- add this line to your config
}

const MainNavigator = createMaterialTopTabNavigator(screens,config);
export default createAppContainer(MainNavigator);

这是一个显示它工作的小吃https://snack.expo.io/@andypandy/materialtopnavigator-at-the-bottom

关于react-navigation - 我们如何在带有bottomTabNavigator的react导航V3中使用滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54903927/

相关文章:

react-native - react 导航 (V2) : How to set the Icon and the label of a stack Navigator inside a Drawer Navigator?

javascript - BottomTabNavigator 隐藏项目可见性

react-native - 使用 react Native DrawerNavigator 注销

react-native - 如何在 React Navigation Stacknavigator 中制作自定义 HeaderTitle?

react-native - 在通过深度链接导航到特定路线导航时 React Native。goBack 不起作用

javascript - React Navigation 检查上一个屏幕是否存在

react-native - 如何在 React Navigation 中使用标题按钮导航到其他页面?

reactjs - 如何在 React Native 中监听子组件中的事件?

reactjs - 如果应用程序关闭,则 React-Native 深层链接不起作用(React-Navigation v5)

reactjs - 使用 react 导航将导航历史记录重置为登录屏幕