Skip to content

Commit

Permalink
Add system background color handler
Browse files Browse the repository at this point in the history
  • Loading branch information
martinezguillaume committed Feb 12, 2024
1 parent 5e51ffb commit 9979279
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import {DarkTheme, DefaultTheme, ThemeProvider} from '@react-navigation/native'
import {
DarkTheme,
DefaultTheme,
ThemeProvider,
useTheme,
} from '@react-navigation/native'
import {useAssets} from 'expo-asset'
import {useFonts} from 'expo-font'
import {Slot, SplashScreen} from 'expo-router'
import {ReactNode, useEffect} from 'react'
import * as SystemUI from 'expo-system-ui'
import Feather from '@expo/vector-icons/Feather'
import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons'
import {View} from 'react-native'
Expand Down Expand Up @@ -53,6 +59,12 @@ export default function RootLayout() {

function Theme({name, children}: {name: ThemeName; children: ReactNode}) {
const {colorScheme} = useColorSchemeStore()
const {colors} = useTheme()

useEffect(() => {
SystemUI.setBackgroundColorAsync(colors.background)
}, [colorScheme, colors.background])

return (
<View className="flex-1" style={themes[name][colorScheme]}>
{children}
Expand All @@ -65,10 +77,10 @@ function RootLayoutNav() {
const {colorScheme} = useColorSchemeStore()

return (
<Theme name="twitter">
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
<Theme name="twitter">
<Slot key={locale} />
</ThemeProvider>
</Theme>
</Theme>
</ThemeProvider>
)
}

0 comments on commit 9979279

Please sign in to comment.