SettingView.js 2.52 KB
Newer Older
Giang Tran committed
1
import React, {useEffect, useState} from 'react';
Giang Tran committed
2
import {View, Text, Switch, StyleSheet} from 'react-native';
3
import HeaderBack from '../../components/Header/HeaderBack';
Giang Tran committed
4 5
import {getFontXD} from '../../Config/Functions';
import PickerItem from '../../components/Picker/PickerItem';
Giang Tran committed
6 7 8 9 10
import AppText from '../../components/AppText';
import {changeLanguage} from '../../actions/language';
import {connect} from 'react-redux';
import AsyncStorage from '@react-native-community/async-storage';
import KEY from '../../assets/AsynStorage';
11
import I18n, {setLocation} from '../../helper/i18/i18n';
Giang Tran committed
12
const dataLanguage = [
Giang Tran committed
13
  {
Giang Tran committed
14
    value: 'vi',
Giang Tran committed
15 16 17
    name: 'Vietnamese',
  },
  {
Giang Tran committed
18
    value: 'en',
Giang Tran committed
19 20 21
    name: 'English',
  },
];
Giang Tran committed
22 23

const SettingView = (props) => {
Giang Tran committed
24
  const [isEnabled, setIsEnabled] = useState(true);
25
  const toggleSwitch = () => setIsEnabled((previousState) => !previousState);
Giang Tran committed
26 27 28 29 30 31 32 33 34 35
  const [language, setLanguage] = useState();
  useEffect(() => {
    convertLanguage();
  }, []);

  const convertLanguage = () => {
    const temp = dataLanguage.filter((e) => e.value == props.language.language);
    setLanguage(temp[0].name);
  };

Giang Tran committed
36
  return (
37
    <View style={{flex: 1}}>
Giang Tran committed
38
      <HeaderBack title={'Setting'} />
Giang Tran committed
39
      <View style={{flex: 1, padding: 10}}>
Giang Tran committed
40
        {/* <View style={styles.row}>
Giang Tran committed
41 42 43 44 45 46 47 48
          <Text style={styles.txtTitle}>Bật thông báo</Text>
          <Switch
            trackColor={{false: '#DBDBDB', true: '#1C6AF6'}}
            ios_backgroundColor="#767577"
            thumbColor={'#f4f3f4'}
            onValueChange={toggleSwitch}
            value={isEnabled}
          />
Giang Tran committed
49
        </View> */}
Giang Tran committed
50

Giang Tran committed
51
        <View style={styles.row}>
Giang Tran committed
52
          <AppText i18nKey={'Language'} style={styles.txtTitle} />
Giang Tran committed
53 54
          <PickerItem
            width={200}
Giang Tran committed
55
            defaultValue={language}
Giang Tran committed
56
            value={language}
Giang Tran committed
57
            data={dataLanguage}
Giang Tran committed
58
            onValueChange={(value, items) => {
Giang Tran committed
59
              setLanguage(items.name);
Giang Tran committed
60 61
              props.changeLanguage(items.value);
              AsyncStorage.setItem(KEY.LANGUAGE, items.value);
62
              setLocation(I18n, items.value)
Giang Tran committed
63 64 65 66
            }}
          />
        </View>
      </View>
Giang Tran committed
67 68 69 70
    </View>
  );
};

Giang Tran committed
71 72 73 74 75 76 77 78 79 80 81 82 83
const styles = StyleSheet.create({
  txtTitle: {
    fontSize: getFontXD(46),
    color: '#001C51',
  },

  row: {
    flexDirection: 'row',
    justifyContent: 'space-between',
    alignItems: 'center',
    marginBottom: 20,
  },
});
Giang Tran committed
84 85 86 87 88 89 90 91

const mapStateToProps = (state) => {
  return {
    language: state.languageReducer,
  };
};

export default connect(mapStateToProps, {changeLanguage})(SettingView);