-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
87 lines (79 loc) · 2.42 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import React from 'react';
import { I18nManager } from 'react-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { AppearanceProvider, useColorScheme } from 'react-native-appearance';
import {
Provider as PaperProvider,
DefaultTheme as PaperTheme,
DarkTheme as PaperDarkTheme,
} from 'react-native-paper';
import { Updates } from 'expo';
import { auth, UserContext } from './lib/firebase';
import * as SplashScreen from 'expo-splash-screen';
import {
PreferencesContext,
PreferencesContextType,
} from './context/preferences';
import { RootNabigator } from './components/navigator';
export default function App(): JSX.Element {
const [user, setUser] = React.useState(auth.currentUser);
const colorScheme = useColorScheme();
const [theme, setTheme] = React.useState<'light' | 'dark'>(
colorScheme === 'dark' ? 'dark' : 'light',
);
const [rtl] = React.useState<boolean>(I18nManager.isRTL);
function toggleTheme() {
setTheme((theme) => (theme === 'light' ? 'dark' : 'light'));
}
const toggleRTL = React.useCallback(() => {
I18nManager.forceRTL(!rtl);
Updates.reloadFromCache();
}, [rtl]);
const preferences = React.useMemo(
(): PreferencesContextType => ({
toggleTheme,
toggleRTL,
theme,
rtl: rtl ? 'right' : 'left',
}),
[rtl, theme, toggleRTL],
);
React.useEffect(() => {
// TODO(k2wanko): Implement loading
SplashScreen.preventAutoHideAsync();
const unsubscribe = auth.onAuthStateChanged((user) => {
SplashScreen.hideAsync();
setUser(user);
});
return () => {
unsubscribe();
};
});
return (
<>
<SafeAreaProvider>
<AppearanceProvider>
<PreferencesContext.Provider value={preferences}>
<PaperProvider
theme={
theme === 'light'
? {
...PaperTheme,
colors: { ...PaperTheme.colors, primary: '#ffab40' },
}
: {
...PaperDarkTheme,
colors: { ...PaperDarkTheme.colors, primary: '#ffab40' },
}
}
>
<UserContext.Provider value={user}>
<RootNabigator />
</UserContext.Provider>
</PaperProvider>
</PreferencesContext.Provider>
</AppearanceProvider>
</SafeAreaProvider>
</>
);
}