TabsNavigator.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 { MockProvider, useMockState } from '../contexts/MockContext';
  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. const {dispatch, state} = useMockState();
  33. // useLayoutEffect(() => {
  34. // const tabBarShouldDisplay = shouldTabBarDisplay(route);
  35. // if (state.tabBarVisible != tabBarShouldDisplay) {
  36. // dispatch({type: "CHANGE_TABBAR_VISIBILITY", payload: tabBarShouldDisplay})
  37. // }
  38. // }, [navigation, route]);
  39. return(
  40. <MapStack.Navigator screenOptions={{headerTransparent: true}} screenOptions={{headerTransparent: true, headerTitle: ""}}>
  41. <MapStack.Screen name="Map" component={Map} />
  42. <MapStack.Screen name="LandmarkForm" component={LandmarkForm} />
  43. </MapStack.Navigator>
  44. )
  45. }
  46. const AccountStackNavigator = () => {
  47. return(
  48. <MapStack.Navigator screenOptions={{headerTransparent: true}} screenOptions={{headerTransparent: true, headerTitle: ""}}>
  49. <MapStack.Screen name="AccountSummary" component={Account} />
  50. </MapStack.Navigator>
  51. )
  52. }
  53. const TabsNavigator = ({route}) => {
  54. const {state} = useMockState();
  55. return(
  56. <Tabs.Navigator
  57. initialRouteName="Map"
  58. tabBarOptions={{
  59. keyboardHidesTabBar: true,
  60. tabBarLabel: 'Test',
  61. activeTintColor: "white",
  62. inactiveTintColor: "lightgrey",
  63. style: {paddingBottom: 5, backgroundColor: "#df3f3f"}
  64. }}>
  65. <Tabs.Screen
  66. name="Map"
  67. component={MapStackNavigator}
  68. options={{
  69. tabBarIcon: ({color}) => (<Icon name="map" size={15} color={color}/>),
  70. }} />
  71. <Tabs.Screen
  72. name="Account"
  73. component={AccountStackNavigator}
  74. options={{
  75. tabBarIcon: ({color}) => (<Icon name="user" size={15} color={color}/>),
  76. }} />
  77. </Tabs.Navigator>
  78. )
  79. }
  80. export default TabsNavigator;