import React from 'react'; import { SafeAreaView, Text, View, TouchableOpacity, Image, TextInput, Keyboard, } from 'react-native'; import { inject, observer } from 'mobx-react'; import Icon from 'react-native-vector-icons/dist/MaterialCommunityIcons'; import { observable } from 'mobx'; import { colors } from './src/assets/styles/colors-theme'; import { images } from './src/assets/images/index'; Icon.loadFont(); const MyTabBar = inject("appStore")(observer(class MyTabBar extends React.Component { constructor(props) { super(props); this.store = props.appStore; } render() { var { state, descriptors, navigation, logined } = this.props; return ( {state.routes.map((route, index) => { const { options } = descriptors[route.key]; const label = options.tabBarLabel !== undefined ? options.tabBarLabel : options.title !== undefined ? options.title : route.name; let iconName; let focus switch (route.name) { case 'Main': iconName = 'home'; focus = 'home'; break; case 'Category': iconName = images.ICON_LIST; focus = images.ICON_LIST_FOCUS; break; // case 'Favourite': // iconName = images.NAV_FAV; // focus = images.NAV_FAV_FOCUS; // break; case 'Cart': iconName = images.NAV_CART; focus = images.NAV_CART_FOCUS; break; case 'Setting': iconName = images.NAV_PROFILE; focus = images.NAV_PROFILE_FOCUS; break; } const isFocused = state.index === index; const onPress = () => { const event = navigation.emit({ type: 'tabPress', target: route.key, }); if (!isFocused && !event.defaultPrevented) { console.log(route.name); if (route.name == 'Setting' && !this.store.logined) { navigation.navigate('Login'); } else { navigation.navigate(route.name); } } }; const onLongPress = () => { navigation.emit({ type: 'tabLongPress', target: route.key, }); }; return ( {route.name == 'Main' ? () : ()} {label == 'Cart' ? ( {this.store.shoppingCart.length} ) : ( )} ); })} ); } })) export default MyTabBar