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

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
10
import {enableScreens} from 'react-native-screens';
Giang Tran committed
11
import NoInternetComponent from './components/NoInternet';
Giang Tran committed
12
import DropdownAlert from 'react-native-dropdownalert';
Nguyễn Thị Thúy committed
13
import DeviceInfo from 'react-native-device-info';
Giang Tran committed
14 15 16
import R from './assets/R';
import {WIDTHXD, HEIGHTXD} from './Config/Functions';
import DropdownManager from './components/DropdownAlert/DropdownManager';
17 18 19 20 21
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
22

Giang Tran committed
23
enableScreens();
Giang Tran committed
24

Giang Tran committed
25
const RootView = (props) => {
26 27 28 29 30
    useEffect(() => {
        DropdownManager.register(
            dropDownAlertRef.current,
            dropDownAlertLongTimeRef.current,
        );
31
        setInitLanguage()
32
    }, []);
Giang Tran committed
33

34 35
    const dropDownAlertRef = useRef(null);
    const dropDownAlertLongTimeRef = useRef(null);
36 37 38 39 40
    const setInitLanguage = async () => {
        const laguage = await AsyncStorage.getItem(KEY.LANGUAGE);
        if (laguage) props.changeLanguage(laguage);
        setLocation(I18n, laguage);
    };
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 89
    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'}}
                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
                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
90 91 92
};

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

98
export default connect(mapStateToProps, {changeLanguage})(RootView);