How to use the @react-native-community/netinfo.addEventListener function in @react-native-community/netinfo

To help you get started, we’ve selected a few @react-native-community/netinfo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zulip / zulip-mobile / src / boot / AppEventHandlers.js View on Github external
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();
  }
github digidem / mapeo-mobile / src / frontend / screens / SyncModal / index.js View on Github external
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();
    };
  }, []);
github celo-org / celo-monorepo / packages / mobile / src / networkInfo / saga.ts View on Github external
return eventChannel((emit) => {
    return NetInfo.addEventListener((state) => emit(state))
  })
}
github expo / expo / apps / native-component-list / src / screens / NetInfoScreen.tsx View on Github external
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;
  }
github search-future / miyou.tv / src / utils / init / index.ts View on Github external
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);
}
github expo / expo / home / api / Connectivity.ts View on Github external
constructor() {
    NetInfo.addEventListener(this._handleConnectivityChange);
    this.isAvailableAsync();
  }
github keybase / client / shared / actions / platform-specific / index.native.js View on Github external
const channel = Saga.eventChannel(emitter => {
    NetInfo.addEventListener('connectionChange', ({type}) => emitter(type === 'none' ? 'offline' : 'online'))
    return () => {}
  }, Saga.buffers.sliding(1))
github zzorba / ArkhamCards / components / core / withNetworkStatus.tsx View on Github external
componentDidMount() {
      this._refreshNetworkStatus();
      this.listenerUnsubscribe = NetInfo.addEventListener(this._networkStatusChanged);
    }
github esteemapp / esteem-mobile / src / screens / application / container / applicationContainer.js View on Github external
_setNetworkListener = () => {
    this.netListener = NetInfo.addEventListener(state => {
      const { isConnected, dispatch } = this.props;
      if (state.isConnected !== isConnected) {
        dispatch(setConnectivityStatus(state.isConnected));
        this._fetchApp();
      }
    });
  };
github CodeRabbitYu / ShiTu / app / components / BaseContainer / index.js View on Github external
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);
    };
  });