0

我目前正在制作自定义底部选项卡导航器,因为我遇到了反应原生安全上下文的问题,其中手机上的黑条位于底部选项卡上的文本之上。

在此处输入图像描述

我想把它放在底部。

我也有基本的底部标签导航,但在某些手机底部有以下黑条的设备上存在一个问题。我试图申请react-native-safe-area-context,但它似乎没有工作或帮助。

在此处输入图像描述

我能做的最简单的事情是什么来解决这个问题?

这是我的基本底部标签导航:

const Tab = createBottomTabNavigator()

const HomeTab = () => {
  return (
    <Tab.Navigator
      screenOptions={({ route, navigation }) => ({
        tabBarIcon: ({ focused, color, size }) => {
          let iconName

          if (route.name === 'Koti') {
            iconName = focused ? 'ios-home' : 'ios-home-outline'
          } else if (route.name === 'Palvelut') {
            iconName = focused ? 'ios-pin' : 'ios-pin-outline'
          } else if (route.name === 'Ukk') {
            iconName = focused ? 'ios-help-circle' : 'ios-help-circle-outline'
          } else if (route.name === 'Omat tiedot') {
            iconName = focused
              ? 'ios-person-circle'
              : 'ios-person-circle-outline'
          }
          // You can return any component that you like here!
          return <Ionicons name={iconName} size={size} color={color} />
        },
        tabBarActiveTintColor: colors.red,
        tabBarInactiveTintColor: colors.black,
        tabBarStyle: [
          {
            display: 'flex',
          },
          null,
        ],
        headerShown: true,
        headerTransparent: true,
        headerTitleAlign: 'center',
        headerTitleStyle: { color: colors.white, fontSize: 20 },
        headerRight: () => (
          <>
            <Pressable
              onPress={() => navigation.dispatch(DrawerActions.openDrawer())}
            >
              <Ionicons
                testID='DrawerMenu'
                name='ios-menu-outline'
                size={40}
                color={colors.white}
              />
            </Pressable>
          </>
        ),
      })}
    >
      <Tab.Screen
        name='Koti'
        component={HomeStack}
        options={{ headerTitle: 'Vahingonsattuessa', headerShown: false }}
      />
      <Tab.Screen name='Palvelut' component={ServicesScreen} />
      <Tab.Screen
        name='Ukk'
        component={UkkScreen}
        options={{ headerTitle: 'Usein kysytyt kysymykset' }}
      />
      <Tab.Screen name='Omat tiedot' component={ProfileScreen} />
    </Tab.Navigator>
  )
}

这是我的自定义标签导航:

import * as React from 'react'
import { Text, Pressable, View, StyleSheet } from 'react-native'
import {
  useNavigationBuilder,
  TabRouter,
  TabActions,
  createNavigatorFactory,
} from '@react-navigation/native'

const TabNavigator = ({
  initialRouteName,
  children,
  screenOptions,
  tabBarStyle,
  contentStyle,
}) => {
  const { state, navigation, descriptors, NavigationContent } =
    useNavigationBuilder(TabRouter, {
      children,
      screenOptions,
      initialRouteName,
    })

  return (
    <NavigationContent>
      <View style={[{ flexDirection: 'row' }, tabBarStyle]}>
        {state.routes.map((route) => (
          <Pressable
            key={route.key}
            onPress={() => {
              const event = navigation.emit({
                type: 'tabPress',
                target: route.key,
                canPreventDefault: true,
              })

              if (!event.defaultPrevented) {
                navigation.dispatch({
                  ...TabActions.jumpTo(route.name),
                  target: state.key,
                })
              }
            }}
            style={{ flex: 1 }}
          >
            <Text>{descriptors[route.key].options.title || route.name}</Text>
          </Pressable>
        ))}
      </View>
      <View style={[{ flex: 1 }, contentStyle]}>
        {state.routes.map((route, i) => {
          return (
            <View
              key={route.key}
              style={[
                StyleSheet.absoluteFill,
                { display: i === state.index ? 'flex' : 'none' },
              ]}
            >
              {descriptors[route.key].render()}
            </View>
          )
        })}
      </View>
    </NavigationContent>
  )
}

export const CustomBottomTabNavigator = createNavigatorFactory(TabNavigator)
4

0 回答 0