我正在使用 expo-router 设置选项卡布局并遇到问题;选项卡导航在特定文件夹结构中无法按预期工作;我对审核文件夹使用选项卡导航,并使用抽屉进行更全局的导航。这是我观察到的:
有问题的文件夹的一些独特特征:
这是我的审核_布局代码:
import { Tabs } from 'expo-router';
import React from 'react';
import { Platform } from 'react-native';
import { HapticTab } from '@/components/HapticTab';
import { IconSymbol } from '@/components/ui/IconSymbol';
import TabBarBackground from '@/components/ui/TabBarBackground';
import { Colors } from '@/constants/Colors';
import { useColorScheme } from '@/hooks/useColorScheme';
export default function AuditsLayout() {
const colorScheme = useColorScheme();
return (
<Tabs
screenOptions={{
tabBarActiveTintColor: Colors[colorScheme ?? 'light'].tint,
headerShown: false,
tabBarButton: HapticTab,
tabBarBackground: TabBarBackground,
tabBarStyle: Platform.select({
ios: { position: 'absolute', backgroundColor: 'transparent' },
default: { backgroundColor: Colors[colorScheme ?? 'light'].background },
}),
}}>
<Tabs.Screen
name="index"
options={{
title: 'Home',
tabBarIcon: ({ color }) => <IconSymbol size={28} name="house.fill" color={color} />,
}}
/>
<Tabs.Screen
name="new"
options={{
title: 'New',
tabBarIcon: ({ color }) => <IconSymbol size={28} name="square.fill" color={color} />,
}}
/>
<Tabs.Screen
name="[id]"
options={{
title: 'Show',
tabBarShowLabel: true,
href: null,
}}
/>
</Tabs>
);
}
这是我的 Base _layout 代码:
import {
DarkTheme,
DefaultTheme,
ThemeProvider,
} from "@react-navigation/native";
import { useFonts } from "expo-font";
import { Stack, Tabs, useRouter, useSegments } from "expo-router";
import * as SplashScreen from "expo-splash-screen";
import { StatusBar } from "expo-status-bar";
import React, { useEffect, useState } from "react";
import "react-native-reanimated";
import "../global.css";
import { i18n, initializeLocale } from "../services/localization";
import { Provider, useSelector, useDispatch } from "react-redux";
import { AppDispatch, RootState } from "@/store/redux";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { Drawer } from "expo-router/drawer";
import { DrawerToggleButton } from "@react-navigation/drawer";
import { View } from "react-native";
import { PersistGate } from "redux-persist/integration/react";
import { store, persistor } from "@/store/redux";
import ConnectionStatusIndicator from "@/components/My components/ConnectionStatusIndicator";
import { monitorConnection } from "@/store/redux/connectionSlice";
import { SafeAreaView } from "react-native-safe-area-context";
import NavigationDrawer from "@/components/My components/NavigationDrawer";
import { themes } from "@/store/redux/themeSlice";
SplashScreen.preventAutoHideAsync();
function AppContent() {
const { theme, settings } = useSelector((state: RootState) => state.theme);
const dispatch = useDispatch<AppDispatch>();
const segments = useSegments(); // Get the current route segments
const hideDrawerToggleRoutes = ["login", "password-reset", "+not-found"];
const isHiddenRoute = segments.some((segment) =>
hideDrawerToggleRoutes.includes(segment)
);
useEffect(() => {
dispatch(monitorConnection());
}, [dispatch]);
return (
<ThemeProvider value={theme === "dark" ? DarkTheme : DefaultTheme}>
<SafeAreaView className={`flex-1 ${settings.SafeAreaView}`}>
<StatusBar style={theme === "dark" ? "light" : "dark"} />
<GestureHandlerRootView className="flex-1">
{!isHiddenRoute && (
<View
className={`h-20 flex-row items-center px-4 ${settings.DrawerHeader}`}
>
<DrawerToggleButton />
<View className="ml-2">
<ConnectionStatusIndicator />
</View>
</View>
)}
<NavigationDrawer />
</GestureHandlerRootView>
</SafeAreaView>
</ThemeProvider>
);
}
export default function RootLayout() {
const [loaded] = useFonts({
SpaceMono: require("../assets/fonts/SpaceMono-Regular.ttf"),
});
useEffect(() => {
if (loaded) {
SplashScreen.hideAsync();
initializeLocale();
}
}, [loaded]);
if (!loaded) {
return null;
}
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<AppContent />
</PersistGate>
</Provider>
);
}
在这个问题上坐了这么久之后,我的解决方案是更新我的所有依赖项,现在我真的不知道是什么为我解决了这个问题,但它可能与世博会有关。