Advertisement
Guest User

tabNav

a guest
Apr 25th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Button, Footer, FooterTab, Icon } from "native-base";
  2. import React from "react";
  3. import { Platform, Image, StyleSheet, Text } from "react-native";
  4. import { createAppContainer, createBottomTabNavigator } from "react-navigation";
  5. import Account from "../../../screen/Container/Account";
  6. import Inbox from "../../../screen/Container/Inbox";
  7. import Order from "../../../screen/Container/Order";
  8. import globalStyles, { colors } from "../../styles/global";
  9. import Home from "../../../screen/Container/Home";
  10. import { store } from "../../../store";
  11. import { isEdit } from "../../../actions/user";
  12. import { setCurrentTab } from "../../../actions/navigation";
  13.  
  14. const styles = StyleSheet.create({
  15.   btnTab: {
  16.     justifyContent: "center",
  17.     alignItems: "center",
  18.     backgroundColor: "white",
  19.     paddingTop: 15,
  20.     height: "100%"
  21.   },
  22.   titleTab: {
  23.     paddingBottom: 10,
  24.     fontSize: 14
  25.   }
  26. });
  27.  
  28. const MainScreenNavigator = createBottomTabNavigator(
  29.   {
  30.     Home: {
  31.       screen: Home
  32.     },
  33.     Order: {
  34.       screen: Order
  35.     },
  36.     Inbox: {
  37.       screen: Inbox
  38.     },
  39.     Account: {
  40.       screen: Account,
  41.       navigationOptions: {
  42.         header: null
  43.       }
  44.     }
  45.   },
  46.   {
  47.     tabBarPosition: "bottom",
  48.     tabBarComponent: props => {
  49.       let navigateTab = (routeName, index) => {
  50.         props.navigation.navigate(routeName);
  51.         store.dispatch(setCurrentTab(routeName));
  52.  
  53.         routeName !== "Account" ? store.dispatch(isEdit(false)) : null;
  54.       };
  55.       let index = props.navigation.state.index;
  56.       return (
  57.         <Footer
  58.           style={{
  59.             backgroundColor: "white",
  60.             borderTopColor: "#f4f4f4",
  61.             borderTopWidth: 0.8
  62.           }}
  63.         >
  64.           <FooterTab
  65.             style={{
  66.               backgroundColor: "white"
  67.             }}
  68.           >
  69.             <Button
  70.               vertical
  71.               style={styles.btnTab}
  72.               transparent
  73.               active={index === 0}
  74.               onPress={() => navigateTab("Home", index)}
  75.             >
  76.               {index === 0 ? (
  77.                 <Image
  78.                   source={require("../../img/icon/ic_home/ic_home_active.png")}
  79.                 />
  80.               ) : (
  81.                 <Image source={require("../../img/icon/ic_home/ic_home.png")} />
  82.               )}
  83.               <Text
  84.                 style={[
  85.                   globalStyles.font,
  86.                   styles.titleTab,
  87.                   {
  88.                     color: index === 0 ? "#2a48b2" : "#c4c4c4"
  89.                   }
  90.                 ]}
  91.               >
  92.                 Home
  93.               </Text>
  94.             </Button>
  95.             <Button
  96.               vertical
  97.               style={styles.btnTab}
  98.               transparent
  99.               active={index === 1}
  100.               onPress={() => navigateTab("Order", index)}
  101.             >
  102.               {index === 1 ? (
  103.                 <Image
  104.                   source={require("../../img/icon/ic_pesanan/ic_pesanan_active.png")}
  105.                 />
  106.               ) : (
  107.                 <Image
  108.                   source={require("../../img/icon/ic_pesanan/ic_pesanan.png")}
  109.                 />
  110.               )}
  111.               <Text
  112.                 style={[
  113.                   globalStyles.font,
  114.                   styles.titleTab,
  115.                   {
  116.                     color: index === 1 ? "#2a48b2" : "#c4c4c4"
  117.                   }
  118.                 ]}
  119.               >
  120.                 Order
  121.               </Text>
  122.             </Button>
  123.             <Button
  124.               vertical
  125.               style={styles.btnTab}
  126.               transparent
  127.               active={index === 2}
  128.               onPress={() => navigateTab("Inbox", index)}
  129.             >
  130.               {index === 2 ? (
  131.                 <Image
  132.                   source={require("../../img/icon/ic_inbox/ic_inbox_active.png")}
  133.                 />
  134.               ) : (
  135.                 <Image
  136.                   source={require("../../img/icon/ic_inbox/ic_inbox.png")}
  137.                 />
  138.               )}
  139.               <Text
  140.                 style={[
  141.                   globalStyles.font,
  142.                   styles.titleTab,
  143.                   {
  144.                     marginTop: 5,
  145.                     color: index === 2 ? "#2a48b2" : "#c4c4c4"
  146.                   }
  147.                 ]}
  148.               >
  149.                 Inbox
  150.               </Text>
  151.             </Button>
  152.             <Button
  153.               vertical
  154.               style={styles.btnTab}
  155.               transparent
  156.               active={index === 3}
  157.               onPress={() => navigateTab("Account", index)}
  158.             >
  159.               {index === 3 ? (
  160.                 <Image
  161.                   source={require("../../img/icon/ic_account/ic_Account_active.png")}
  162.                 />
  163.               ) : (
  164.                 <Image
  165.                   source={require("../../img/icon/ic_account/ic_Account.png")}
  166.                 />
  167.               )}
  168.               <Text
  169.                 style={[
  170.                   globalStyles.font,
  171.                   styles.titleTab,
  172.                   {
  173.                     color: index === 3 ? "#2a48b2" : "#c4c4c4"
  174.                   }
  175.                 ]}
  176.               >
  177.                 Account
  178.               </Text>
  179.             </Button>
  180.           </FooterTab>
  181.         </Footer>
  182.       );
  183.     },
  184.     tabBarOptions: {
  185.       activeTintColor: colors.WHITE,
  186.       activeBackgroundColor: colors.DARK_BLUE,
  187.       iconStyle: { flex: 1, width: 15, height: 15, padding: 0 },
  188.       // labelStyle: { fontSize: 10, paddingHorizontal: 0 },
  189.       style: {
  190.         backgroundColor:
  191.           Platform.OS === "ios" ? colors.DARK_BLUE : colors.DARK_BLUE,
  192.         marginBottom: Platform.OS == "android" ? -10 : 0,
  193.         // height: Metrics.screenHeight * 0.1,
  194.         borderTopColor: "#fafafa"
  195.         // flex: 1,
  196.       },
  197.       indicatorStyle: {
  198.         flex: 1,
  199.         backgroundColor: colors.DARK_BLUE
  200.       },
  201.       tabStyle: {
  202.         flex: 1,
  203.         backgroundColor: Platform.OS == "android" ? colors.DARK_BLUE : null
  204.       },
  205.       labelStyle: {
  206.         fontSize: 10
  207.       }
  208.     }
  209.   }
  210. );
  211.  
  212. const Tab = createAppContainer(MainScreenNavigator);
  213.  
  214. export default Tab;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement