Created
January 6, 2020 15:09
-
-
Save darksh3ll/f603b4e75136ab9461dada441a70d30e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component, 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 StatusConnexion extends Component { | |
state = { | |
isConnected: null | |
}; | |
handleConnectivityChange = isConnected => { | |
this.setState({ isConnected }); | |
}; | |
componentDidMount() { | |
NetInfo.isConnected.addEventListener('connectionChange', this.handleConnectivityChange); | |
} | |
componentWillUnmount() { | |
NetInfo.isConnected.removeEventListener('connectionChange', this.handleConnectivityChange); | |
} | |
render() { | |
return ( | |
!this.state.isConnected?<MiniOfflineSign />: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 StatusConnexion; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment