-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
109 lines (97 loc) · 3.34 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React, {Component} from 'react';
import { Platform, StatusBar, AsyncStorage, ImageBackground, Dimensions, NetInfo, Modal} from 'react-native';
import { Container, Root, Text } from 'native-base';
import SplashScreen from 'react-native-splash-screen'
import Spinner from 'react-native-loading-spinner-overlay'
import { setCustomText } from 'react-native-global-props';
import { SwitchNavigation } from './core/Router'
import FirebaseListener from './core/FirebaseListener'
import NavigationService from './core/NavigationService'
import { MenuProvider } from 'react-native-popup-menu';
import BottomTabs from './components/BottomTabs'
import Logo from './assets/images/logo.png'
var { width, height } = Dimensions.get('window')
let Leyout = {}
global.isLogged = false
const customTextProps = {
style: {
fontFamily:'OpenSans-Regular'
}
}
class App extends React.Component{
constructor(props){
super(props)
this.state = {
isDisconnected: false,
isMount:false,
}
AsyncStorage.getItem('logged').then((value) => {
console.log(value);
if (value) {
Leyout = SwitchNavigation(value)
if (value == 'logged') {
global.isLogged = false
}else {
global.isLogged = true
}
this.setState({isMount:true},()=>console.log('2'))
}else {
Leyout = SwitchNavigation('login')
this.setState({isMount:true},()=>console.log('3'))
}
})
AsyncStorage.getItem('userData').then((value)=>{
if (value) {
if (JSON.parse(value).user.type == 'employee') {
global.userType = 'employee'
global.permissions = JSON.parse(value).user.roles.clientrole.permissions
}else {
global.userType = 'user'
global.permissions = []
}
}
})
setCustomText(customTextProps);
global.tab='home'
}
componentDidMount(){
// AsyncStorage.clear();
this.handleConnectionChange()
NetInfo.isConnected.addEventListener('connectionChange', this.handleConnectionChange)
setTimeout(() => SplashScreen.hide(), 2000)
}
componentWillUnmount() {
NetInfo.isConnected.removeEventListener('connectionChange', this.handleConnectionChange)
}
handleConnectionChange = (isConnected) => {
if (!isConnected && isConnected != undefined) {
return this.setState({ isDisconnected: true});
}else {
return this.setState({ isDisconnected: false});
}
}
render() {
if (this.state.isMount != true) {
return (
<Container style={{backgroundColor:'#fff'}}>
<StatusBar backgroundColor="#fff" barStyle="dark-content" />
{/* <ImageBackground source={Logo} style={{width:width, height:height, resizeMode:'cover'}}/> */}
</Container>
)
}else {
return (
<Root>
<FirebaseListener />
<Modal animationType="slide" transparent={true} visible={this.state.isDisconnected} onRequestClose={()=>{}}>
<Text style={{textAlign:'center',paddingTop:15,paddingBottom:10, backgroundColor: '#b52424',color:'#fff'}}>No Internet Connection</Text>
</Modal>
<MenuProvider>
<Leyout ref={navigatorRef => { NavigationService.setTopLevelNavigator(navigatorRef)}}/>
{/* {global.isLogged? <BottomTabs /> :null} */}
</MenuProvider>
</Root>
)
}
}
}
export default App;