-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
168 lines (146 loc) · 6.06 KB
/
Copy pathApp.js
File metadata and controls
168 lines (146 loc) · 6.06 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import { colors, ThemeContext } from "./non-components/globalStyles";
import { useFonts } from "expo-font";
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { NavigationContainer } from '@react-navigation/native';
import IntroScreen from './components/screens/IntroScreen';
import HomeTabNavigation from "./components/shared/HomeTabNavigation";
import { SafeAreaProvider } from "react-native-safe-area-context";
import React, { useState } from 'react';
import { StatusBar } from "expo-status-bar";
import { getFocusedRouteNameFromRoute } from "@react-navigation/native";
const Stack = createNativeStackNavigator();
export default function App() {
const [fontsLoaded] = useFonts({
'nunito-light': require('./assets/fonts/nunito/Nunito-Light.ttf'),
'nunito-regular': require('./assets/fonts/nunito/Nunito-Regular.ttf'),
'nunito-medium': require('./assets/fonts/nunito/Nunito-Medium.ttf'),
'nunito-semi-bold': require('./assets/fonts/nunito/Nunito-SemiBold.ttf'),
'nunito-bold': require('./assets/fonts/nunito/Nunito-Bold.ttf'),
'roboto-light': require('./assets/fonts/roboto/Roboto-Light.ttf'),
'roboto-regular': require('./assets/fonts/roboto/Roboto-Regular.ttf'),
'roboto-medium': require('./assets/fonts/roboto/Roboto-Medium.ttf'),
'roboto-bold': require('./assets/fonts/roboto/Roboto-Bold.ttf'),
'work-sans-extra-light': require('./assets/fonts/work-sans/WorkSans-ExtraLight.ttf'),
'work-sans-light': require('./assets/fonts/work-sans/WorkSans-Light.ttf'),
'work-sans-regular': require('./assets/fonts/work-sans/WorkSans-Regular.ttf'),
'work-sans-medium': require('./assets/fonts/work-sans/WorkSans-Medium.ttf'),
'work-sans-semi-bold': require('./assets/fonts/work-sans/WorkSans-SemiBold.ttf'),
'work-sans-bold': require('./assets/fonts/work-sans/WorkSans-Bold.ttf')
});
/*
? State should be exactly the same as the default
? value in ThemeContext as recommended by docs.
? https://reactjs.org/docs/context.html#updating-context-from-a-nested-component
*/
const [theme, setTheme] = useState({
darkModeEnabled: false,
toggleDarkMode: toggleDarkMode
});
function toggleDarkMode() {
setTheme(prevState => ({
...prevState,
darkModeEnabled: !prevState.darkModeEnabled
}));
};
const themeColors = {
backgroundColor:
getColor(colors.offWhite, colors.darkCharcoalGrey),
whiteOrDarkBrown:
getColor(colors.darkBrown, colors.white),
whiteOrDarkGreyPurple:
getColor(colors.white, colors.darkGreyPurple),
whiteOrDarkCharcoalGrey:
getColor(colors.white, colors.darkCharcoalGrey),
partialOpacityDarkBrownOrGrey:
getColor(colors.partialOpacityDarkBrown, colors.grey),
translucentDarkBrownOrGrey:
getColor(colors.translucentDarkBrown, colors.grey),
transparentOrDarkGreyPurple:
getColor('transparent', colors.darkGreyPurple),
darkBrownOrDarkGreyPurple:
getColor(colors.darkBrown, colors.darkGreyPurple),
darkBrown10PercentOpacityOrDarkGreyPurple:
getColor(colors.darkBrown10PercentOpacity, colors.darkGreyPurple)
};
function getColor(lightModeColor, darkModeColor) {
return theme.darkModeEnabled
? darkModeColor
: lightModeColor;
}
function getHeaderTitle(route) {
/*
? If the focused route is not found, we need to assume
? it's the initial screen. This can happen if
? there hasn't been any navigation inside the screen
? In our case, it's "My Recipes" as that's the first
? screen inside the navigator
*/
const routeName = getFocusedRouteNameFromRoute(route) ?? "Inpirations";
switch (routeName) {
case 'My Recipes':
return 'My recipes';
case 'Cook Now!':
return 'Cooking time!'
case 'Settings':
return 'Settings';
default:
return 'Cooksy';
}
}
if (!fontsLoaded)
return null;
return (
/*
* All screens seem to have the light mode background color
* somehow even though I don't remember applying it somewhere.
* Worth looking into.
*/
<SafeAreaProvider>
<StatusBar style={ theme.darkModeEnabled ? "light" : "dark" } />
<NavigationContainer>
<ThemeContext.Provider value={{
theme: theme,
themeColors: themeColors
}}>
<Stack.Navigator screenOptions={{
headerStyle: {
backgroundColor: themeColors.backgroundColor
},
headerShadowVisible: false,
headerTitleStyle: {
fontFamily: 'work-sans-semi-bold',
fontSize: 24
},
headerTitleAlign: 'center',
headerTintColor: themeColors.whiteOrDarkBrown
}}>
<Stack.Screen
name='Intro'
component={ IntroScreen }
options={{
title: 'Cooksy',
headerTransparent: true // * <- Absolutely position header. Read more in docs: https://reactnavigation.org/docs/native-stack-navigator#headertransparent
}}
/>
{/*
This part of the docs explained how to set the
header title of the stack navigator based on the
state of the nested tab navigator.
https://reactnavigation.org/docs/screen-options-resolution#setting-parent-screen-options-based-on-child-navigators-state
*/}
<Stack.Screen
name='Home'
component={ HomeTabNavigation }
options={({ route }) => ({
headerTitle: getHeaderTitle(route),
headerTitleStyle: getHeaderTitle(route) !== 'Cooksy'
? { fontFamily: 'work-sans-semi-bold', fontSize: 18 }
: { fontFamily: 'work-sans-semi-bold', fontSize: 24 }
})}
/>
</Stack.Navigator>
</ThemeContext.Provider>
</NavigationContainer>
</SafeAreaProvider>
);
}