BottomTabNavigator.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
  2. import * as React from "react";
  3. import TabBarIcon from "../components/TabBarIcon";
  4. import HomeScreen from "../screens/HomeScreen";
  5. import LinksScreen from "../screens/LinksScreen";
  6. const BottomTab = createBottomTabNavigator();
  7. const INITIAL_ROUTE_NAME = "Home";
  8. export default function BottomTabNavigator({ navigation, route }) {
  9. // Set the header title on the parent stack navigator depending on the
  10. // currently active tab. Learn more in the documentation:
  11. // https://reactnavigation.org/docs/en/screen-options-resolution.html
  12. navigation.setOptions({ headerTitle: getHeaderTitle(route) });
  13. return (
  14. <BottomTab.Navigator initialRouteName={INITIAL_ROUTE_NAME}>
  15. <BottomTab.Screen
  16. name='Home'
  17. component={HomeScreen}
  18. options={{
  19. title: "叮咚外卖协助平台用户协作",
  20. tabBarIcon: ({ focused }) => (
  21. <TabBarIcon focused={focused} name='md-code-working' />
  22. ),
  23. }}
  24. />
  25. <BottomTab.Screen
  26. name='Links'
  27. component={LinksScreen}
  28. options={{
  29. title: "叮咚外卖协助平台骑手协作",
  30. tabBarIcon: ({ focused }) => (
  31. <TabBarIcon focused={focused} name='md-book' />
  32. ),
  33. }}
  34. />
  35. </BottomTab.Navigator>
  36. );
  37. }
  38. function getHeaderTitle(route) {
  39. const routeName =
  40. route.state?.routes[route.state.index]?.name ?? INITIAL_ROUTE_NAME;
  41. switch (routeName) {
  42. case "Home":
  43. return "用户下单流程";
  44. case "Links":
  45. return "骑手接单";
  46. }
  47. }