Last active
December 1, 2022 07:50
-
-
Save Chiamaka/c28010389c830ac675643c7291c3a7df 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, { PureComponent } from 'react'; | |
import { View, Text, NetInfo, Dimensions, StyleSheet } from 'react-native'; | |
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); | |
} | |
componentWillUnmount() { | |
NetInfo.isConnected.removeEventListener('connectionChange', this.handleConnectivityChange); | |
} | |
handleConnectivityChange = isConnected => { | |
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tried to make this work in Expo App with typescript.
Think it works now (2022-11).Got a fork.