How to use the @react-native-community/netinfo.isConnected 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 rgommezz / react-native-offline / src / components / NetworkConnectivity.js View on Github external
async componentDidMount() {
    const { pingInterval } = this.props;
    const handler = this.getConnectionChangeHandler();

    NetInfo.isConnected.addEventListener('connectionChange', handler);
    // On Android the listener does not fire on startup
    if (Platform.OS === 'android') {
      const netConnected = await NetInfo.isConnected.fetch();
      handler(netConnected);
    }
    if (pingInterval > 0) {
      connectivityInterval.setup(this.intervalHandler, pingInterval);
    }
  }
github jayesbe / react-native-cacheable-image / image.js View on Github external
componentWillMount() {
        if (this.props.checkNetwork) {
            NetInfo.isConnected.addEventListener('connectionChange', this._handleConnectivityChange);
            // componentWillUnmount unsets this._handleConnectivityChange in case the component unmounts before this fetch resolves
            NetInfo.isConnected.fetch().done(this._handleConnectivityChange);
        }

        this._processSource(this.props.source, true);
    }
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 rainbow-me / rainbow / src / hoc / withNetInfo.js View on Github external
componentDidMount() {
      NetInfo.isConnected.addEventListener('connectionChange', this.props.setIsConnected);
    },
    componentWillUnmount() {
github LedgerHQ / ledger-live-mobile / src / components / AppStateListener.js View on Github external
componentWillUnmount() {
    NetInfo.isConnected.removeEventListener("connectionChange", this.sync);
  }
github LedgerHQ / ledger-live-mobile / src / components / AppStateListener.js View on Github external
componentDidMount() {
    NetInfo.isConnected.fetch().then(this.sync);
    NetInfo.isConnected.addEventListener("connectionChange", this.sync);
  }
github rainbow-me / rainbow / src / hoc / withNetInfo.js View on Github external
componentWillUnmount() {
      NetInfo.isConnected.removeEventListener('connectionChange', this.props.setIsConnected);
    },
  }),
github rgommezz / react-native-offline / src / redux / sagas.js View on Github external
return () => {
    NetInfo.isConnected.removeEventListener('connectionChange', emit);
  };
}
github CarGuo / GSYGithubAPP / app / net / index.js View on Github external
async netFetch(url, method = 'GET', params, json, header, text) {
        let isConnected = await NetInfo.isConnected.fetch().done;

        if (!isConnected) {
            return {
                result: false,
                code: Code.NETWORK_ERROR,
                msg: I18n('netError')
            }
        }

        let headers = {};
        if (header) {
            headers = Object.assign({}, headers, header)
        }

        //授权码
        if (!this.optionParams.authorizationCode) {
github MetaMask / metamask-mobile / app / components / Views / OfflineMode / index.js View on Github external
tryAgain = () => {
		NetInfo.isConnected.fetch().then(isConnected => {
			if (isConnected) {
				this.props.navigation.pop();
			}
		});
	};