UNPKG

1.65 kBPlain TextView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10import {NativeEventEmitter} from 'react-native';
11import RNCNetInfo from './nativeModule';
12
13// Produce an error if we don't have the native module
14if (!RNCNetInfo) {
15 throw new Error(`@react-native-community/netinfo: NativeModule.RNCNetInfo is null. To fix this issue try these steps:
16
17• Run \`react-native link @react-native-community/netinfo\` in the project root.
18• Rebuild and re-run the app.
19• 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.
20• Check that the library was linked correctly when you used the link command by running through the manual installation instructions in the README.
21* If you are getting this error while unit testing you need to mock the native module. Follow the guide in the README.
22
23If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-netinfo`);
24}
25
26/**
27 * We export the native interface in this way to give easy shared access to it between the
28 * JavaScript code and the tests
29 */
30let nativeEventEmitter: NativeEventEmitter | null = null;
31export default {
32 ...RNCNetInfo,
33 get eventEmitter(): NativeEventEmitter {
34 if (!nativeEventEmitter) {
35 /// @ts-ignore
36 nativeEventEmitter = new NativeEventEmitter(RNCNetInfo);
37 }
38 /// @ts-ignore
39 return nativeEventEmitter;
40 },
41};