-
Notifications
You must be signed in to change notification settings - Fork 17
/
splashScreen.js
58 lines (56 loc) · 1.28 KB
/
splashScreen.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
import React, {Component} from 'react';
import {StyleSheet, View, ActivityIndicator, BackHandler} from 'react-native';
import NetInfo from '@react-native-community/netinfo';
import Settings from '../../settings';
import BaseScreen from './baseScreen';
export default class SplashScreen extends BaseScreen {
constructor(props) {
super(props);
this.style = getStyleSheet(global.css);
}
redirect() {
NetInfo.fetch().then((state) => {
if(state.isConnected) {
Settings.getSession().then((session) => {
if(session) {
this.goTo('Main');
} else {
this.goTo('SignIn');
}
});
} else {
this.goTo('NoConnection');
}
});
}
// functions below overrides base functions
onBackPress() {
BackHandler.exitApp();
}
componentDidMount() {
// use super to call the base function
// super.componentDidMount();
this.redirect();
}
componentDidUpdate() {
this.redirect();
}
render() {
return (
<View style={this.style.container}>
<ActivityIndicator size='large' color={global.css.bodyIconColorInverted}/>
</View>
);
}
}
function getStyleSheet(props) {
return StyleSheet.create({
container: {
backgroundColor: props.bodyBackgroundColorInverted,
alignItems: 'center',
justifyContent: 'center',
flex: 1,
padding: 10
}
});
}