import React from 'react'; import { SafeAreaView, Text, View, TouchableOpacity, Image, TextInput, Keyboard, } from 'react-native'; import { inject, observer } from 'mobx-react'; import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'; import Toast, { DURATION } from 'react-native-easy-toast'; import Icon from 'react-native-vector-icons/dist/MaterialCommunityIcons'; import { observable } from 'mobx'; import { colors } from './src/assets/styles/colors-theme'; import { s, vs, ms } from 'react-native-size-matters'; import DeviceInfo from 'react-native-device-info'; Icon.loadFont(); @inject('appStore') @observer export default class MyTabBar extends React.Component { constructor(props) { super(props); this.store = props.appStore; } langLabelReturn(label) { switch (label) { case 'main': return this.store.text.main; break; case 'myfavourite': return this.store.text.myfavourite; break; case 'ShoppingCart': return this.store.text.shoppingcart; break; case 'shoppingHistory': return this.store.text.shoppingHistory; break; case 'acAndSetting': return this.store.text.acAndSetting; break; } } 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; switch (route.name) { case 'Main': iconName = 'home-outline'; break; case 'BuyHistory': iconName = 'history'; break; case 'ShoppingCart': iconName = 'shopping-outline'; break; case 'Favorite': iconName = 'heart-outline'; break; case 'Profile': iconName = 'account-outline'; break; } const isFocused = state.index === index; const onPress = () => { const event = navigation.emit({ type: 'tabPress', target: route.key, }); if (!isFocused && !event.defaultPrevented) { this.store.catalogueSelected = null; console.log(route.name); if (route.name == 'Profile' && !this.store.logined) { navigation.navigate('Signin'); } else if (route.name == 'Favorite' && !this.store.logined) { navigation.navigate('Signin'); } else if (route.name == 'BuyHistory' && !this.store.logined) { navigation.navigate('Signin'); } else { navigation.navigate(route.name); } } else if (isFocused && route.name == 'Main') { this.store.catalogueSelected = null; } }; const onLongPress = () => { navigation.emit({ type: 'tabLongPress', target: route.key, }); }; return ( {this.langLabelReturn(label)} {label == 'ShoppingCart' ? ( {this.store.shoppingCartList.length} ) : ( )} ); })} ); } }