@exodus/netinfo
Version:
React Native Network Info API for iOS & Android
40 lines (33 loc) • 1.28 kB
JavaScript
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
import {NativeEventEmitter, NativeModules} from 'react-native';
const {RNCNetInfo} = NativeModules;
// Produce an error if we don't have the native module
if (!RNCNetInfo) {
throw new Error(`@exodus/netinfo: NativeModule.RNCNetInfo is null. To fix this issue try these steps:
• Run \`react-native link @exodus/netinfo\` in the project root.
• Rebuild and re-run the app.
• If you are using CocoaPods on iOS, run \`pod install\` in the \`ios\` directory and then rebuild and re-run the app. You may also need to re-open Xcode to get the new pods.
If none of these fix the issue, please open an issue on the Github repository: https://github.com/ExodusMovement/react-native-netinfo`);
}
/**
* We export the native interface in this way to give easy shared access to it between the
* JavaScript code and the tests
*/
let nativeEventEmitter = null;
module.exports = {
RNCNetInfo,
get NetInfoEventEmitter() {
if (!nativeEventEmitter) {
nativeEventEmitter = new NativeEventEmitter(RNCNetInfo);
}
return nativeEventEmitter;
},
};