-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
76 lines (65 loc) · 2 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
import AsyncStorage from '@react-native-async-storage/async-storage';
import { DarkTheme as NavDark, DefaultTheme as NavLight, NavigationContainer, Theme } from '@react-navigation/native';
import React, { Suspense, useEffect, useState } from 'react';
import { AppState, StatusBar } from 'react-native';
import SplashScreen from 'react-native-splash-screen';
import { RecoilRoot, useRecoilValue } from 'recoil';
import { DefaultTheme, ThemeProvider } from 'styled-components';
import { rstDarkMode } from './source/model/setting';
import { DarkTheme, LightTheme } from './source/model/theme';
import { updateLastOpenedDate } from './source/util/storage';
import { Navigator } from './source/view/Navigator';
interface AppUIProps {
theme: DefaultTheme;
navTheme: Theme;
}
const AppUI = (props: AppUIProps) => {
const { theme, navTheme } = props;
return (
<NavigationContainer theme={navTheme}>
<ThemeProvider theme={theme}>
<Navigator />
</ThemeProvider>
</NavigationContainer>
);
};
const ThemeLoader = () => {
const isDarkMode = useRecoilValue(rstDarkMode);
const [theme, setTheme] = useState<DefaultTheme>(DarkTheme);
const [navTheme, setNavTheme] = useState<Theme>(NavDark);
useEffect(() => {
AsyncStorage.getAllKeys().then(keys => AsyncStorage.multiGet(keys)).then(result => {
console.log('All Data:\t', JSON.stringify(result));
});
const update = AppState.addEventListener('change', nextState => {
if (nextState !== 'active') {
console.log('Update last_opened_date');
updateLastOpenedDate();
}
});
return () => update.remove();
}, []);
useEffect(() => {
setTheme(isDarkMode ? DarkTheme : LightTheme);
setNavTheme(isDarkMode ? NavDark : NavLight);
}, [isDarkMode]);
return (
<AppUI theme={theme} navTheme={navTheme} />
);
};
const App = () => {
useEffect(() => {
setTimeout(() => {
SplashScreen.hide();
}, 3 * 1000);
}, []);
return (
<RecoilRoot>
<Suspense>
<ThemeLoader />
<StatusBar hidden />
</Suspense>
</RecoilRoot >
);
};
export default App;