2021-08-16 07:50:50 +00:00
|
|
|
/**
|
2021-08-22 04:30:04 +00:00
|
|
|
* If you are not familiar with React Navigation, refer to the "Fundamentals" guide:
|
2021-08-16 07:50:50 +00:00
|
|
|
* https://reactnavigation.org/docs/getting-started
|
|
|
|
*
|
|
|
|
*/
|
2021-08-22 04:30:04 +00:00
|
|
|
import { FontAwesome } from '@expo/vector-icons';
|
|
|
|
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
2021-08-16 07:50:50 +00:00
|
|
|
import { NavigationContainer, DefaultTheme, DarkTheme } from '@react-navigation/native';
|
2021-08-22 04:30:04 +00:00
|
|
|
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
2021-08-16 07:50:50 +00:00
|
|
|
import * as React from 'react';
|
2021-08-22 04:30:04 +00:00
|
|
|
import { ColorSchemeName, Pressable } from 'react-native';
|
2021-08-16 07:50:50 +00:00
|
|
|
|
2021-08-22 04:30:04 +00:00
|
|
|
import Colors from '../constants/Colors';
|
|
|
|
import useColorScheme from '../hooks/useColorScheme';
|
|
|
|
import ModalScreen from '../screens/ModalScreen';
|
2021-08-16 07:50:50 +00:00
|
|
|
import NotFoundScreen from '../screens/NotFoundScreen';
|
2021-08-22 04:30:04 +00:00
|
|
|
import TripScreen from '../screens/TripScreen';
|
|
|
|
import HomeScreen from '../screens/HomeScreen';
|
|
|
|
import SettingsScreen from '../screens/SettingsScreen';
|
|
|
|
import { RootStackParamList, RootTabParamList, RootTabScreenProps } from '../types';
|
2021-08-16 07:50:50 +00:00
|
|
|
import LinkingConfiguration from './LinkingConfiguration';
|
|
|
|
|
|
|
|
export default function Navigation({ colorScheme }: { colorScheme: ColorSchemeName }) {
|
|
|
|
return (
|
|
|
|
<NavigationContainer
|
|
|
|
linking={LinkingConfiguration}
|
|
|
|
theme={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
|
|
|
|
<RootNavigator />
|
|
|
|
</NavigationContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-22 04:30:04 +00:00
|
|
|
/**
|
|
|
|
* A root stack navigator is often used for displaying modals on top of all other content.
|
|
|
|
* https://reactnavigation.org/docs/modal
|
|
|
|
*/
|
|
|
|
const Stack = createNativeStackNavigator<RootStackParamList>();
|
2021-08-16 07:50:50 +00:00
|
|
|
|
|
|
|
function RootNavigator() {
|
|
|
|
return (
|
2021-08-22 04:30:04 +00:00
|
|
|
<Stack.Navigator>
|
|
|
|
<Stack.Screen name="Root" component={BottomTabNavigator} options={{ headerShown: false }} />
|
2021-08-16 07:50:50 +00:00
|
|
|
<Stack.Screen name="NotFound" component={NotFoundScreen} options={{ title: 'Oops!' }} />
|
2021-08-22 04:30:04 +00:00
|
|
|
<Stack.Group screenOptions={{ presentation: 'modal' }}>
|
|
|
|
</Stack.Group>
|
2021-08-16 07:50:50 +00:00
|
|
|
</Stack.Navigator>
|
|
|
|
);
|
|
|
|
}
|
2021-08-22 04:30:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A bottom tab navigator displays tab buttons on the bottom of the display to switch screens.
|
|
|
|
* https://reactnavigation.org/docs/bottom-tab-navigator
|
|
|
|
*/
|
|
|
|
const BottomTab = createBottomTabNavigator<RootTabParamList>();
|
|
|
|
|
|
|
|
function BottomTabNavigator() {
|
|
|
|
const colorScheme = useColorScheme();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BottomTab.Navigator
|
|
|
|
initialRouteName="Home"
|
|
|
|
screenOptions={{
|
|
|
|
tabBarActiveTintColor: Colors[colorScheme].tint,
|
|
|
|
}}>
|
|
|
|
<BottomTab.Screen
|
|
|
|
name="Home"
|
|
|
|
component={HomeScreen}
|
|
|
|
options={({ navigation }: RootTabScreenProps<'Home'>) => ({
|
|
|
|
title: 'Home',
|
|
|
|
tabBarIcon: ({ color }) => <TabBarIcon name="code" color={color} />,
|
|
|
|
headerRight: () => (
|
|
|
|
<Pressable
|
|
|
|
onPress={() => navigation.navigate('Modal')}
|
|
|
|
style={({ pressed }) => ({
|
|
|
|
opacity: pressed ? 0.5 : 1,
|
|
|
|
})}>
|
|
|
|
<FontAwesome
|
|
|
|
name="info-circle"
|
|
|
|
size={25}
|
|
|
|
color={Colors[colorScheme].text}
|
|
|
|
style={{ marginRight: 15 }}
|
|
|
|
/>
|
|
|
|
</Pressable>
|
|
|
|
),
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
<BottomTab.Screen
|
|
|
|
name="Settings"
|
|
|
|
component={SettingsScreen}
|
|
|
|
options={{
|
|
|
|
title: 'Settings',
|
|
|
|
tabBarIcon: ({ color }) => <TabBarIcon name="code" color={color} />,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<BottomTab.Screen
|
|
|
|
name="Trip"
|
|
|
|
component={TripScreen}
|
|
|
|
options={{
|
|
|
|
title: 'Trip',
|
|
|
|
tabBarIcon: ({ color }) => <TabBarIcon name="code" color={color} />,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</BottomTab.Navigator>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* You can explore the built-in icon families and icons on the web at https://icons.expo.fyi/
|
|
|
|
*/
|
|
|
|
function TabBarIcon(props: {
|
|
|
|
name: React.ComponentProps<typeof FontAwesome>['name'];
|
|
|
|
color: string;
|
|
|
|
}) {
|
|
|
|
return <FontAwesome size={30} style={{ marginBottom: -3 }} {...props} />;
|
|
|
|
}
|