RootView.js 3.17 KB
Newer Older
Giang Tran committed
1
import React, {useEffect, useRef} from 'react';
Giang Tran committed
2
import {View} from 'react-native';
Giang Tran committed
3 4 5 6 7

import {connect} from 'react-redux';
import StackNavigation from './routers/StackNavigation';
import Modal from 'react-native-modal';
import {SkypeIndicator} from 'react-native-indicators';
Giang Tran committed
8
import {enableScreens} from 'react-native-screens';
Giang Tran committed
9
import NoInternetComponent from './components/NoInternet';
Giang Tran committed
10
import DropdownAlert from 'react-native-dropdownalert';
Nguyễn Thị Thúy committed
11
import DeviceInfo from 'react-native-device-info';
Giang Tran committed
12 13 14
import R from './assets/R';
import {WIDTHXD, HEIGHTXD} from './Config/Functions';
import DropdownManager from './components/DropdownAlert/DropdownManager';
15 16 17 18 19
import AsyncStorage from '@react-native-community/async-storage';
import KEY from './assets/AsynStorage';
import I18n, {setLocation} from './helper/i18/i18n';
import {changeLanguage} from './actions/language';

Giang Tran committed
20
enableScreens();
Giang Tran committed
21

Giang Tran committed
22
const RootView = (props) => {
Giang Tran committed
23 24 25 26
  useEffect(() => {
    DropdownManager.register(
      dropDownAlertRef.current,
      dropDownAlertLongTimeRef.current,
27
    );
Giang Tran committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    setInitLanguage();
  }, []);

  const dropDownAlertRef = useRef(null);
  const dropDownAlertLongTimeRef = useRef(null);
  const setInitLanguage = async () => {
    const laguage = await AsyncStorage.getItem(KEY.LANGUAGE);
    if (laguage) props.changeLanguage(laguage);
    setLocation(I18n, laguage);
  };
  return (
    <>
      <View style={{flex: 1}}>
        <Modal isVisible={props.loadingModal.isVisible}>
          <SkypeIndicator color={'white'} />
        </Modal>
        <StackNavigation />
      </View>
      <DropdownAlert
        inactiveStatusBarBackgroundColor={R.colors.main}
        activeStatusBarBackgroundColor={R.colors.main}
        warnImageSrc={R.images.iconWarn}
        successImageSrc={R.images.iconSuccess}
        errorImageSrc={R.images.iconError}
        titleStyle={{color: '#fff'}}
        messageStyle={{color: '#fff'}}
        updateStatusBar={false}
        closeInterval={1000}
        ref={dropDownAlertRef}
        warnColor={R.colors.orange400}
        defaultContainer={{
          borderBottomRightRadius: WIDTHXD(30),
          borderBottomLeftRadius: WIDTHXD(30),
          paddingTop: HEIGHTXD(30),
          paddingVertical: HEIGHTXD(30),
          paddingHorizontal: WIDTHXD(20),
        }}
      />
      <DropdownAlert
        updateStatusBar={false}
        inactiveStatusBarBackgroundColor={R.colors.colorMain}
        activeStatusBarBackgroundColor={R.colors.colorMain}
        warnImageSrc={R.images.iconWarn}
        successImageSrc={R.images.iconSuccess}
        errorImageSrc={R.images.iconError}
        titleStyle={{color: '#fff'}}
        messageStyle={{color: '#fff'}}
        closeInterval={600000}
        ref={dropDownAlertLongTimeRef}
        warnColor={R.colors.orange400}
        defaultContainer={{
          borderBottomRightRadius: WIDTHXD(30),
          borderBottomLeftRadius: WIDTHXD(30),
          paddingTop: HEIGHTXD(30),
          paddingVertical: HEIGHTXD(30),
          paddingHorizontal: WIDTHXD(20),
        }}
      />
      <NoInternetComponent />
    </>
  );
Giang Tran committed
89 90 91
};

const mapStateToProps = (state) => {
Giang Tran committed
92 93 94
  return {
    loadingModal: state.ModalLoadingReducer,
  };
Giang Tran committed
95 96
};

Nguyễn Thị Thúy committed
97
export default connect(mapStateToProps, {})(RootView);