-
Notifications
You must be signed in to change notification settings - Fork 239
/
Copy pathnativeInterface.ts
50 lines (43 loc) · 1.35 KB
/
nativeInterface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Copyright (c) React Native Community
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
const LINKING_ERROR =
`The package '@react-native-community/geolocation' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo managed workflow\n';
// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;
const RNCGeolocationModule = isTurboModuleEnabled
? require('./NativeRNCGeolocation').default
: NativeModules.RNCGeolocation;
const RNCGeolocation = RNCGeolocationModule
? RNCGeolocationModule
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);
/**
* We export the native interface in this way to give easy shared access to it between the
* JavaScript code and the tests
*/
let nativeEventEmitter: NativeEventEmitter | null = null;
export default {
RNCGeolocation,
get GeolocationEventEmitter() {
if (!nativeEventEmitter) {
nativeEventEmitter = new NativeEventEmitter(RNCGeolocation);
}
return nativeEventEmitter;
},
};