-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (60 loc) · 1.53 KB
/
index.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
import {AppRegistry} from 'react-native';
import React, {Component} from 'react';
import {name as appName} from './app.json';
import NetInfo from '@react-native-community/netinfo';
import SplashScreen from 'react-native-splash-screen';
//The No Internet component
import NoInternet from './chapters/NoInternet';
//Here we import the different chapters of the app
import Intro from './chapters/Intro';
import NoPermissions from './chapters/NoPermissions';
class Main extends Component {
constructor() {
super();
this.state = {
chapter: 0,
hasInternetConnection: false,
};
}
componentDidMount() {
NetInfo.addEventListener(state => {
this.state.hasInternetConnection = state.isInternetReachable;
this.setState(this.state);
});
//Hide the splashscreen
SplashScreen.hide();
}
advanceState() {
this.state.chapter++;
this.setState(this.state);
}
render() {
let component;
if (this.state.hasInternetConnection) {
switch (this.state.chapter) {
case 0:
component = (
<Intro
advanceState={() => {
this.advanceState();
}}
/>
);
break;
case 1:
component = (
<NoPermissions
advanceState={() => {
this.advanceState();
}}
/>
);
break;
}
} else {
component = <NoInternet />;
}
return component;
}
}
AppRegistry.registerComponent(appName, () => Main);