-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.tsx
More file actions
167 lines (154 loc) · 6.46 KB
/
Copy pathApp.tsx
File metadata and controls
167 lines (154 loc) · 6.46 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
import React, { useState } from 'react';
import { StatusBar } from 'react-native';
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import { createStackNavigator } from 'react-navigation-stack';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import ErrorBoundary from 'react-native-error-boundary';
import 'react-native-gesture-handler';
import AppLoading from 'expo-app-loading';
import * as Linking from 'expo-linking';
import * as Font from 'expo-font';
import { FontAwesome5 } from '@expo/vector-icons';
import I18n from './i18n';
import ExploreScreen from './src/screens/ExploreScreen';
import BookmarkedScreen from './src/screens/BookmarkedScreen';
import LikedScreen from './src/screens/LikedScreen';
import ProfileOverviewScreen from './src/screens/ProfileOverviewScreen';
import TourScreen from './src/screens/TourScreen';
import ErrorFallback from './src/components/ErrorFallback';
import useMarkers from './src/hooks/useMarkers';
import useLocation from './src/hooks/useLocation';
import { markerProvider as MarkerProvider } from './src/context/markerContext';
import { BACKGROUND_COLOR, INACTIVE_SYMBOL_COLOR, PRIMARY_COLOR } from './src/styles/globalStyles';
// flow inside the profile tab should be stacked
// means: multiple screens inside the same tab
const profileFlow = createStackNavigator(
{
Overview: ProfileOverviewScreen,
Liked: LikedScreen,
Bookmarked: BookmarkedScreen,
},
{
headerMode: 'none',
},
);
//@ts-ignore
const getScreenRegisteredFunctions = navState => {
const { routes, index, params } = navState;
if (navState.hasOwnProperty('index')) {
return getScreenRegisteredFunctions(routes[index]);
} else {
return params;
}
};
const bottomTab = createBottomTabNavigator(
{
// the screens which are associated with the tabs in the navigator
// the left id is the routename which is per default also the title of the tab
// profileFlow consists of the stack navigator with multiple screens
Explore: {
screen: ExploreScreen,
path: 'objects/:objectId',
navigationOptions: {
tabBarLabel: I18n.t('exploreScreen'),
},
},
Tour: {
screen: TourScreen,
path: 'tours',
navigationOptions: {
tabBarLabel: I18n.t('tourScreen'),
},
},
profileFlow: {
screen: profileFlow,
navigationOptions: {
tabBarLabel: I18n.t('profileScreen'),
},
},
},
{
initialRouteName: 'Explore',
// function to set the icons and colors of the tabs
// 'navigation' is the the current route which is focued
defaultNavigationOptions: ({ navigation }) => ({
// the tintColor is defined in the tabBarOptions and given to
// the tabbaricon
tabBarIcon: ({ tintColor }) => {
let { routeName } = navigation.state;
let iconName; // the FontAwesome5 name of the icon according to @expo/vector-icons
if (routeName === 'Explore') {
iconName = 'compass';
} else if (routeName === 'Tour') {
iconName = 'route';
} else if (routeName === 'profileFlow') {
iconName = 'user-circle';
}
return (
<>
{/* set the colors of the status bar to be visible; default is white content */}
<StatusBar backgroundColor={'transparent'} translucent barStyle='dark-content' />
<FontAwesome5 name={`${iconName}`} size={26} color={`${tintColor}`} />
</>
);
},
tabBarOnPress: ({ defaultHandler }) => {
if (navigation && navigation.isFocused()) {
const screenFunctions = getScreenRegisteredFunctions(navigation.state);
if (screenFunctions && typeof screenFunctions.tapOnNavigator === 'function') {
screenFunctions.tapOnNavigator();
}
}
defaultHandler();
},
}),
tabBarOptions: {
activeBackgroundColor: BACKGROUND_COLOR,
inactiveBackgroundColor: BACKGROUND_COLOR,
activeTintColor: PRIMARY_COLOR,
inactiveTintColor: INACTIVE_SYMBOL_COLOR,
style: {
backgroundColor: BACKGROUND_COLOR,
},
},
},
);
// switch navigator will be neccessary as soon as we have a splash screen
// after the loading of the app is ready => app should switch from the splash screen to our mainFlow
const switchNavigator = createSwitchNavigator({
mainFlow: { screen: bottomTab, path: '' },
});
const App = createAppContainer(switchNavigator);
const prefix = Linking.makeUrl('/');
export default () => {
const [ready, setReady] = useState<boolean>(false);
const [getMarkers, getMarkersBySearch, markerResult, markerApiLoading, markerApiErrorMessage] = useMarkers();
const { checkLocationPermission } = useLocation();
const onInit = async () => {
await Font.loadAsync({
'OpenSans Regular': require('./assets/fonts/OpenSans-Regular.ttf'),
'OpenSans Italic': require('./assets/fonts/OpenSans-Italic.ttf'),
'OpenSans SemiBold': require('./assets/fonts/OpenSans-SemiBold.ttf'),
'OpenSans SemiBold Italic': require('./assets/fonts/OpenSans-SemiBoldItalic.ttf'),
'OpenSans Light': require('./assets/fonts/OpenSans-Light.ttf'),
'OpenSans Light Italic': require('./assets/fonts/OpenSans-LightItalic.ttf'),
'Lato Bold Italic': require('./assets/fonts/Lato-BoldItalic.ttf'),
});
//await checkLocationPermission();
await getMarkers();
};
return !ready ? (
<ErrorBoundary FallbackComponent={ErrorFallback}>
<AppLoading startAsync={onInit} onFinish={() => setReady(true)} onError={console.warn} />
</ErrorBoundary>
) : (
<ErrorBoundary FallbackComponent={ErrorFallback}>
<MarkerProvider value={markerResult}>
<SafeAreaProvider>
<App uriPrefix={prefix} />
</SafeAreaProvider>
</MarkerProvider>
</ErrorBoundary>
);
};