expo-location 58.0.12 → 58.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/android/build.gradle +2 -2
  3. package/build/Location.types.d.ts +4 -1
  4. package/build/Location.types.js.map +1 -1
  5. package/build/next/Location.d.ts +1 -0
  6. package/build/next/Location.js +3 -0
  7. package/build/next/Location.js.map +1 -0
  8. package/build/next/index.d.ts +3 -0
  9. package/build/next/index.js +5 -0
  10. package/build/next/index.js.map +1 -0
  11. package/build/next/js/LocationProvider.d.ts +9 -0
  12. package/build/next/js/LocationProvider.js +20 -0
  13. package/build/next/js/LocationProvider.js.map +1 -0
  14. package/build/next/js/LocationUpdatesHandle.d.ts +15 -0
  15. package/build/next/js/LocationUpdatesHandle.js +39 -0
  16. package/build/next/js/LocationUpdatesHandle.js.map +1 -0
  17. package/build/next/js/Permissions.d.ts +7 -0
  18. package/build/next/js/Permissions.js +24 -0
  19. package/build/next/js/Permissions.js.map +1 -0
  20. package/build/next/js/PositionWatchHandle.d.ts +16 -0
  21. package/build/next/js/PositionWatchHandle.js +50 -0
  22. package/build/next/js/PositionWatchHandle.js.map +1 -0
  23. package/build/next/js/getPosition.d.ts +2 -0
  24. package/build/next/js/getPosition.js +6 -0
  25. package/build/next/js/getPosition.js.map +1 -0
  26. package/build/next/js/index.d.ts +6 -0
  27. package/build/next/js/index.js +8 -0
  28. package/build/next/js/index.js.map +1 -0
  29. package/build/next/js/locationServices.d.ts +3 -0
  30. package/build/next/js/locationServices.js +35 -0
  31. package/build/next/js/locationServices.js.map +1 -0
  32. package/build/next/native/NativeLocationModuleNext.d.ts +5 -0
  33. package/build/next/native/NativeLocationModuleNext.js +7 -0
  34. package/build/next/native/NativeLocationModuleNext.js.map +1 -0
  35. package/build/next/native/index.d.ts +5 -0
  36. package/build/next/native/index.js +3 -0
  37. package/build/next/native/index.js.map +1 -0
  38. package/build/next/native/types/NativeLocationModuleNextClass.types.d.ts +21 -0
  39. package/build/next/native/types/NativeLocationModuleNextClass.types.js +3 -0
  40. package/build/next/native/types/NativeLocationModuleNextClass.types.js.map +1 -0
  41. package/build/next/native/types/NativeLocationProviderClass.types.d.ts +8 -0
  42. package/build/next/native/types/NativeLocationProviderClass.types.js +3 -0
  43. package/build/next/native/types/NativeLocationProviderClass.types.js.map +1 -0
  44. package/build/next/native/types/NativeLocationUpdatesHandleClass.types.d.ts +8 -0
  45. package/build/next/native/types/NativeLocationUpdatesHandleClass.types.js +3 -0
  46. package/build/next/native/types/NativeLocationUpdatesHandleClass.types.js.map +1 -0
  47. package/build/next/native/types/NativePositionWatchHandleClass.types.d.ts +12 -0
  48. package/build/next/native/types/NativePositionWatchHandleClass.types.js +3 -0
  49. package/build/next/native/types/NativePositionWatchHandleClass.types.js.map +1 -0
  50. package/build/next/types/LocationProvider.types.d.ts +1 -0
  51. package/build/next/types/LocationProvider.types.js +3 -0
  52. package/build/next/types/LocationProvider.types.js.map +1 -0
  53. package/build/next/types/Permissions.types.d.ts +22 -0
  54. package/build/next/types/Permissions.types.js +19 -0
  55. package/build/next/types/Permissions.types.js.map +1 -0
  56. package/build/next/types/Position.types.d.ts +55 -0
  57. package/build/next/types/Position.types.js +11 -0
  58. package/build/next/types/Position.types.js.map +1 -0
  59. package/build/next/types/index.d.ts +3 -0
  60. package/build/next/types/index.js +5 -0
  61. package/build/next/types/index.js.map +1 -0
  62. package/expo-module.config.json +1 -1
  63. package/ios/EXLocation.m +1 -0
  64. package/ios/ExpoLocation.podspec +9 -0
  65. package/ios/LocationUtils.swift +3 -1
  66. package/ios/next/LocationModuleNext.swift +110 -0
  67. package/ios/next/LocationNextExceptions.swift +118 -0
  68. package/ios/next/LocationUpdatesHandle/LocationUpdatesHandle.swift +52 -0
  69. package/ios/next/LocationUpdatesHandle/LocationUpdatesTaskConsumer.swift +40 -0
  70. package/ios/next/LocationUpdatesHandle/LocationUpdatesTaskOptions.swift +19 -0
  71. package/ios/next/LocationUpdatesHandle/SignificantLocationChangeMonitor.swift +20 -0
  72. package/ios/next/Permissions/BackgroundPermissionsRequester.swift +34 -0
  73. package/ios/next/Permissions/CLLocationManager+MainThread.swift +10 -0
  74. package/ios/next/Permissions/ForegroundPermissionsRequester.swift +38 -0
  75. package/ios/next/Permissions/LocationAccessGuard.swift +21 -0
  76. package/ios/next/Permissions/LocationAccuracyAuthorization.swift +9 -0
  77. package/ios/next/Permissions/LocationAccuracyOption.swift +6 -0
  78. package/ios/next/Permissions/LocationAuthorizationScope.swift +16 -0
  79. package/ios/next/Permissions/LocationManagerAlwaysAuthorizationRequest.swift +109 -0
  80. package/ios/next/Permissions/LocationPermissionKind.swift +26 -0
  81. package/ios/next/Permissions/LocationPermissionResponse.swift +51 -0
  82. package/ios/next/Permissions/LocationPermissionsDelegate.swift +85 -0
  83. package/ios/next/Permissions/LocationPermissionsRequester.swift +96 -0
  84. package/ios/next/Permissions/LocationPlistKeys.swift +10 -0
  85. package/ios/next/Permissions/PermissionsRequestOptions.swift +5 -0
  86. package/ios/next/Permissions/TemporaryFullAccuracyPlistKeys.swift +13 -0
  87. package/ios/next/Permissions/TemporaryFullAccuracyRequester.swift +28 -0
  88. package/ios/next/Position/Coordinates.swift +7 -0
  89. package/ios/next/Position/GetPositionOptions.swift +7 -0
  90. package/ios/next/Position/LocationUpdateDiagnostics.swift +41 -0
  91. package/ios/next/Position/Position.swift +43 -0
  92. package/ios/next/Position/PositionRequester.swift +55 -0
  93. package/ios/next/Position/PositionUpdatesCompatibilitySource.swift +43 -0
  94. package/ios/next/Position/PositionUpdatesLiveSource.swift +46 -0
  95. package/ios/next/Position/PositionUpdatesSource.swift +40 -0
  96. package/ios/next/Position/PositionUpdatesSubscription.swift +85 -0
  97. package/ios/next/PositionWatcher/PositionWatchStatus.swift +9 -0
  98. package/ios/next/PositionWatcher/PositionWatcher.swift +143 -0
  99. package/ios/next/Profile.swift +60 -0
  100. package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12.module → 58.0.13/expo.modules.location-58.0.13.module} +7 -7
  101. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.md5 +1 -0
  102. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.sha1 +1 -0
  103. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.sha256 +1 -0
  104. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.module.sha512 +1 -0
  105. package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12.pom → 58.0.13/expo.modules.location-58.0.13.pom} +1 -1
  106. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.md5 +1 -0
  107. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.sha1 +1 -0
  108. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.sha256 +1 -0
  109. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.13/expo.modules.location-58.0.13.pom.sha512 +1 -0
  110. package/package.json +32 -3
  111. package/plugin/build/withLocation.d.ts +18 -0
  112. package/plugin/build/withLocation.js +28 -1
  113. package/plugin/build/withLocation.js.map +1 -1
  114. package/plugin/src/withLocation.ts +52 -0
  115. package/src/Location.types.ts +4 -1
  116. package/src/next/Location.ts +12 -0
  117. package/src/next/index.ts +28 -0
  118. package/src/next/js/LocationProvider.ts +28 -0
  119. package/src/next/js/LocationUpdatesHandle.ts +60 -0
  120. package/src/next/js/Permissions.ts +34 -0
  121. package/src/next/js/PositionWatchHandle.ts +75 -0
  122. package/src/next/js/getPosition.ts +6 -0
  123. package/src/next/js/index.ts +21 -0
  124. package/src/next/js/locationServices.ts +38 -0
  125. package/src/next/native/NativeLocationModuleNext.ts +9 -0
  126. package/src/next/native/index.ts +10 -0
  127. package/src/next/native/types/NativeLocationModuleNextClass.types.ts +34 -0
  128. package/src/next/native/types/NativeLocationProviderClass.types.ts +12 -0
  129. package/src/next/native/types/NativeLocationUpdatesHandleClass.types.ts +9 -0
  130. package/src/next/native/types/NativePositionWatchHandleClass.types.ts +14 -0
  131. package/src/next/types/LocationProvider.types.ts +1 -0
  132. package/src/next/types/Permissions.types.ts +27 -0
  133. package/src/next/types/Position.types.ts +58 -0
  134. package/src/next/types/index.ts +3 -0
  135. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.module.md5 +0 -1
  136. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.module.sha1 +0 -1
  137. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.module.sha256 +0 -1
  138. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.module.sha512 +0 -1
  139. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.pom.md5 +0 -1
  140. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.pom.sha1 +0 -1
  141. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.pom.sha256 +0 -1
  142. package/local-maven-repo/host/exp/exponent/expo.modules.location/58.0.12/expo.modules.location-58.0.12.pom.sha512 +0 -1
  143. /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12-sources.jar → 58.0.13/expo.modules.location-58.0.13-sources.jar} +0 -0
  144. /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12-sources.jar.md5 → 58.0.13/expo.modules.location-58.0.13-sources.jar.md5} +0 -0
  145. /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12-sources.jar.sha1 → 58.0.13/expo.modules.location-58.0.13-sources.jar.sha1} +0 -0
  146. /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12-sources.jar.sha256 → 58.0.13/expo.modules.location-58.0.13-sources.jar.sha256} +0 -0
  147. /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12-sources.jar.sha512 → 58.0.13/expo.modules.location-58.0.13-sources.jar.sha512} +0 -0
  148. /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12.aar → 58.0.13/expo.modules.location-58.0.13.aar} +0 -0
  149. /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12.aar.md5 → 58.0.13/expo.modules.location-58.0.13.aar.md5} +0 -0
  150. /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12.aar.sha1 → 58.0.13/expo.modules.location-58.0.13.aar.sha1} +0 -0
  151. /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12.aar.sha256 → 58.0.13/expo.modules.location-58.0.13.aar.sha256} +0 -0
  152. /package/local-maven-repo/host/exp/exponent/expo.modules.location/{58.0.12/expo.modules.location-58.0.12.aar.sha512 → 58.0.13/expo.modules.location-58.0.13.aar.sha512} +0 -0
