-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
62 lines (53 loc) · 1.78 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
import 'react-native-gesture-handler';
import React, {useEffect, useState} from 'react';
import {useTranslation} from 'react-i18next';
import {I18nManager} from 'react-native';
import RNRestart from 'react-native-restart';
import RNBootSplash from 'react-native-bootsplash';
//Context
import StateContext from './app/StateContext';
import DispatchContext from './app/DispatchContext';
//Components and utils
import cache from './app/utils/cache';
import BaseNavigation from './app/navigation/BaseNavigation';
import useRoleManager from './app/utils/useRoleManager';
import './app/services/i18n';
export default function App(props) {
const {i18n, ready} = useTranslation();
const {state, dispatch} = useRoleManager();
const [cachedRoles, setCachedRoles] = useState('');
const getCache = async () => {
setCachedRoles(await cache.get('roles'));
};
useEffect(() => {
getCache();
}, []);
useEffect(() => {
if (ready) {
if (i18n.language === 'fa' && !I18nManager.isRTL) {
I18nManager.forceRTL(true);
RNRestart.Restart();
}
if (i18n.language !== 'fa' && I18nManager.isRTL) {
I18nManager.forceRTL(false);
RNRestart.Restart();
}
}
}, [ready]);
useEffect(() => {
if (cachedRoles != '') {
dispatch({type: 'initialize', roles: cachedRoles});
}
RNBootSplash.hide({fade: true});
}, [cachedRoles]);
useEffect(() => {
cache.store('roles', state.roles); //Store changes to asyncStorage
}, [state.roles]);
return (
<StateContext.Provider value={state}>
<DispatchContext.Provider value={dispatch}>
{ready && <BaseNavigation /> /*Force not render until i18n is ready, cannot use suspence because makes entire app suspended*/}
</DispatchContext.Provider>
</StateContext.Provider>
);
}