修复主题切换导航栏和状态栏

This commit is contained in:
xianyi
2026-01-13 09:46:05 +08:00
parent 9c16586994
commit 98134c5be9
3 changed files with 36 additions and 6 deletions

View File

@@ -17,6 +17,7 @@ export default function TabLayout() {
<Tabs <Tabs
screenOptions={{ screenOptions={{
tabBarActiveTintColor: Colors[theme].tint, tabBarActiveTintColor: Colors[theme].tint,
tabBarInactiveTintColor: Colors[theme].tabIconDefault,
headerShown: false, headerShown: false,
tabBarButton: HapticTab, tabBarButton: HapticTab,
tabBarBackground: TabBarBackground, tabBarBackground: TabBarBackground,

View File

@@ -7,6 +7,7 @@ import { Stack } from "expo-router";
import { StatusBar } from "expo-status-bar"; import { StatusBar } from "expo-status-bar";
import "react-native-reanimated"; import "react-native-reanimated";
import { Colors } from "@/constants/theme";
import { ThemeProvider } from "@/context/ThemeContext"; import { ThemeProvider } from "@/context/ThemeContext";
import { useColorScheme } from "@/hooks/use-color-scheme"; import { useColorScheme } from "@/hooks/use-color-scheme";
import "@/i18n"; // Initialize i18n import "@/i18n"; // Initialize i18n
@@ -25,11 +26,35 @@ export default function RootLayout() {
function RootLayoutNav() { function RootLayoutNav() {
const colorScheme = useColorScheme(); const colorScheme = useColorScheme();
const isDark = colorScheme === "dark";
// Custom navigation theme to ensure proper colors
const navigationTheme = isDark
? {
...DarkTheme,
colors: {
...DarkTheme.colors,
background: Colors.dark.background,
card: Colors.dark.background,
text: Colors.dark.text,
border: Colors.dark.background,
notification: Colors.dark.tint,
},
}
: {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: Colors.light.background,
card: Colors.light.background,
text: Colors.light.text,
border: Colors.light.background,
notification: Colors.light.tint,
},
};
return ( return (
<NavigationThemeProvider <NavigationThemeProvider value={navigationTheme}>
value={colorScheme === "dark" ? DarkTheme : DefaultTheme}
>
<Stack> <Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} /> <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen <Stack.Screen

View File

@@ -3,12 +3,16 @@ import { BlurView } from "expo-blur";
import { StyleSheet } from "react-native"; import { StyleSheet } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context"; import { useSafeAreaInsets } from "react-native-safe-area-context";
import { useTheme } from "@/context/ThemeContext";
export default function BlurTabBarBackground() { export default function BlurTabBarBackground() {
const { theme } = useTheme();
const isDark = theme === "dark";
return ( return (
<BlurView <BlurView
// System chrome material automatically adapts to the system's theme // Use theme-specific tint to ensure proper background color
// and matches the native tab bar appearance on iOS. tint={isDark ? "dark" : "light"}
tint="systemChromeMaterial"
intensity={100} intensity={100}
style={StyleSheet.absoluteFill} style={StyleSheet.absoluteFill}
/> />