@@ -15,6 +15,9 @@ import { resolve } from 'path';
15
15
  const pkg = require('../../package.json');
16
16
  const LOCATION_USAGE = 'Allow $(PRODUCT_NAME) to access your location';
17
17
  const MOTION_USAGE = 'Allow $(PRODUCT_NAME) to detect your current motion activity';
18
+ const FULL_ACCURACY_USAGE = 'Allow $(PRODUCT_NAME) to access your precise location';
19
+
20
+ export const FULL_ACCURACY_PURPOSE_KEY = 'ExpoLocationFullAccuracy';
18
21
 
19
22
  type DPIString = 'mdpi' | 'hdpi' | 'xhdpi' | 'xxhdpi' | 'xxxhdpi';
20
23
  type dpiMap = Record<DPIString, { folderName: string; scale: number }>;
@@ -140,6 +143,25 @@ function removeForegroundServiceIconImageFiles(projectRoot: string) {
140
143
  });
141
144
  }
142
145
 
146
+ const withTemporaryFullAccuracy: ConfigPlugin<string> = (config, message) => {
147
+ return withInfoPlist(config, (config) => {
148
+ config.modResults.NSLocationTemporaryUsageDescriptionDictionary = {
149
+ ...(config.modResults.NSLocationTemporaryUsageDescriptionDictionary as
150
+ | Record<string, string>
151
+ | undefined),
152
+ [FULL_ACCURACY_PURPOSE_KEY]: message,
153
+ };
154
+ return config;
155
+ });
156
+ };
157
+
158
+ const withReducedAccuracyDefault: ConfigPlugin = (config) => {
159
+ return withInfoPlist(config, (config) => {
160
+ config.modResults.NSLocationDefaultAccuracyReduced = true;
161
+ return config;
162
+ });
163
+ };
164
+
143
165
  export type Props = {
144
166
  /**
145
167
  * A string to set the `NSLocationAlwaysAndWhenInUseUsageDescription` permission message.
@@ -169,6 +191,23 @@ export type Props = {
169
191
  * @platform ios
170
192
  */
171
193
  motionUsagePermission?: string | false;
194
+ /**
195
+ * A string to set the message the system shows when a permission request from
196
+ * `expo-location/next` asks to raise a reduced accuracy authorization to full accuracy. It is written under the
197
+ * `ExpoLocationFullAccuracy` key of `NSLocationTemporaryUsageDescriptionDictionary`.
198
+ * Pass `false` to omit the key, which skips the raise.
199
+ * @default "Allow $(PRODUCT_NAME) to access your precise location"
200
+ * @platform ios
201
+ */
202
+ locationFullAccuracyPermission?: string | false;
203
+ /**
204
+ * Whether the permission prompt offers reduced accuracy by default, by setting
205
+ * `NSLocationDefaultAccuracyReduced` in `Info.plist`. The app can still ask for full accuracy
206
+ * for a session with `accuracy: 'full'` in a permission request from `expo-location/next`.
207
+ * @default false
208
+ * @platform ios
209
+ */
210
+ isIosReducedAccuracyByDefault?: boolean;
172
211
  /**
173
212
  * Whether to enable location in `UIBackgroundModes`.
174
213
  * @default false
@@ -208,6 +247,8 @@ const withLocation: ConfigPlugin<Props | void> = (
208
247
  locationAlwaysPermission,
209
248
  locationWhenInUsePermission,
210
249
  motionUsagePermission,
250
+ locationFullAccuracyPermission,
251
+ isIosReducedAccuracyByDefault,
211
252
  isIosBackgroundLocationEnabled,
212
253
  isAndroidBackgroundLocationEnabled,
213
254
  isAndroidForegroundServiceEnabled,
@@ -228,6 +269,17 @@ const withLocation: ConfigPlugin<Props | void> = (
228
269
  return config;
229
270
  });
230
271
 
272
+ if (locationFullAccuracyPermission !== false) {
273
+ config = withTemporaryFullAccuracy(
274
+ config,
275
+ locationFullAccuracyPermission || FULL_ACCURACY_USAGE
276
+ );
277
+ }
278
+
279
+ if (isIosReducedAccuracyByDefault) {
280
+ config = withReducedAccuracyDefault(config);
281
+ }
282
+
231
283
  config = withForegroundServiceIcon(config, { icon: androidForegroundServiceIcon ?? null });
232
284
 
233
285
  IOSConfig.Permissions.createPermissionsPlugin({
@@ -265,8 +265,11 @@ export type LocationObject = {
265
265
  */
266
266
  timestamp: number;
267
267
  /**
268
- * Whether the location coordinates is mocked or not.
268
+ * Whether the location coordinates is mocked or not. On Android, this is `true` when the location
269
+ * comes from a mock provider. On iOS, it is `true` when the location is simulated by software
270
+ * (for example, by Xcode or a location-spoofing tool).
269
271
  * @platform android
272
+ * @platform ios
270
273
  */
271
274
  mocked?: boolean;
272
275
  };
