1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | import {NativeEventEmitter} from 'react-native';
|
11 | import RNCNetInfo from './nativeModule';
|
12 |
|
13 |
|
14 | if (!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 |
|
23 | If 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 |
|
28 |
|
29 |
|
30 | let nativeEventEmitter: NativeEventEmitter | null = null;
|
31 | export default {
|
32 | ...RNCNetInfo,
|
33 | get eventEmitter(): NativeEventEmitter {
|
34 | if (!nativeEventEmitter) {
|
35 |
|
36 | nativeEventEmitter = new NativeEventEmitter(RNCNetInfo);
|
37 | }
|
38 |
|
39 | return nativeEventEmitter;
|
40 | },
|
41 | };
|