Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default function connectionAwareActivity(WrappedComponent) {
- return class extends PureComponent {
- constructor(props) {
- super(props);
- this.state = { isConnected: false };
- this.switchConnectivity = this.switchConnectivity.bind(this);
- }
- static navigationOptions = WrappedComponent.navigationOptions
- componentDidMount() {
- NetInfo.addEventListener('connectionChange', this.switchConnectivity);
- NetInfo.isConnected.fetch().then(isConnected => {
- this.setState({ isConnected });
- });
- }
- componentWillUnmount(){
- NetInfo.removeEventListener('connectionChange', this.switchConnectivity);
- }
- switchConnectivity(type) {
- if(type === 'none'){
- this.setState({isConnected: false})
- }
- else{
- this.setState({isConnected: true})
- }
- }
- render() {
- return this.state.isConnected ? (
- <WrappedComponent {...this.props} />
- ) : (
- <OfflineScreen/>
- );
- }
- };
- }
Add Comment
Please, Sign In to add comment