-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
153 lines (140 loc) · 4.86 KB
/
Copy pathApp.js
File metadata and controls
153 lines (140 loc) · 4.86 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import 'react-native-gesture-handler';
import React, { useEffect, useRef, useState } from 'react';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import {
NavigationContainer,
DefaultTheme as NavDefaultTheme,
DarkTheme as NavDarkTheme,
} from '@react-navigation/native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { View, StatusBar, Animated, StyleSheet } from 'react-native';
import * as SystemUI from 'expo-system-ui';
import * as SplashScreen from 'expo-splash-screen';
import { SettingsProvider, useSettings } from './src/store/SettingsStore';
import { NotesProvider } from './src/store/NotesStore';
import { ThemeProvider } from './src/theme/theme';
import { I18nProvider } from './src/i18n/i18n';
import HomeScreen from './src/screens/HomeScreen';
import SettingsScreen from './src/screens/SettingsScreen';
import SidePanel from './src/components/SidePanel';
import UpdateChecker from './src/components/UpdateChecker';
// Keep the splash visible until our content is ready.
SplashScreen.preventAutoHideAsync().catch(() => {});
const Drawer = createDrawerNavigator();
const Stack = createNativeStackNavigator();
function DrawerNav() {
const { theme } = useSettings();
return (
<Drawer.Navigator
drawerContent={(props) => <SidePanel {...props} />}
screenOptions={{
headerShown: false,
drawerType: 'front',
drawerStyle: { width: '78%', backgroundColor: theme.bg },
sceneContainerStyle: { backgroundColor: theme.bg },
overlayColor: 'rgba(0,0,0,0.4)',
}}
>
<Drawer.Screen name="Home" component={HomeScreen} />
</Drawer.Navigator>
);
}
function Root() {
const { theme, ready } = useSettings();
// Overlay opacity for the splash fade-out (1 = fully covering, 0 = invisible).
const splashOpacity = useRef(new Animated.Value(1)).current;
const [splashVisible, setSplashVisible] = useState(true);
// Keep the native window background in sync with the theme so the
// Android system doesn't flash white when the keyboard opens.
useEffect(() => {
SystemUI.setBackgroundColorAsync(theme.bg).catch(() => {});
}, [theme.bg]);
// When data is loaded: hide the native splash and fade out our overlay.
useEffect(() => {
if (!ready) return;
SplashScreen.hideAsync().catch(() => {});
Animated.timing(splashOpacity, {
toValue: 0,
duration: 500,
useNativeDriver: true,
}).start(() => setSplashVisible(false));
}, [ready, splashOpacity]);
// Match the navigation theme to our background so transitions don't flash.
const baseNavTheme = theme.mode === 'dark' ? NavDarkTheme : NavDefaultTheme;
const navTheme = {
...baseNavTheme,
colors: {
...baseNavTheme.colors,
background: theme.bg,
card: theme.bg,
text: theme.textPrimary,
border: 'transparent',
primary: theme.primary,
},
};
return (
<ThemeProvider theme={theme}>
<StatusBar
barStyle={theme.mode === 'dark' ? 'light-content' : 'dark-content'}
backgroundColor={theme.bg}
translucent={false}
/>
<View style={{ flex: 1, backgroundColor: theme.bg }}>
{ready && (
<NavigationContainer theme={navTheme}>
<Stack.Navigator
screenOptions={{
headerShown: false,
contentStyle: { backgroundColor: theme.bg },
animation: 'slide_from_right',
}}
>
<Stack.Screen name="Drawer" component={DrawerNav} />
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={{ presentation: 'card' }}
/>
</Stack.Navigator>
</NavigationContainer>
)}
{/* Solid-color overlay that fades out once content is ready.
Color matches the theme so the splash blends into the app. */}
{splashVisible && (
<Animated.View
pointerEvents={ready ? 'none' : 'auto'}
style={[
StyleSheet.absoluteFill,
{ backgroundColor: theme.bg, opacity: splashOpacity },
]}
/>
)}
</View>
</ThemeProvider>
);
}
// Bridge: pull locale from settings and feed it into I18nProvider.
function LocalizedRoot() {
const { locale } = useSettings();
return (
<I18nProvider locale={locale}>
<NotesProvider>
<UpdateChecker />
<Root />
</NotesProvider>
</I18nProvider>
);
}
export default function App() {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<SafeAreaProvider>
<SettingsProvider>
<LocalizedRoot />
</SettingsProvider>
</SafeAreaProvider>
</GestureHandlerRootView>
);
}