【问题标题】:React-Native Tab Navigation Bar cut offReact-Native 选项卡导航栏被切断
【发布时间】:2020-11-05 01:50:47
【问题描述】:

我目前正在使用 material-bottom-tabs 在我的移动应用中实现导航。

由于某些奇怪的原因,它没有正确显示,而是在我的屏幕底部被截断。

无论我是否激活手势控制(因此 Android 内置导航栏消失),都会发生这种情况。

如果我在我的 Tabs.Navigator 的样式中添加填充,那么 Tab-Navigation-Bar 仍然被切断,现在被白色填充。

我尝试将 Tab.Navigator 包装在 SafeAreaView 中(来自 react-native-safe-area-context),但如果我这样做,我只会得到一个纯白屏幕。

这是我的代码:

import React, { Component } from 'react';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import DrawerHome from './DrawerHome';
import Bookmarks from './Bookmarks';

const Tab = createMaterialBottomTabNavigator();
const Stack = createStackNavigator();
//const insets = useSafeArea();

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      userToken: 1, // set to 'null' in production state
    };
  }
  render() {
    return this.userToken === null ? (
      <Stack.Screen name="LogIn" component={LoginScreen} />
    ) : (
      <SafeAreaProvider>
        <NavigationContainer>
          <SafeAreaView>
            <Tab.Navigator style={{ paddingBottom: '10%' }}>
              <Tab.Screen
                name="Current Schedule"
                component={CarouselPage}
                options={{
                  tabBarLabel: 'Current\nSchedule',
                  tabBarIcon: <Ionicons name="ios-calendar" size={20} />,
                }}
              />
              <Tab.Screen name="Resources" component={ResourceScreen} />
              <Tab.Screen
                name="Schedule Selection"
                component={ScheduleSelectionScreen}
              />
              <Tab.Screen name="About" component={AboutScreen} />
            </Tab.Navigator>
          </SafeAreaView>
        </NavigationContainer>
      </SafeAreaProvider>
    );
  }
}

export default App;

A screenshot of the display issue

【问题讨论】:

    标签: android ios react-native react-navigation react-native-safe-area-view


    【解决方案1】:

    试试这个:

    // ...
    <NavigationContainer>
      <Tab.Navigator>
        <Tab.Screen
          name="Current Schedule"
          component={CarouselPage}
          options={{
            tabBarLabel: 'Schedule',
            tabBarIcon: ({}) => (
                <Ionicons name="ios-calendar" size={20} />
            ),
          }}
        />
        // ...
      </Tab.Navigator>
    </NavigationContainer>
    // ...
    

    栏没有被切断。文本被截断的原因是,因为您在 tabBarLabel 文本中添加了换行符。我建议为您的标签标签选择较短的单词。

    文档似乎没有提供增加标签填充以允许更长文本的选项。

    【讨论】:

    • 感谢您的回复 :) 不过,我还有另一个问题:我正在使用 expo 和 Ionicons,但如果我像在代码中那样设置“tabBarIcon”,它不会显示.你知道为什么吗?
    • 好的,我自己发现了错误:您必须使用箭头函数将图标传递给标签栏,如下所示:}}>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-17
    • 1970-01-01
    相关资源
    最近更新 更多