-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathApp.tsx
54 lines (45 loc) · 1.73 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
import 'react-native-get-random-values'; // react native moment
import {useEffect, useState} from 'react';
import {StatusBar, StyleSheet} from 'react-native';
import {ErrorBoundary} from 'react-error-boundary';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {KeyboardProvider} from 'react-native-keyboard-controller';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import {setFunction} from '@clerotri/Generic';
import {MainView} from '@clerotri/MainView';
import {ErrorMessage} from '@clerotri/components/ErrorMessage';
import {initialiseSettings} from '@clerotri/lib/storage/utils';
import {themes, type Theme, ThemeContext} from '@clerotri/lib/themes';
export const App = () => {
const [theme, setTheme] = useState<Theme>(themes.Dark);
const localStyles = generateLocalStyles(theme);
setFunction('setTheme', (themeName: string) => {
const newTheme = themes[themeName] ?? themes.Dark;
setTheme(newTheme);
StatusBar.setBarStyle(`${newTheme.contentType}-content`);
});
useEffect(() => {
initialiseSettings();
}, []);
return (
<SafeAreaProvider style={localStyles.outer}>
<KeyboardProvider statusBarTranslucent navigationBarTranslucent>
<GestureHandlerRootView>
<ThemeContext.Provider
value={{currentTheme: theme, setCurrentTheme: setTheme}}>
<ErrorBoundary FallbackComponent={ErrorMessage}>
<MainView />
</ErrorBoundary>
</ThemeContext.Provider>
</GestureHandlerRootView>
</KeyboardProvider>
</SafeAreaProvider>
);
};
const generateLocalStyles = (currentTheme: Theme) => {
return StyleSheet.create({
outer: {
backgroundColor: currentTheme.background,
},
});
};