TabsNavigator.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import 'react-native-gesture-handler';
  2. import React, {useLayoutEffect} from 'react';
  3. import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
  4. import { createStackNavigator } from '@react-navigation/stack';
  5. import { DefaultTheme } from 'react-native-paper'
  6. import Map from '../screens/Map'
  7. import { MapProvider } from '../contexts/MapContext';
  8. import Icon from 'react-native-vector-icons/FontAwesome';
  9. import Account from '../screens/Account';
  10. import LandmarkForm from '../screens/LandmarkForm';
  11. import { getFocusedRouteNameFromRoute } from '@react-navigation/native';
  12. // unused method for displaying tabbar based on screen shown
  13. // const shouldTabBarDisplay = (route) => {
  14. // const routeName = getFocusedRouteNameFromRoute(route);
  15. // console.log(routeName)
  16. // if (routeName == "LandmarkForm") {
  17. // return false;
  18. // }
  19. // return true;
  20. // }
  21. const Tabs = createBottomTabNavigator();
  22. const MapStack = createStackNavigator();
  23. const AccountStack = createStackNavigator();
  24. const theme = {
  25. ...DefaultTheme,
  26. colors: {
  27. primary: '#df3f3f',
  28. accent: 'white',
  29. },
  30. }
  31. const MapStackNavigator = ({navigation, route}) => {
  32. // useLayoutEffect(() => {
  33. // const tabBarShouldDisplay = shouldTabBarDisplay(route);
  34. // if (state.tabBarVisible != tabBarShouldDisplay) {
  35. // dispatch({type: "CHANGE_TABBAR_VISIBILITY", payload: tabBarShouldDisplay})
  36. // }
  37. // }, [navigation, route]);
  38. return(
  39. <MapStack.Navigator screenOptions={{headerTransparent: true}} screenOptions={{headerTransparent: true, headerTitle: ""}}>
  40. <MapStack.Screen name="Map" component={Map} />
  41. <MapStack.Screen name="LandmarkForm" component={LandmarkForm} />
  42. </MapStack.Navigator>
  43. )
  44. }
  45. const AccountStackNavigator = () => {
  46. return(
  47. <MapStack.Navigator screenOptions={{headerTransparent: true}} screenOptions={{headerTransparent: true, headerTitle: ""}}>
  48. <MapStack.Screen name="AccountSummary" component={Account} />
  49. </MapStack.Navigator>
  50. )
  51. }
  52. const TabsNavigator = ({route}) => {
  53. return(
  54. <Tabs.Navigator
  55. initialRouteName="Map"
  56. tabBarOptions={{
  57. keyboardHidesTabBar: true,
  58. tabBarLabel: 'Test',
  59. activeTintColor: "white",
  60. inactiveTintColor: "lightgrey",
  61. style: {paddingBottom: 5, backgroundColor: "#df3f3f"}
  62. }}>
  63. <Tabs.Screen
  64. name="Map"
  65. component={MapStackNavigator}
  66. options={{
  67. tabBarIcon: ({color}) => (<Icon name="map" size={15} color={color}/>),
  68. }} />
  69. <Tabs.Screen
  70. name="Account"
  71. component={AccountStackNavigator}
  72. options={{
  73. tabBarIcon: ({color}) => (<Icon name="user" size={15} color={color}/>),
  74. }} />
  75. </Tabs.Navigator>
  76. )
  77. }
  78. export default TabsNavigator;