@@ -5,7 +5,7 @@ import { DeprecatedUi } from '@rnr/reusables';
5
5
import { Stack } from 'expo-router' ;
6
6
import { StatusBar } from 'expo-status-bar' ;
7
7
import * as React from 'react' ;
8
- import { Platform } from 'react-native' ;
8
+ import { Appearance , Platform } from 'react-native' ;
9
9
import { GestureHandlerRootView } from 'react-native-gesture-handler' ;
10
10
import { ThemeToggle } from '~/components/ThemeToggle' ;
11
11
import { Text } from '~/components/ui/text' ;
@@ -34,28 +34,16 @@ export const unstable_settings = {
34
34
initialRouteName : '(tabs)' ,
35
35
} ;
36
36
37
- export default function RootLayout ( ) {
38
- const hasMounted = React . useRef ( false ) ;
39
- const { colorScheme, isDarkColorScheme } = useColorScheme ( ) ;
40
- const [ isColorSchemeLoaded , setIsColorSchemeLoaded ] = React . useState ( false ) ;
41
-
42
- useIsomorphicLayoutEffect ( ( ) => {
43
- if ( hasMounted . current ) {
44
- return ;
45
- }
37
+ const usePlatformSpecificSetup = Platform . select ( {
38
+ web : useSetWebBackgroundClassName ,
39
+ android : useSetAndroidNavigationBar ,
40
+ default : noop ,
41
+ } ) ;
46
42
47
- if ( Platform . OS === 'web' ) {
48
- // Adds the background color to the html element to prevent white background on overscroll.
49
- document . documentElement . classList . add ( 'bg-background' ) ;
50
- }
51
- setAndroidNavigationBar ( colorScheme ) ;
52
- setIsColorSchemeLoaded ( true ) ;
53
- hasMounted . current = true ;
54
- } , [ ] ) ;
43
+ export default function RootLayout ( ) {
44
+ const { isDarkColorScheme } = useColorScheme ( ) ;
55
45
56
- if ( ! isColorSchemeLoaded ) {
57
- return null ;
58
- }
46
+ usePlatformSpecificSetup ( ) ;
59
47
60
48
return (
61
49
< ThemeProvider value = { isDarkColorScheme ? DARK_THEME : LIGHT_THEME } >
@@ -95,9 +83,6 @@ export default function RootLayout() {
95
83
) ;
96
84
}
97
85
98
- const useIsomorphicLayoutEffect =
99
- Platform . OS === 'web' && typeof window === 'undefined' ? React . useEffect : React . useLayoutEffect ;
100
-
101
86
function toOptions ( name : string ) {
102
87
const title = name
103
88
. split ( '-' )
@@ -109,3 +94,21 @@ function toOptions(name: string) {
109
94
. join ( ' ' ) ;
110
95
return title ;
111
96
}
97
+
98
+ const useIsomorphicLayoutEffect =
99
+ Platform . OS === 'web' && typeof window === 'undefined' ? React . useEffect : React . useLayoutEffect ;
100
+
101
+ function useSetWebBackgroundClassName ( ) {
102
+ useIsomorphicLayoutEffect ( ( ) => {
103
+ // Adds the background color to the html element to prevent white background on overscroll.
104
+ document . documentElement . classList . add ( 'bg-background' ) ;
105
+ } , [ ] ) ;
106
+ }
107
+
108
+ function useSetAndroidNavigationBar ( ) {
109
+ React . useLayoutEffect ( ( ) => {
110
+ setAndroidNavigationBar ( Appearance . getColorScheme ( ) ?? 'light' ) ;
111
+ } , [ ] ) ;
112
+ }
113
+
114
+ function noop ( ) { }
0 commit comments