-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathApp.tsx
68 lines (55 loc) · 1.95 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
import 'react-native-get-random-values'; // react native moment
import {useEffect, useState} from 'react';
import {StyleSheet} from 'react-native';
import {ErrorBoundary} from 'react-error-boundary';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {setFunction} from '@rvmob/Generic';
import {MainView} from '@rvmob/MainView';
import {ErrorMessage} from '@rvmob/components/ErrorMessage';
import {LoadingScreen} from '@rvmob/components/views/LoadingScreen';
import {storage} from '@rvmob/lib/storage';
import {migrateToMMKV} from '@rvmob/lib/storage/migration';
import {initialiseSettings} from '@rvmob/lib/storage/utils';
import {themes, Theme, ThemeContext} from '@rvmob/lib/themes';
export const App = () => {
const [checkedMigration, setCheckedMigration] = useState(false);
const [theme, setTheme] = useState<Theme>(themes.Dark);
const localStyles = generateLocalStyles(theme);
setFunction('setTheme', (themeName: string) => {
const newTheme = themes[themeName] ?? themes.Dark;
setTheme(newTheme);
});
useEffect(() => {
async function migrationCheck() {
const hasMigrated = storage.getBoolean('hasMigrated');
if (!hasMigrated) {
await migrateToMMKV();
}
initialiseSettings();
setCheckedMigration(true);
}
migrationCheck();
}, []);
return (
<GestureHandlerRootView style={localStyles.outer}>
<ThemeContext.Provider
value={{currentTheme: theme, setCurrentTheme: setTheme}}>
<ErrorBoundary fallbackRender={ErrorMessage}>
{checkedMigration ? (
<MainView />
) : (
<LoadingScreen header={'app.loading.migrating_settings'} />
)}
</ErrorBoundary>
</ThemeContext.Provider>
</GestureHandlerRootView>
);
};
const generateLocalStyles = (currentTheme: Theme) => {
return StyleSheet.create({
outer: {
flex: 1,
backgroundColor: currentTheme.backgroundSecondary,
},
});
};