@@ -0,0 +1,12 @@
1
+ export {
2
+ getPosition,
3
+ watchPosition,
4
+ hasLocationServicesEnabled,
5
+ enableLocationServices,
6
+ getForegroundPermissions,
7
+ requestForegroundPermissions,
8
+ getBackgroundPermissions,
9
+ requestBackgroundPermissions,
10
+ setLocationProvider,
11
+ getSelectedLocationProviderName,
12
+ } from './js';
@@ -0,0 +1,28 @@
1
+ export * as Location from './Location';
2
+
3
+ export {
4
+ useForegroundLocationPermissions,
5
+ useBackgroundLocationPermissions,
6
+ useLocationServices,
7
+ PositionWatchHandle,
8
+ LocationProvider,
9
+ LocationUpdatesHandle,
10
+ defineLocationTask,
11
+ } from './js';
12
+
13
+ export {
14
+ LocationProfile,
15
+ LocationAccuracy,
16
+ LocationScope,
17
+ RequestPermissionsAccuracyOption,
18
+ type Coordinates,
19
+ type Position,
20
+ type PositionUpdate,
21
+ type PositionWatchError,
22
+ type PositionWatchStatus,
23
+ type WatchPositionParams,
24
+ type GetPositionOptions,
25
+ type LocationPermissionResponse,
26
+ type RequestPermissionsOptions,
27
+ type LocationProviderRefType,
28
+ } from './types';
@@ -0,0 +1,28 @@
1
+ import type { SharedRef } from 'expo';
2
+
3
+ import { NativeLocationModuleNext, NativeLocationProvider } from '../native';
4
+ import type { LocationProviderRefType } from '../types';
5
+
6
+ export class LocationProvider {
7
+ static Gms(): SharedRef<LocationProviderRefType> {
8
+ return NativeLocationProvider.Gms();
9
+ }
10
+
11
+ static Android(): SharedRef<LocationProviderRefType> {
12
+ return NativeLocationProvider.Android();
13
+ }
14
+
15
+ static Fallback(
16
+ providers: SharedRef<LocationProviderRefType>[]
17
+ ): SharedRef<LocationProviderRefType> {
18
+ return NativeLocationProvider.Fallback(providers);
19
+ }
20
+ }
21
+
22
+ export function setLocationProvider(provider: SharedRef<LocationProviderRefType>): void {
23
+ NativeLocationModuleNext.setLocationProvider(provider);
24
+ }
25
+
26
+ export function getSelectedLocationProviderName(): string {
27
+ return NativeLocationModuleNext.getSelectedLocationProviderName();
28
+ }
@@ -0,0 +1,60 @@
1
+ import type { TaskManagerError } from 'expo-task-manager';
2
+
3
+ import { NativeLocationUpdatesHandle } from '../native';
4
+ import type { NativeLocationUpdatesHandleClass } from '../native';
5
+ import type { LocationProfile, Position } from '../types';
6
+
7
+ const DEFAULT_LOCATION_TASK_NAME = 'expo-location-background-location';
8
+
9
+ export class LocationUpdatesHandle {
10
+ private readonly nativeHandle: NativeLocationUpdatesHandleClass;
11
+
12
+ constructor(taskName: string = DEFAULT_LOCATION_TASK_NAME) {
13
+ this.nativeHandle = new NativeLocationUpdatesHandle(taskName);
14
+ }
15
+
16
+ withProfile(profile: LocationProfile): this {
17
+ this.nativeHandle.withProfile(profile);
18
+ return this;
19
+ }
20
+
21
+ start(): Promise<void> {
22
+ return this.nativeHandle.start();
23
+ }
24
+
25
+ stop(): Promise<void> {
26
+ return this.nativeHandle.stop();
27
+ }
28
+
29
+ hasStarted(): Promise<boolean> {
30
+ return this.nativeHandle.hasStarted();
31
+ }
32
+ }
33
+
34
+ export function defineLocationTask({
35
+ taskName = DEFAULT_LOCATION_TASK_NAME,
36
+ onPosition,
37
+ onError,
38
+ }: {
39
+ taskName?: string;
40
+ onPosition: (position: Position) => void;
41
+ onError?: (error: TaskManagerError) => void;
42
+ }): void {
43
+ requireTaskManager().defineTask<Position>(taskName, async ({ data, error }) => {
44
+ if (error) {
45
+ onError?.(error);
46
+ return;
47
+ }
48
+ onPosition(data);
49
+ });
50
+ }
51
+
52
+ function requireTaskManager(): typeof import('expo-task-manager') {
53
+ try {
54
+ return require('expo-task-manager');
55
+ } catch {
56
+ throw new Error(
57
+ "defineLocationTask couldn't define the background location task because the 'expo-task-manager' package isn't installed. Background location updates are delivered through it. Install it with `npx expo install expo-task-manager` and rebuild the app."
58
+ );
59
+ }
60
+ }
@@ -0,0 +1,34 @@
1
+ import { createPermissionHook } from 'expo-modules-core';
2
+
3
+ import { NativeLocationModuleNext } from '../native';
4
+ import type { LocationPermissionResponse, RequestPermissionsOptions } from '../types';
5
+
6
+ export async function getForegroundPermissions(): Promise<LocationPermissionResponse> {
7
+ return NativeLocationModuleNext.getForegroundPermissions();
8
+ }
9
+
10
+ export async function requestForegroundPermissions(
11
+ options?: RequestPermissionsOptions
12
+ ): Promise<LocationPermissionResponse> {
13
+ return NativeLocationModuleNext.requestForegroundPermissions(options);
14
+ }
15
+
16
+ export async function getBackgroundPermissions(): Promise<LocationPermissionResponse> {
17
+ return NativeLocationModuleNext.getBackgroundPermissions();
18
+ }
19
+
20
+ export async function requestBackgroundPermissions(
21
+ options?: RequestPermissionsOptions
22
+ ): Promise<LocationPermissionResponse> {
23
+ return NativeLocationModuleNext.requestBackgroundPermissions(options);
24
+ }
25
+
26
+ export const useForegroundLocationPermissions = createPermissionHook({
27
+ getMethod: getForegroundPermissions,
28
+ requestMethod: requestForegroundPermissions,
29
+ });
30
+
31
+ export const useBackgroundLocationPermissions = createPermissionHook({
32
+ getMethod: getBackgroundPermissions,
33
+ requestMethod: requestBackgroundPermissions,
34
+ });
@@ -0,0 +1,75 @@
1
+ import type { EventSubscription } from 'expo';
2
+
3
+ import { NativeLocationModuleNext } from '../native';
4
+ import type { NativePositionWatchHandleClass } from '../native';
5
+ import { LocationProfile } from '../types';
6
+ import type {
7
+ Position,
8
+ PositionWatchError,
9
+ PositionWatchStatus,
10
+ WatchPositionParams,
11
+ } from '../types';
12
+
13
+ export class PositionWatchHandle {
14
+ private readonly nativeHandle: NativePositionWatchHandleClass;
15
+
16
+ constructor(profile: LocationProfile = LocationProfile.DEFAULT) {
17
+ this.nativeHandle = NativeLocationModuleNext.watchPosition(profile);
18
+ }
19
+
20
+ pause(): void {
21
+ this.nativeHandle.pause();
22
+ }
23
+
24
+ resume(): boolean {
25
+ return this.nativeHandle.resume();
26
+ }
27
+
28
+ withProfile(profile: LocationProfile): this {
29
+ this.nativeHandle.withProfile(profile);
30
+ return this;
31
+ }
32
+
33
+ withInterval(intervalSeconds: number): this {
34
+ this.nativeHandle.withInterval(intervalSeconds);
35
+ return this;
36
+ }
37
+
38
+ restart(): boolean {
39
+ return this.nativeHandle.restart();
40
+ }
41
+
42
+ status(): PositionWatchStatus {
43
+ return this.nativeHandle.status();
44
+ }
45
+
46
+ dispose(): void {
47
+ this.nativeHandle.removeAllListeners('positionChanged');
48
+ this.nativeHandle.release();
49
+ }
50
+
51
+ addListener(
52
+ onPosition: (position: Position) => void,
53
+ onError?: (error: PositionWatchError) => void
54
+ ): EventSubscription {
55
+ return this.nativeHandle.addListener('positionChanged', ({ data, error }) => {
56
+ if (error != null) {
57
+ onError?.(error);
58
+ return;
59
+ }
60
+ if (data != null) {
61
+ onPosition(data);
62
+ }
63
+ });
64
+ }
65
+ }
66
+
67
+ export function watchPosition({
68
+ profile = LocationProfile.DEFAULT,
69
+ onPosition,
70
+ onError,
71
+ }: WatchPositionParams): PositionWatchHandle {
72
+ const handle = new PositionWatchHandle(profile);
73
+ handle.addListener(onPosition, onError);
74
+ return handle;
75
+ }
@@ -0,0 +1,6 @@
1
+ import { NativeLocationModuleNext } from '../native';
2
+ import type { GetPositionOptions, Position } from '../types';
3
+
4
+ export async function getPosition(options?: GetPositionOptions): Promise<Position | null> {
5
+ return NativeLocationModuleNext.getPosition(options);
6
+ }
@@ -0,0 +1,21 @@
1
+ export { getPosition } from './getPosition';
2
+ export {
3
+ hasLocationServicesEnabled,
4
+ enableLocationServices,
5
+ useLocationServices,
6
+ } from './locationServices';
7
+ export { PositionWatchHandle, watchPosition } from './PositionWatchHandle';
8
+ export {
9
+ LocationProvider,
10
+ setLocationProvider,
11
+ getSelectedLocationProviderName,
12
+ } from './LocationProvider';
13
+ export {
14
+ getForegroundPermissions,
15
+ requestForegroundPermissions,
16
+ getBackgroundPermissions,
17
+ requestBackgroundPermissions,
18
+ useForegroundLocationPermissions,
19
+ useBackgroundLocationPermissions,
20
+ } from './Permissions';
21
+ export { LocationUpdatesHandle, defineLocationTask } from './LocationUpdatesHandle';
@@ -0,0 +1,38 @@
1
+ import { Platform, UnavailabilityError } from 'expo';
2
+ import { useCallback, useEffect, useState } from 'react';
3
+ import { AppState } from 'react-native';
4
+
5
+ import { NativeLocationModuleNext } from '../native';
6
+
7
+ export function hasLocationServicesEnabled(): boolean {
8
+ return NativeLocationModuleNext.hasLocationServicesEnabled();
9
+ }
10
+
11
+ export async function enableLocationServices(): Promise<boolean> {
12
+ if (Platform.OS !== 'android') {
13
+ throw new UnavailabilityError('expo-location', 'enableLocationServices');
14
+ }
15
+
16
+ return NativeLocationModuleNext.enableLocationServices();
17
+ }
18
+
19
+ export function useLocationServices(): [enabled: boolean, enable: () => Promise<boolean>] {
20
+ const [enabled, setEnabled] = useState(hasLocationServicesEnabled);
21
+
22
+ useEffect(() => {
23
+ const subscription = AppState.addEventListener('change', (state) => {
24
+ if (state === 'active') {
25
+ setEnabled(hasLocationServicesEnabled());
26
+ }
27
+ });
28
+ return () => subscription.remove();
29
+ }, []);
30
+
31
+ const enable = useCallback(async () => {
32
+ const result = await enableLocationServices();
33
+ setEnabled(result);
34
+ return result;
35
+ }, []);
36
+
37
+ return [enabled, enable];
38
+ }
@@ -0,0 +1,9 @@
1
+ import { requireNativeModule } from 'expo';
2
+
3
+ import type { NativeLocationModuleNextClass } from './types/NativeLocationModuleNextClass.types';
4
+
5
+ export const NativeLocationModuleNext =
6
+ requireNativeModule<NativeLocationModuleNextClass>('LocationModuleNext');
7
+ export const NativeLocationProvider = NativeLocationModuleNext.LocationProvider;
8
+ export const NativePositionWatchHandle = NativeLocationModuleNext.PositionWatchHandle;
9
+ export const NativeLocationUpdatesHandle = NativeLocationModuleNext.LocationUpdatesHandle;
@@ -0,0 +1,10 @@
1
+ export {
2
+ NativeLocationModuleNext,
3
+ NativeLocationProvider,
4
+ NativePositionWatchHandle,
5
+ NativeLocationUpdatesHandle,
6
+ } from './NativeLocationModuleNext';
7
+ export type { NativeLocationModuleNextClass } from './types/NativeLocationModuleNextClass.types';
8
+ export type { NativePositionWatchHandleClass } from './types/NativePositionWatchHandleClass.types';
9
+ export type { NativeLocationProviderClass } from './types/NativeLocationProviderClass.types';
10
+ export type { NativeLocationUpdatesHandleClass } from './types/NativeLocationUpdatesHandleClass.types';
@@ -0,0 +1,34 @@
1
+ import { NativeModule } from 'expo';
2
+ import type { SharedRef } from 'expo';
3
+
4
+ import type {
5
+ GetPositionOptions,
6
+ LocationPermissionResponse,
7
+ LocationProfile,
8
+ LocationProviderRefType,
9
+ Position,
10
+ RequestPermissionsOptions,
11
+ } from '../../types';
12
+ import type { NativeLocationProviderClass } from './NativeLocationProviderClass.types';
13
+ import type { NativeLocationUpdatesHandleClass } from './NativeLocationUpdatesHandleClass.types';
14
+ import type { NativePositionWatchHandleClass } from './NativePositionWatchHandleClass.types';
15
+
16
+ export declare class NativeLocationModuleNextClass extends NativeModule {
17
+ requestForegroundPermissions(
18
+ options?: RequestPermissionsOptions
19
+ ): Promise<LocationPermissionResponse>;
20
+ getForegroundPermissions(): Promise<LocationPermissionResponse>;
21
+ requestBackgroundPermissions(
22
+ options?: RequestPermissionsOptions
23
+ ): Promise<LocationPermissionResponse>;
24
+ getBackgroundPermissions(): Promise<LocationPermissionResponse>;
25
+ setLocationProvider(provider: SharedRef<LocationProviderRefType>): void;
26
+ getSelectedLocationProviderName(): string;
27
+ hasLocationServicesEnabled(): boolean;
28
+ enableLocationServices(): Promise<boolean>;
29
+ getPosition(options?: GetPositionOptions): Promise<Position | null>;
30
+ watchPosition(profile?: LocationProfile): NativePositionWatchHandleClass;
31
+ LocationProvider: typeof NativeLocationProviderClass;
32
+ PositionWatchHandle: typeof NativePositionWatchHandleClass;
33
+ LocationUpdatesHandle: typeof NativeLocationUpdatesHandleClass;
34
+ }
@@ -0,0 +1,12 @@
1
+ import { SharedObject } from 'expo';
2
+ import type { SharedRef } from 'expo';
3
+
4
+ import type { LocationProviderRefType } from '../../types';
5
+
6
+ export declare class NativeLocationProviderClass extends SharedObject {
7
+ static Gms(): SharedRef<LocationProviderRefType>;
8
+ static Android(): SharedRef<LocationProviderRefType>;
9
+ static Fallback(
10
+ providers: SharedRef<LocationProviderRefType>[]
11
+ ): SharedRef<LocationProviderRefType>;
12
+ }
@@ -0,0 +1,9 @@
1
+ import type { LocationProfile } from '../../types';
2
+
3
+ export declare class NativeLocationUpdatesHandleClass {
4
+ constructor(taskName: string);
5
+ withProfile(profile: LocationProfile): void;
6
+ start(): Promise<void>;
7
+ stop(): Promise<void>;
8
+ hasStarted(): Promise<boolean>;
9
+ }
@@ -0,0 +1,14 @@
1
+ import { SharedObject } from 'expo';
2
+
3
+ import type { LocationProfile, PositionUpdate, PositionWatchStatus } from '../../types';
4
+
5
+ export declare class NativePositionWatchHandleClass extends SharedObject<{
6
+ positionChanged: (update: PositionUpdate) => void;
7
+ }> {
8
+ pause(): void;
9
+ resume(): boolean;
10
+ withProfile(profile: LocationProfile): NativePositionWatchHandleClass;
11
+ withInterval(intervalSeconds: number): NativePositionWatchHandleClass;
12
+ restart(): boolean;
13
+ status(): PositionWatchStatus;
14
+ }
@@ -0,0 +1 @@
1
+ export type LocationProviderRefType = 'LocationProvider';
@@ -0,0 +1,27 @@
1
+ import type { PermissionResponse } from 'expo';
2
+
3
+ export enum LocationScope {
4
+ ALWAYS = 'always',
5
+ WHEN_IN_USE = 'whenInUse',
6
+ NOT_GRANTED = 'notGranted',
7
+ }
8
+
9
+ export enum LocationAccuracy {
10
+ FULL = 'full',
11
+ REDUCED = 'reduced',
12
+ NOT_GRANTED = 'notGranted',
13
+ }
14
+
15
+ export enum RequestPermissionsAccuracyOption {
16
+ FULL = 'full',
17
+ REDUCED = 'reduced',
18
+ }
19
+
20
+ export type LocationPermissionResponse = PermissionResponse & {
21
+ scope: LocationScope;
22
+ accuracy: LocationAccuracy;
23
+ };
24
+
25
+ export type RequestPermissionsOptions = {
26
+ accuracy?: RequestPermissionsAccuracyOption;
27
+ };
@@ -0,0 +1,58 @@
1
+ export enum LocationProfile {
2
+ DEFAULT = 'default',
3
+ AUTOMOTIVE_NAVIGATION = 'automotiveNavigation',
4
+ OTHER_NAVIGATION = 'otherNavigation',
5
+ FITNESS = 'fitness',
6
+ AIRBORNE = 'airborne',
7
+ LOW_POWER = 'lowPower',
8
+ }
9
+
10
+ export type Coordinates = {
11
+ latitude: number;
12
+ longitude: number;
13
+ };
14
+
15
+ export type Position = {
16
+ coordinates: Coordinates;
17
+ horizontalAccuracy: number | null;
18
+ timestamp: number;
19
+ altitude: number | null;
20
+ mslAltitude: number | null;
21
+ verticalAccuracy: number | null;
22
+ mocked: boolean;
23
+ heading: number | null;
24
+ headingAccuracy: number | null;
25
+ speed: number | null;
26
+ speedAccuracy: number | null;
27
+ };
28
+
29
+ export type GetPositionOptions = {
30
+ maxCachedAge?: number;
31
+ timeout?: number;
32
+ profile?: LocationProfile;
33
+ };
34
+
35
+ export type PositionWatchError = {
36
+ code: string;
37
+ message: string;
38
+ };
39
+
40
+ export type PositionUpdate =
41
+ | { data: Position; error: null }
42
+ | { data: null; error: PositionWatchError };
43
+
44
+ export type PositionWatchStatus = {
45
+ /** Whether the provider is feeding positions right now. */
46
+ isSubscribed: boolean;
47
+ /** Whether the handle can still be brought back to sending. False only once released. */
48
+ isHandleAlive: boolean;
49
+ isStarted: boolean;
50
+ isPaused: boolean;
51
+ isInForeground: boolean;
52
+ };
53
+
54
+ export type WatchPositionParams = {
55
+ profile?: LocationProfile;
56
+ onPosition: (position: Position) => void;
57
+ onError?: (error: PositionWatchError) => void;
58
+ };
@@ -0,0 +1,3 @@
1
+ export * from './Position.types';
2
+ export * from './Permissions.types';
3
+ export * from './LocationProvider.types';
@@ -1 +0,0 @@
1
- 9b18faeb56470f2f1d68419c7f23630301ea8b61565b1e8d4973a29b781ec712
@@ -1 +0,0 @@
1
- e03034e003f2d8317f21d942444c429d51db50f8bacc38ffcbb0846945dc3eb6e4af7e653a4a99a609a969201c96f072bf021f022f1d3fa8874dbbe8185c07cb
@@ -1 +0,0 @@
1
- e77f2b978e01d419b6ebc6645f5de9e76325d79e8c86a2f2386585aeccf8d4b8
@@ -1 +0,0 @@
1
- 7433c354aa7c717458927782ee3bd1503a33f913c388d5b8180301071a3278c34dcd21d29b5248557168084edeee8ad9e1ce5338f1a5ad81eb760a1fc8c66ff3