-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
95 lines (68 loc) · 2.69 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
88
89
90
91
92
93
94
95
import React, { useEffect } from 'react';
import { LogBox, StatusBar } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import {
DarkTheme as NavigationDarkTheme,
DefaultTheme as NavigationDefaultTheme,
} from '@react-navigation/native';
import {
MD3LightTheme,
MD3DarkTheme,
PaperProvider,
adaptNavigationTheme
} from 'react-native-paper';
import merge from 'deepmerge';
import { loadValue } from './functions/DataStorageFunctions';
import { serialNumberStoredKey } from './Variables';
const { LightTheme, DarkTheme } = adaptNavigationTheme({
reactNavigationLight: NavigationDefaultTheme,
reactNavigationDark: NavigationDarkTheme,
});
const CombinedDefaultTheme = merge(MD3LightTheme, LightTheme);
const CombinedDarkTheme = merge(MD3DarkTheme, DarkTheme);
import { PreferencesContext } from './PreferencesContext';
import { PageHeader } from './components/PageHeader';
import { BottomTabNavigator } from './components/BottomTabNavigator';
import { StartDialog } from './components/StartDialog';
const darkThemeColors = require('./theme/dark-theme.json');
const lightThemeColors = require('./theme/light-theme.json');
LogBox.ignoreLogs([
"Require cycle: node_modules/victory",
]);
export default function App () {
const [isThemeDark, setIsThemeDark] = React.useState(true);
const [serialNumber, setSerialNumber] = React.useState("");
let theme = isThemeDark ? CombinedDarkTheme : CombinedDefaultTheme;
let themeColors = isThemeDark ? darkThemeColors : lightThemeColors;
const toggleTheme = React.useCallback(() => {
return setIsThemeDark(!isThemeDark);
}, [isThemeDark]);
const preferences = React.useMemo(
() => ({
toggleTheme,
isThemeDark
}),
[toggleTheme, isThemeDark]
);
useEffect(() => {
loadValue(serialNumberStoredKey).then(loadedSerialNumber => {
if (loadedSerialNumber != null) {
setSerialNumber(loadedSerialNumber);
}
})
}, [])
const [dialogVisible, setDialogVisible] = React.useState(true);
const hideDialog = () => setDialogVisible(false);
return (
<PreferencesContext.Provider value={preferences}>
<PaperProvider theme={theme}>
<NavigationContainer theme={theme}>
<StatusBar barStyle={isThemeDark ? 'light-content': 'dark-content'} />
<PageHeader showStartDialog={setDialogVisible} />
<StartDialog visible={dialogVisible} hideDialog={hideDialog} />
<BottomTabNavigator serialNumber={serialNumber} setSerialNumber={setSerialNumber} themeColors={themeColors} />
</NavigationContainer>
</PaperProvider>
</PreferencesContext.Provider>
)
};