-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
131 lines (110 loc) · 3.59 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
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
import 'react-native-gesture-handler';
import 'react-native-get-random-values';
import React, {
useEffect,
useLayoutEffect,
useState,
type PropsWithChildren,
} from 'react';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
useColorScheme,
View,
} from 'react-native';
import Text from './components/global/CustomText';
import {NavigationContainer, DefaultTheme} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import HomeScreen from './components/home/Index';
import Forecasts from './components/home/Forecasts';
import Location from './components/locations/Index';
import LocationSearch from './components/locations/Search';
import Settings from './components/settings/Index';
import Setting from './components/settings/Setting';
import {NavigationDarkTheme} from './Global.styles';
import {
LocationStackParamList,
RootStackParamList,
SettingsStackParamList,
} from './types';
import locationManager, {LocationProfile} from './classes/LocationManager';
import SettingsManager from './Settings';
const Stack = createNativeStackNavigator<RootStackParamList>();
const LocationStack = createNativeStackNavigator<LocationStackParamList>();
const SettingsStack = createNativeStackNavigator<SettingsStackParamList>();
// @ts-expect-error
export const LocationContext = React.createContext<LocationContextProps>();
interface LocationContextProps {
location: LocationProfile | null;
setLocation: (location: LocationProfile) => void;
}
function LocationScreen() {
return (
<LocationStack.Navigator
initialRouteName="Index"
screenOptions={{headerShown: false}}>
<LocationStack.Screen name="Index" component={Location} />
<LocationStack.Screen name="Search" component={LocationSearch} />
</LocationStack.Navigator>
);
}
function SettingsScreen() {
return (
<SettingsStack.Navigator
initialRouteName="Index"
screenOptions={{headerShown: false}}>
<SettingsStack.Screen name="Index" component={Settings} />
<SettingsStack.Screen
name="Setting"
component={Setting}
options={{animation: 'slide_from_right'}}
/>
</SettingsStack.Navigator>
);
}
function HomeStackScreen() {
return (
<Stack.Navigator
initialRouteName="Home"
screenOptions={{headerShown: false}}>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Forecasts" component={Forecasts} />
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={{animation: 'slide_from_right'}}
/>
<Stack.Screen
name="Locations"
component={LocationScreen}
options={{animation: 'slide_from_right'}}
/>
</Stack.Navigator>
);
}
const App = () => {
const isDark = useColorScheme() === 'dark';
// TODO: Change to use my theme instead of default
// theme={isDark ? NavigationDarkTheme : DefaultTheme}
const [location, setLocation] = useState(locationManager.selectedLocation);
useEffect(() => {
locationManager.addEventStateUpdater('selectedLocation', setLocation);
return () =>
locationManager.removeEventStateUpdater('selectedLocation', setLocation);
}, [setLocation]);
return (
<>
<StatusBar barStyle={isDark ? 'light-content' : 'dark-content'} />
<NavigationContainer
theme={NavigationDarkTheme}
fallback={<Text>Loading</Text>}>
<LocationContext.Provider value={{location, setLocation}}>
<HomeStackScreen />
</LocationContext.Provider>
</NavigationContainer>
</>
);
};
export default App;