Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentDidMount() {
const { dispatch } = this.props;
handleInitialNotification(dispatch);
this.netInfoDisconnectCallback = NetInfo.addEventListener(this.handleConnectivityChange);
AppState.addEventListener('change', this.handleAppStateChange);
AppState.addEventListener('memoryWarning', this.handleMemoryWarning);
SafeArea.getSafeAreaInsetsForRootView().then(params =>
dispatch(initSafeAreaInsets(params.safeAreaInsets)),
);
// $FlowFixMe: libdef wrongly says callback's parameter is optional
Orientation.addOrientationListener(this.handleOrientationChange);
this.notificationListener.start();
}
ssid = await NetworkInfo.getSSID();
} catch (e) {
bugsnag.notify(e);
} finally {
// Even if we don't get the SSID, we still want to show that a wifi
// network is connected.
setSsid(ssid);
}
};
// When the modal opens, start announcing this device as available for sync
api.syncJoin(deviceName);
// Subscribe to peer updates
subscriptions.push(api.addPeerListener(setServerPeers));
// Subscribe to NetInfo to know when the user connects/disconnects to wifi
subscriptions.push({
remove: NetInfo.addEventListener(handleConnectionChange)
});
// Keep the screen awake whilst on this screen
KeepAwake.activate();
return () => {
// When the modal closes, stop announcing for sync
api.syncLeave();
// Unsubscribe all listeners
subscriptions.forEach(s => s.remove());
// Turn off keep screen awake
KeepAwake.deactivate();
};
}, []);
return eventChannel((emit) => {
return NetInfo.addEventListener((state) => emit(state))
})
}
componentDidMount() {
this._eventCounter = 0;
NetInfo.getConnectionInfo()
.then(connectionInfo => this.setState({ connectionInfo }))
.catch(console.warn);
this._ensureIsConnectionExpensiveIsUpToDate();
this._subscription = NetInfo.addEventListener(
'connectionChange',
this._handleConnectionChange
) as unknown as Subscription;
this._isConnectedSubscription = NetInfo.isConnected.addEventListener(
'connectionChange',
this._handleIsConnectedChange
) as unknown as Subscription;
}
export default function init(store: Store) {
BackHandler.addEventListener("hardwareBackPress", () => {
const { nav }: { nav: NavigationState } = store.getState();
const { index } = nav;
if (index > 1) {
store.dispatch(StackActions.pop({}));
return true;
}
return false;
});
NetInfo.fetch().then(state => {
store.dispatch(NetworkActions.update(state));
});
NetInfo.addEventListener(state => {
if (typeof state === "object") {
store.dispatch(NetworkActions.update(state));
}
});
common(store);
}
constructor() {
NetInfo.addEventListener(this._handleConnectivityChange);
this.isAvailableAsync();
}
const channel = Saga.eventChannel(emitter => {
NetInfo.addEventListener('connectionChange', ({type}) => emitter(type === 'none' ? 'offline' : 'online'))
return () => {}
}, Saga.buffers.sliding(1))
componentDidMount() {
this._refreshNetworkStatus();
this.listenerUnsubscribe = NetInfo.addEventListener(this._networkStatusChanged);
}
_setNetworkListener = () => {
this.netListener = NetInfo.addEventListener(state => {
const { isConnected, dispatch } = this.props;
if (state.isConnected !== isConnected) {
dispatch(setConnectivityStatus(state.isConnected));
this._fetchApp();
}
});
};
useEffect(() => {
NetInfo.getConnectionInfo().then(networkHandle);
if (netInfoListen) {
NetInfo.removeEventListener('connectionChange', networkHandle);
} else {
netInfoListen = NetInfo.addEventListener('connectionChange', networkHandle);
}
return () => {
props.store && props.store.hideLoading();
netInfoListen && NetInfo.removeEventListener('connectionChange', networkHandle);
};
});