import React, { Component } from "react"; import { Platform, StyleSheet, View, TouchableOpacity, SafeAreaView, ScrollView, Image, Linking, Alert, Share } from "react-native"; import Text from "react-native-text"; import { observable } from "mobx"; import { observer, inject } from "mobx-react/native"; import { scale, verticalScale, moderateScale } from "react-native-size-matters"; import Size from "../../config/size"; import Icon from "react-native-vector-icons/dist/Ionicons"; import Icon2 from "react-native-vector-icons/dist/MaterialCommunityIcons"; import { width, height } from "../../config/screen"; import theme from "../../config/colors"; import { Fonts } from "../../config/fonts"; import DrawerNavigationHeader from "../../components/Public/drawerNavigationHeader"; import PopupDialog, { SlideAnimation } from "react-native-popup-dialog"; import language from "../../config/language"; const size = new Size(); const slideAnimation = new SlideAnimation({ slideFrom: "bottom" }); @inject(["menuStore"], ["userStore"]) @observer export default class SettingInside extends Component { @observable items = [ { icon: require("../../images/settinglang.png"), popup: true, screen: "language", id: 0 }, { icon: require("../../images/settingnotification.png"), screen: "NotificationSetting", popup: true, id: 1 }, { icon: require("../../images/settinghowtouse.png"), popup: true, id: 2 }, { icon: require("../../images/settinglogout.png"), popup: true, id: 3 } ]; @observable lang = false; constructor(props) { super(props); this.store = this.props.menuStore; this.userStore = this.props.userStore; } static navigationOptions = { drawerLabel: "Settings", swipeEnabled: false, tabBarLabel: language.en.setting }; getTitle(id) { switch (id) { case 0: return this.props.userStore.text.language; break; case 1: return this.props.userStore.text.notification; break; case 2: return this.props.userStore.text.howtouse; break; case 3: return this.props.userStore.text.logout; break; } } componentWillMount() { if (this.userStore.languageSelection == "english") { this.lang = false; } else { this.lang = true; } } languageText() { if (this.userStore.languageSelection == "english") { return "English"; } else { return "繁體中文"; } } languageView(id) { if (id == 0) { return ( {this.languageText()} ); } else { return ; } } onPressAction(index) { if (this.items[index].popup) { switch (index) { case 0: this.languagePagePopUp(); break; case 1: Linking.openURL("app-settings:"); break; case 2: this.props.navigation.navigate("Tutorial", { data: "setting" }); break; case 3: this.logoutAlert(); break; } } else { console.log(this.items[index].screen); this.props.navigation.navigate(this.items[index].screen); } } logoutAlert() { Alert.alert( "Logout", "Are you sure to Logout?", [ { text: "Cancel", onPress: () => console.log("Cancel Pressed"), style: "cancel" }, { text: "Sure", onPress: () => this.logoutAction() } ], { cancelable: false } ); } referYourFriender() { Share.share({ message: "Hello,Come to join Hangry, this is my refer code: ", title: "Hangry no more" }); } logoutAction() { this.userStore.logoutPost(this, false); } navigatieAction(page) { this.props.navigation.navigate(page); } renderItems() { return this.items.map((item, index, array) => { if (item.id == 3 && !this.userStore.logined) { return null; } else { if (item.id == 1 && Platform.OS !== 'ios') { return null; }else{ return ( this.onPressAction(index)} > {this.getTitle(item.id)} {this.languageView(item.id)} ); } } }); } languagePagePopUp() { this.popupDialog.show(); } languagePageDismiss() { this.popupDialog.dismiss(); } updateUser() { if (this.lang) { this.userStore.saveLanguage("chinese"); this.popupDialog.dismiss(); } else { this.userStore.saveLanguage("english"); this.popupDialog.dismiss(); } } languagePageDismissedCallBack() { console.log("dismiss dialog"); if (this.userStore.languageSelection == "english") { this.lang = false; } else { this.lang = true; } } selectIcon(lang) { if (!lang) { if (!this.lang) { return ( ); } else { return ( ); } } else { if (!this.lang) { return ( ); } else { return ( ); } } } render() { return ( this.props.navigation.goBack()} /> {this.renderItems()} {"Ver 4.4 28 - 3 - 2019"} { this.popupDialog = popupDialog; }} dialogAnimation={slideAnimation} height={height / 4} width={width - scale(60)} onDismissed={() => this.languagePageDismissedCallBack()} > {this.userStore.text.slectLang} (this.lang = false)} > English {this.selectIcon(false)} (this.lang = true)} > 繁體中文 {this.selectIcon(true)} this.updateUser()} style={{ backgroundColor: theme.mainColor, flex: 1, justifyContent: "center", alignItems: "center" }} > OK ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: theme.mainColor } });