-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.tsx
74 lines (67 loc) · 2.08 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
import React from 'react';
import { ImageProps } from 'react-native';
import { mapping, light, dark } from '@eva-design/eva';
import {
ApplicationProvider,
Button,
ButtonProps,
Icon,
IconRegistry,
} from '@ui-kitten/components';
import { MaterialIconsPack } from './app/components/AppIcons';
import { ColorScheme } from './app/types';
import { ThemeContext } from './app/contexts/ThemeContext';
import { getData, storeData } from './app/api/store';
import useCachedResources from './app/hooks/useCachedResources';
import Navigation from './app/navigation';
import { default as colors } from './app/assets/theme.json';
import { default as customMapping } from './app/assets/mapping.json';
export default function App() {
const isLoadingComplete = useCachedResources();
const [theme, setTheme] = React.useState<ColorScheme>('light');
const isLightTheme = theme === 'light';
React.useEffect(() => {
const getSetTheme = async () => {
const themeData = (await getData('theme', 'light')) as ColorScheme;
setTheme(themeData);
};
getSetTheme();
}, [setTheme]);
const switchTheme = async () => {
const newTheme = isLightTheme ? 'dark' : 'light';
setTheme(newTheme);
await storeData('theme', newTheme);
};
const toggleIcon = (props: Partial<ImageProps> | undefined) => (
<Icon
key="themeToggle"
name={isLightTheme ? 'brightness-2' : 'brightness-7'}
{...props}
/>
);
const ThemeToggle = (props: ButtonProps | undefined) => (
<Button
appearance="ghost"
status="basic"
accessoryLeft={toggleIcon}
onPress={switchTheme}
{...props}
/>
);
return isLoadingComplete ? (
<>
<IconRegistry icons={MaterialIconsPack} />
<ThemeContext.Provider
value={{ theme, setTheme, switchTheme, ThemeToggle }}
>
<ApplicationProvider
mapping={mapping}
customMapping={customMapping}
theme={{ ...(isLightTheme ? light : dark), ...colors }}
>
<Navigation />
</ApplicationProvider>
</ThemeContext.Provider>
</>
) : null;
}