-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
54 lines (47 loc) · 1002 Bytes
/
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
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import Rout from './Route'
import NetInfo from "@react-native-community/netinfo";
export default class App extends Component {
constructor(props) {
super(props)
this.state = {
isOnline: true
}
}
componentDidMount = async () => {
// Get Init state of net
NetInfo.fetch().then(state => {
if (state.isConnected) {
this.setState({
isOnline: true
})
}
else {
this.setState({
isOnline: false
})
}
})
// When net-info change status
NetInfo.addEventListener(state => {
if (state.isConnected) {
this.setState({
isOnline: true
})
}
else {
this.setState({
isOnline: false
})
}
})
}
render() {
return (
<Rout
screenProps={{ isOnline: this.state.isOnline }}
/>
);
}
}