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'; Icon.loadFont(); const MyTabBar = inject("appStore")(observer(class MyTabBar extends React.Component { constructor(props) { super(props); this.store = props.appStore; } langLabelReturn() { switch (this.props.label) { case 'home': return this.store.text.home break; case 'info': return this.store.text.rentTools break; case 'history': return this.store.text.history break; case 'profile': return this.store.text.profile break; } } langLabelReturn(label) { switch (label) { case 'main': return this.store.text.main break; case 'myfavourite': return this.store.text.myfavourite 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 = 'storefront'; break; case 'BuyHistory': iconName = 'cart'; break; case 'Favorite': iconName = 'heart'; break; case 'Profile': iconName = 'account-circle'; 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 == '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); } } }; const onLongPress = () => { navigation.emit({ type: 'tabLongPress', target: route.key, }); }; return ( {this.langLabelReturn(label)} ); })} ); } })) export default MyTabBar