This repository was archived by the owner on Aug 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.tsx
More file actions
91 lines (82 loc) · 2.7 KB
/
app.tsx
File metadata and controls
91 lines (82 loc) · 2.7 KB
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
/* eslint-disable no-unused-vars */
/* eslint-disable react/style-prop-object */
// eslint-disable-next-line import/no-extraneous-dependencies
import 'react-native-gesture-handler';
import {
NavigationContainer,
DefaultTheme,
DarkTheme,
} from '@react-navigation/native';
import { useColorScheme, LogBox } from 'react-native';
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
import { StatusBar } from 'expo-status-bar';
import { SafeAreaView } from 'react-native-safe-area-context';
import React, { useState, useEffect } from 'react';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { ThemeContext } from '@util/constants';
import HomeScreen from '@screens/home';
import GalleryScreen from '@screens/gallery';
import SettingScreen from '@screens/settings';
import { StorageKeys } from '@util/types';
import { log } from '@util/log';
import checkUpdate from '@util/update';
LogBox.ignoreLogs([
'`new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.',
'`new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.',
]);
const Tab = createMaterialTopTabNavigator();
export default function App() {
const scheme = useColorScheme();
const [currentTheme, changeTheme] = useState(scheme);
// get the theme from the storage
useEffect(() => {
checkUpdate();
AsyncStorage.getItem(StorageKeys.Settings)
.then(x => {
const value = JSON.parse(x);
if (value.theme) {
if (value.theme === 'auto') {
changeTheme(scheme);
} else changeTheme(value.theme);
} else {
changeTheme(scheme);
}
})
.catch(err => log.error(err));
}, [scheme]);
const selectedTheme = currentTheme === 'dark' ? DarkTheme : DefaultTheme;
// eslint-disable-next-line react/jsx-no-constructed-context-values
const themeData = { currentTheme, changeTheme };
return (
<SafeAreaView style={{ flex: 1 }}>
<ThemeContext.Provider value={themeData}>
<NavigationContainer theme={selectedTheme}>
<Tab.Navigator
screenOptions={() => ({
tabBarActiveTintColor: 'turquoise',
tabBarInactiveTintColor: 'gray',
headerShown: false,
unmountOnBlur: true,
})}>
<Tab.Screen
name='Home'
component={HomeScreen}
/>
<Tab.Screen
name='Gallery'
component={GalleryScreen}
/>
<Tab.Screen
name='Settings'
component={SettingScreen}
/>
</Tab.Navigator>
</NavigationContainer>
</ThemeContext.Provider>
<StatusBar
style={currentTheme === 'dark' ? 'light' : 'dark'}
backgroundColor={currentTheme === 'dark' ? '#000' : '#fff'}
/>
</SafeAreaView>
);
}