-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOfflineNotice.js
65 lines (54 loc) · 1.5 KB
/
OfflineNotice.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
import React, { PureComponent } from 'react';
import { View, Text, Dimensions, StyleSheet } from 'react-native';
import NetInfo from "@react-native-community/netinfo";
const { width } = Dimensions.get('window');
function MiniOfflineSign() {
return (
<View style={styles.offlineContainer}>
<Text style={styles.offlineText}>No Internet Connection</Text>
</View>
);
}
class OfflineNotice extends PureComponent {
state = {
isConnected: true
};
// componentDidMount() {
// // NetInfo.isConnected.addEventListener('connectionChange', this.handleConnectivityChange);
// // NetInfo.addEventListener(state => {
// // console.log("Connection type", state.type);
// // console.log("Is connected?", state.isConnected);
// // });
// }
// componentWillUnmount() {
// NetInfo.isConnected.removeEventListener('connectionChange', this.handleConnectivityChange);
// }
handleConnectivityChange = isConnected => {
console.log(this.state);
if (isConnected) {
this.setState({ isConnected });
} else {
this.setState({ isConnected });
}
};
render() {
if (!this.state.isConnected) {
return <MiniOfflineSign />;
}
return null;
}
}
const styles = StyleSheet.create({
offlineContainer: {
backgroundColor: '#b52424',
height: 30,
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
width,
position: 'absolute',
top: 30
},
offlineText: { color: '#fff' }
});
export default OfflineNotice;