@symbiote-native/location 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +193 -0
- package/build/angular/index.d.ts +1 -0
- package/build/angular/index.js +4 -0
- package/build/core/index.d.ts +5 -0
- package/build/core/index.js +5 -0
- package/build/core/location.d.ts +39 -0
- package/build/core/location.js +204 -0
- package/build/core/native-module.d.ts +31 -0
- package/build/core/native-module.js +3 -0
- package/build/core/subscribers.d.ts +23 -0
- package/build/core/subscribers.js +65 -0
- package/build/core/types.d.ts +160 -0
- package/build/core/types.js +44 -0
- package/build-ngc/angular/index.d.ts +1 -0
- package/build-ngc/angular/index.js +5 -0
- package/build-ngc/angular/index.js.map +1 -0
- package/build-ngc/core/index.d.ts +5 -0
- package/build-ngc/core/index.js +6 -0
- package/build-ngc/core/index.js.map +1 -0
- package/build-ngc/core/location.d.ts +39 -0
- package/build-ngc/core/location.js +205 -0
- package/build-ngc/core/location.js.map +1 -0
- package/build-ngc/core/native-module.d.ts +31 -0
- package/build-ngc/core/native-module.js +4 -0
- package/build-ngc/core/native-module.js.map +1 -0
- package/build-ngc/core/subscribers.d.ts +23 -0
- package/build-ngc/core/subscribers.js +66 -0
- package/build-ngc/core/subscribers.js.map +1 -0
- package/build-ngc/core/types.d.ts +160 -0
- package/build-ngc/core/types.js +45 -0
- package/build-ngc/core/types.js.map +1 -0
- package/native-link.json +40 -0
- package/package.json +151 -0
- package/src/angular/index.ts +4 -0
- package/src/core/index.ts +17 -0
- package/src/core/location.ts +313 -0
- package/src/core/native-module.ts +62 -0
- package/src/core/subscribers.ts +101 -0
- package/src/core/types.ts +191 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { PermissionResponse } from 'expo-modules-core';
|
|
2
|
+
export declare enum LocationAccuracy {
|
|
3
|
+
Lowest = 1,
|
|
4
|
+
Low = 2,
|
|
5
|
+
Balanced = 3,
|
|
6
|
+
High = 4,
|
|
7
|
+
Highest = 5,
|
|
8
|
+
BestForNavigation = 6
|
|
9
|
+
}
|
|
10
|
+
export declare enum LocationActivityType {
|
|
11
|
+
Other = 1,
|
|
12
|
+
AutomotiveNavigation = 2,
|
|
13
|
+
Fitness = 3,
|
|
14
|
+
OtherNavigation = 4,
|
|
15
|
+
/** @platform ios */
|
|
16
|
+
Airborne = 5
|
|
17
|
+
}
|
|
18
|
+
export declare enum LocationGeofencingEventType {
|
|
19
|
+
Enter = 1,
|
|
20
|
+
Exit = 2
|
|
21
|
+
}
|
|
22
|
+
export declare enum LocationGeofencingRegionState {
|
|
23
|
+
Unknown = 0,
|
|
24
|
+
Inside = 1,
|
|
25
|
+
Outside = 2
|
|
26
|
+
}
|
|
27
|
+
export type ILocationOptions = {
|
|
28
|
+
accuracy?: LocationAccuracy;
|
|
29
|
+
/** @platform android */
|
|
30
|
+
mayShowUserSettingsDialog?: boolean;
|
|
31
|
+
/** @platform android */
|
|
32
|
+
timeInterval?: number;
|
|
33
|
+
distanceInterval?: number;
|
|
34
|
+
};
|
|
35
|
+
export type ILocationLastKnownOptions = {
|
|
36
|
+
maxAge?: number;
|
|
37
|
+
requiredAccuracy?: number;
|
|
38
|
+
};
|
|
39
|
+
export type ILocationTaskServiceOptions = {
|
|
40
|
+
notificationTitle: string;
|
|
41
|
+
notificationBody: string;
|
|
42
|
+
notificationColor?: string;
|
|
43
|
+
killServiceOnDestroy?: boolean;
|
|
44
|
+
};
|
|
45
|
+
export type ILocationTaskOptions = ILocationOptions & {
|
|
46
|
+
/** @platform ios */
|
|
47
|
+
showsBackgroundLocationIndicator?: boolean;
|
|
48
|
+
deferredUpdatesDistance?: number;
|
|
49
|
+
deferredUpdatesTimeout?: number;
|
|
50
|
+
deferredUpdatesInterval?: number;
|
|
51
|
+
/** @platform ios */
|
|
52
|
+
activityType?: LocationActivityType;
|
|
53
|
+
/** @platform ios */
|
|
54
|
+
pausesUpdatesAutomatically?: boolean;
|
|
55
|
+
foregroundService?: ILocationTaskServiceOptions;
|
|
56
|
+
};
|
|
57
|
+
export type ILocationRegion = {
|
|
58
|
+
identifier?: string;
|
|
59
|
+
latitude: number;
|
|
60
|
+
longitude: number;
|
|
61
|
+
radius: number;
|
|
62
|
+
/** @default true */
|
|
63
|
+
notifyOnEnter?: boolean;
|
|
64
|
+
/** @default true */
|
|
65
|
+
notifyOnExit?: boolean;
|
|
66
|
+
state?: LocationGeofencingRegionState;
|
|
67
|
+
};
|
|
68
|
+
export type ILocationObjectCoords = {
|
|
69
|
+
latitude: number;
|
|
70
|
+
longitude: number;
|
|
71
|
+
altitude: number | null;
|
|
72
|
+
accuracy: number | null;
|
|
73
|
+
altitudeAccuracy: number | null;
|
|
74
|
+
heading: number | null;
|
|
75
|
+
speed: number | null;
|
|
76
|
+
};
|
|
77
|
+
export type ILocationObject = {
|
|
78
|
+
coords: ILocationObjectCoords;
|
|
79
|
+
timestamp: number;
|
|
80
|
+
/** @platform android */
|
|
81
|
+
mocked?: boolean;
|
|
82
|
+
};
|
|
83
|
+
export type ILocationCallback = (location: ILocationObject) => unknown;
|
|
84
|
+
export type ILocationErrorCallback = (reason: string) => void;
|
|
85
|
+
export type ILocationProviderStatus = {
|
|
86
|
+
locationServicesEnabled: boolean;
|
|
87
|
+
backgroundModeEnabled: boolean;
|
|
88
|
+
/** @platform android */
|
|
89
|
+
gpsAvailable?: boolean;
|
|
90
|
+
/** @platform android */
|
|
91
|
+
networkAvailable?: boolean;
|
|
92
|
+
/** @platform android */
|
|
93
|
+
passiveAvailable?: boolean;
|
|
94
|
+
};
|
|
95
|
+
export type ILocationHeadingObject = {
|
|
96
|
+
trueHeading: number;
|
|
97
|
+
magHeading: number;
|
|
98
|
+
/** 0 none, 1 low, 2 medium, 3 high */
|
|
99
|
+
accuracy: number;
|
|
100
|
+
};
|
|
101
|
+
export type ILocationHeadingCallback = (heading: ILocationHeadingObject) => unknown;
|
|
102
|
+
export type ILocationGeocodedLocation = {
|
|
103
|
+
latitude: number;
|
|
104
|
+
longitude: number;
|
|
105
|
+
altitude?: number;
|
|
106
|
+
accuracy?: number;
|
|
107
|
+
};
|
|
108
|
+
export type ILocationGeocodedAddress = {
|
|
109
|
+
city: string | null;
|
|
110
|
+
district: string | null;
|
|
111
|
+
streetNumber: string | null;
|
|
112
|
+
street: string | null;
|
|
113
|
+
region: string | null;
|
|
114
|
+
subregion: string | null;
|
|
115
|
+
country: string | null;
|
|
116
|
+
postalCode: string | null;
|
|
117
|
+
name: string | null;
|
|
118
|
+
isoCountryCode: string | null;
|
|
119
|
+
/** @platform ios */
|
|
120
|
+
timezone: string | null;
|
|
121
|
+
/** @platform android */
|
|
122
|
+
formattedAddress: string | null;
|
|
123
|
+
};
|
|
124
|
+
export type ILocationSubscription = {
|
|
125
|
+
remove: () => void;
|
|
126
|
+
};
|
|
127
|
+
export type IPermissionDetailsLocationIOS = {
|
|
128
|
+
scope: 'whenInUse' | 'always' | 'none';
|
|
129
|
+
accuracy: 'full' | 'reduced';
|
|
130
|
+
};
|
|
131
|
+
export type IPermissionDetailsLocationAndroid = {
|
|
132
|
+
accuracy: 'fine' | 'coarse' | 'none';
|
|
133
|
+
};
|
|
134
|
+
export type ILocationPermissionResponse = PermissionResponse & {
|
|
135
|
+
ios?: IPermissionDetailsLocationIOS;
|
|
136
|
+
android?: IPermissionDetailsLocationAndroid;
|
|
137
|
+
};
|
|
138
|
+
export type { PermissionResponse };
|
|
139
|
+
export declare enum MotionActivityConfidence {
|
|
140
|
+
Low = 0,
|
|
141
|
+
Medium = 1,
|
|
142
|
+
High = 2
|
|
143
|
+
}
|
|
144
|
+
export declare enum MotionActivityType {
|
|
145
|
+
Automotive = "automotive",
|
|
146
|
+
Cycling = "cycling",
|
|
147
|
+
Running = "running",
|
|
148
|
+
Walking = "walking",
|
|
149
|
+
Stationary = "stationary",
|
|
150
|
+
Unknown = "unknown"
|
|
151
|
+
}
|
|
152
|
+
export type IMotionActivityState = {
|
|
153
|
+
detected: boolean;
|
|
154
|
+
confidence: MotionActivityConfidence;
|
|
155
|
+
};
|
|
156
|
+
export type IMotionActivityObject = {
|
|
157
|
+
activities: Record<MotionActivityType, IMotionActivityState>;
|
|
158
|
+
timestamp: number;
|
|
159
|
+
};
|
|
160
|
+
export type IMotionActivityCallback = (activity: IMotionActivityObject) => unknown;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export var LocationAccuracy;
|
|
2
|
+
(function (LocationAccuracy) {
|
|
3
|
+
LocationAccuracy[LocationAccuracy["Lowest"] = 1] = "Lowest";
|
|
4
|
+
LocationAccuracy[LocationAccuracy["Low"] = 2] = "Low";
|
|
5
|
+
LocationAccuracy[LocationAccuracy["Balanced"] = 3] = "Balanced";
|
|
6
|
+
LocationAccuracy[LocationAccuracy["High"] = 4] = "High";
|
|
7
|
+
LocationAccuracy[LocationAccuracy["Highest"] = 5] = "Highest";
|
|
8
|
+
LocationAccuracy[LocationAccuracy["BestForNavigation"] = 6] = "BestForNavigation";
|
|
9
|
+
})(LocationAccuracy || (LocationAccuracy = {}));
|
|
10
|
+
export var LocationActivityType;
|
|
11
|
+
(function (LocationActivityType) {
|
|
12
|
+
LocationActivityType[LocationActivityType["Other"] = 1] = "Other";
|
|
13
|
+
LocationActivityType[LocationActivityType["AutomotiveNavigation"] = 2] = "AutomotiveNavigation";
|
|
14
|
+
LocationActivityType[LocationActivityType["Fitness"] = 3] = "Fitness";
|
|
15
|
+
LocationActivityType[LocationActivityType["OtherNavigation"] = 4] = "OtherNavigation";
|
|
16
|
+
/** @platform ios */
|
|
17
|
+
LocationActivityType[LocationActivityType["Airborne"] = 5] = "Airborne";
|
|
18
|
+
})(LocationActivityType || (LocationActivityType = {}));
|
|
19
|
+
export var LocationGeofencingEventType;
|
|
20
|
+
(function (LocationGeofencingEventType) {
|
|
21
|
+
LocationGeofencingEventType[LocationGeofencingEventType["Enter"] = 1] = "Enter";
|
|
22
|
+
LocationGeofencingEventType[LocationGeofencingEventType["Exit"] = 2] = "Exit";
|
|
23
|
+
})(LocationGeofencingEventType || (LocationGeofencingEventType = {}));
|
|
24
|
+
export var LocationGeofencingRegionState;
|
|
25
|
+
(function (LocationGeofencingRegionState) {
|
|
26
|
+
LocationGeofencingRegionState[LocationGeofencingRegionState["Unknown"] = 0] = "Unknown";
|
|
27
|
+
LocationGeofencingRegionState[LocationGeofencingRegionState["Inside"] = 1] = "Inside";
|
|
28
|
+
LocationGeofencingRegionState[LocationGeofencingRegionState["Outside"] = 2] = "Outside";
|
|
29
|
+
})(LocationGeofencingRegionState || (LocationGeofencingRegionState = {}));
|
|
30
|
+
export var MotionActivityConfidence;
|
|
31
|
+
(function (MotionActivityConfidence) {
|
|
32
|
+
MotionActivityConfidence[MotionActivityConfidence["Low"] = 0] = "Low";
|
|
33
|
+
MotionActivityConfidence[MotionActivityConfidence["Medium"] = 1] = "Medium";
|
|
34
|
+
MotionActivityConfidence[MotionActivityConfidence["High"] = 2] = "High";
|
|
35
|
+
})(MotionActivityConfidence || (MotionActivityConfidence = {}));
|
|
36
|
+
export var MotionActivityType;
|
|
37
|
+
(function (MotionActivityType) {
|
|
38
|
+
MotionActivityType["Automotive"] = "automotive";
|
|
39
|
+
MotionActivityType["Cycling"] = "cycling";
|
|
40
|
+
MotionActivityType["Running"] = "running";
|
|
41
|
+
MotionActivityType["Walking"] = "walking";
|
|
42
|
+
MotionActivityType["Stationary"] = "stationary";
|
|
43
|
+
MotionActivityType["Unknown"] = "unknown";
|
|
44
|
+
})(MotionActivityType || (MotionActivityType = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../core';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @symbiote-native/location/angular: the Angular entry over the framework-agnostic core. Same
|
|
2
|
+
// reasoning as the React/Vue entries — no per-instance state or event stream to wrap in a
|
|
3
|
+
// service, so this is a plain re-export.
|
|
4
|
+
export * from '../core';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/angular/index.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,0FAA0F;AAC1F,yCAAyC;AACzC,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { PermissionStatus, type PermissionHookOptions, type PermissionExpiration, } from 'expo-modules-core';
|
|
2
|
+
export { getCurrentWatchId } from './subscribers';
|
|
3
|
+
export * from './location';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export { LocationAccuracy as Accuracy, LocationActivityType as ActivityType, LocationGeofencingEventType as GeofencingEventType, LocationGeofencingRegionState as GeofencingRegionState, } from './types';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { PermissionStatus, } from 'expo-modules-core';
|
|
2
|
+
export { getCurrentWatchId } from './subscribers';
|
|
3
|
+
export * from './location';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export { LocationAccuracy as Accuracy, LocationActivityType as ActivityType, LocationGeofencingEventType as GeofencingEventType, LocationGeofencingRegionState as GeofencingRegionState, } from './types';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAGjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,gBAAgB,IAAI,QAAQ,EAC5B,oBAAoB,IAAI,YAAY,EACpC,2BAA2B,IAAI,mBAAmB,EAClD,6BAA6B,IAAI,qBAAqB,GACvD,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ILocationCallback, ILocationErrorCallback, ILocationGeocodedAddress, ILocationGeocodedLocation, ILocationHeadingCallback, ILocationHeadingObject, ILocationLastKnownOptions, ILocationObject, ILocationOptions, ILocationPermissionResponse, ILocationProviderStatus, ILocationRegion, ILocationSubscription, ILocationTaskOptions, IMotionActivityCallback, IMotionActivityObject, PermissionResponse } from './types';
|
|
2
|
+
export declare function getProviderStatusAsync(): Promise<ILocationProviderStatus>;
|
|
3
|
+
/** @platform android */
|
|
4
|
+
export declare function enableNetworkProviderAsync(): Promise<void>;
|
|
5
|
+
export declare function getCurrentPositionAsync(options?: ILocationOptions): Promise<ILocationObject>;
|
|
6
|
+
export declare function getLastKnownPositionAsync(options?: ILocationLastKnownOptions): Promise<ILocationObject | null>;
|
|
7
|
+
export declare function watchPositionAsync(options: ILocationOptions, callback: ILocationCallback, errorHandler?: ILocationErrorCallback): Promise<ILocationSubscription>;
|
|
8
|
+
export declare function watchHeadingAsync(callback: ILocationHeadingCallback, errorHandler?: ILocationErrorCallback): Promise<ILocationSubscription>;
|
|
9
|
+
/** Waits for a couple of heading updates and returns the first accurate-enough one. */
|
|
10
|
+
export declare function getHeadingAsync(): Promise<ILocationHeadingObject>;
|
|
11
|
+
export declare function geocodeAsync(address: string): Promise<ILocationGeocodedLocation[]>;
|
|
12
|
+
export declare function reverseGeocodeAsync(location: Pick<ILocationGeocodedLocation, 'latitude' | 'longitude'>): Promise<ILocationGeocodedAddress[]>;
|
|
13
|
+
export declare function getForegroundPermissionsAsync(): Promise<ILocationPermissionResponse>;
|
|
14
|
+
export declare function requestForegroundPermissionsAsync(): Promise<ILocationPermissionResponse>;
|
|
15
|
+
export declare const useForegroundPermissions: (options?: import("expo-modules-core").PermissionHookOptions<object> | undefined) => [ILocationPermissionResponse | null, () => Promise<ILocationPermissionResponse>, () => Promise<ILocationPermissionResponse>];
|
|
16
|
+
export declare function getBackgroundPermissionsAsync(): Promise<PermissionResponse>;
|
|
17
|
+
export declare function requestBackgroundPermissionsAsync(): Promise<PermissionResponse>;
|
|
18
|
+
export declare const useBackgroundPermissions: (options?: import("expo-modules-core").PermissionHookOptions<object> | undefined) => [PermissionResponse | null, () => Promise<PermissionResponse>, () => Promise<PermissionResponse>];
|
|
19
|
+
export declare function hasServicesEnabledAsync(): Promise<boolean>;
|
|
20
|
+
export declare function getMotionActivityPermissionsAsync(): Promise<PermissionResponse>;
|
|
21
|
+
export declare function requestMotionActivityPermissionsAsync(): Promise<PermissionResponse>;
|
|
22
|
+
export declare const useMotionActivityPermissions: (options?: import("expo-modules-core").PermissionHookOptions<object> | undefined) => [PermissionResponse | null, () => Promise<PermissionResponse>, () => Promise<PermissionResponse>];
|
|
23
|
+
/** No location permission required — uses Play Services activity recognition / the iOS motion
|
|
24
|
+
* coprocessor directly. */
|
|
25
|
+
export declare function getMotionActivityAsync(): Promise<IMotionActivityObject>;
|
|
26
|
+
/** Foreground-only — updates pause while the app is backgrounded. */
|
|
27
|
+
export declare function watchMotionActivityAsync(callback: IMotionActivityCallback, errorHandler?: ILocationErrorCallback): Promise<ILocationSubscription>;
|
|
28
|
+
export declare function isBackgroundLocationAvailableAsync(): Promise<boolean>;
|
|
29
|
+
/** Register a task (defined with `@symbiote-native/task-manager`'s `defineTask`) to keep
|
|
30
|
+
* receiving location updates while the app is backgrounded. */
|
|
31
|
+
export declare function startLocationUpdatesAsync(taskName: string, options?: ILocationTaskOptions): Promise<void>;
|
|
32
|
+
export declare function stopLocationUpdatesAsync(taskName: string): Promise<void>;
|
|
33
|
+
export declare function hasStartedLocationUpdatesAsync(taskName: string): Promise<boolean>;
|
|
34
|
+
/** Register a task (defined with `@symbiote-native/task-manager`'s `defineTask`) to receive
|
|
35
|
+
* enter/exit events for the given regions, including while the app is backgrounded. Calling
|
|
36
|
+
* this again with a new region array replaces the regions already being watched. */
|
|
37
|
+
export declare function startGeofencingAsync(taskName: string, regions?: ILocationRegion[]): Promise<void>;
|
|
38
|
+
export declare function stopGeofencingAsync(taskName: string): Promise<void>;
|
|
39
|
+
export declare function hasStartedGeofencingAsync(taskName: string): Promise<boolean>;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { createPermissionHook, Platform } from 'expo-modules-core';
|
|
2
|
+
import { expoLocation } from './native-module';
|
|
3
|
+
import { headingSubscriber, locationErrorSubscriber, locationSubscriber, motionActivitySubscriber, } from './subscribers';
|
|
4
|
+
import { LocationAccuracy } from './types';
|
|
5
|
+
export async function getProviderStatusAsync() {
|
|
6
|
+
return expoLocation.getProviderStatusAsync();
|
|
7
|
+
}
|
|
8
|
+
/** @platform android */
|
|
9
|
+
export async function enableNetworkProviderAsync() {
|
|
10
|
+
if (Platform.OS === 'android') {
|
|
11
|
+
return expoLocation.enableNetworkProviderAsync();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export async function getCurrentPositionAsync(options = {}) {
|
|
15
|
+
return expoLocation.getCurrentPositionAsync(options);
|
|
16
|
+
}
|
|
17
|
+
export async function getLastKnownPositionAsync(options = {}) {
|
|
18
|
+
return expoLocation.getLastKnownPositionAsync(options);
|
|
19
|
+
}
|
|
20
|
+
export async function watchPositionAsync(options, callback, errorHandler) {
|
|
21
|
+
const watchId = locationSubscriber.registerCallback(callback);
|
|
22
|
+
if (errorHandler)
|
|
23
|
+
locationErrorSubscriber.registerCallbackForId(watchId, errorHandler);
|
|
24
|
+
await expoLocation.watchPositionImplAsync(watchId, options);
|
|
25
|
+
return {
|
|
26
|
+
remove() {
|
|
27
|
+
locationSubscriber.unregisterCallback(watchId);
|
|
28
|
+
if (errorHandler)
|
|
29
|
+
locationErrorSubscriber.unregisterCallback(watchId);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export async function watchHeadingAsync(callback, errorHandler) {
|
|
34
|
+
const watchId = headingSubscriber.registerCallback(callback);
|
|
35
|
+
if (errorHandler)
|
|
36
|
+
locationErrorSubscriber.registerCallbackForId(watchId, errorHandler);
|
|
37
|
+
await expoLocation.watchDeviceHeading(watchId);
|
|
38
|
+
return {
|
|
39
|
+
remove() {
|
|
40
|
+
headingSubscriber.unregisterCallback(watchId);
|
|
41
|
+
if (errorHandler)
|
|
42
|
+
locationErrorSubscriber.unregisterCallback(watchId);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Waits for a couple of heading updates and returns the first accurate-enough one. */
|
|
47
|
+
export async function getHeadingAsync() {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
let tries = 0;
|
|
50
|
+
let subscriber;
|
|
51
|
+
watchHeadingAsync(heading => {
|
|
52
|
+
if (heading.accuracy > 1 || tries > 5) {
|
|
53
|
+
subscriber?.remove();
|
|
54
|
+
resolve(heading);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
tries += 1;
|
|
58
|
+
}
|
|
59
|
+
}, reason => {
|
|
60
|
+
subscriber?.remove();
|
|
61
|
+
reject(new Error(reason));
|
|
62
|
+
})
|
|
63
|
+
.then(sub => {
|
|
64
|
+
subscriber = sub;
|
|
65
|
+
})
|
|
66
|
+
.catch(reject);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
export async function geocodeAsync(address) {
|
|
70
|
+
if (typeof address !== 'string') {
|
|
71
|
+
throw new TypeError(`Address to geocode must be a string. Got ${address} instead.`);
|
|
72
|
+
}
|
|
73
|
+
return expoLocation.geocodeAsync(address);
|
|
74
|
+
}
|
|
75
|
+
export async function reverseGeocodeAsync(location) {
|
|
76
|
+
if (typeof location.latitude !== 'number' ||
|
|
77
|
+
typeof location.longitude !== 'number') {
|
|
78
|
+
throw new TypeError('Location to reverse-geocode must be an object with number properties `latitude` and `longitude`.');
|
|
79
|
+
}
|
|
80
|
+
return expoLocation.reverseGeocodeAsync(location);
|
|
81
|
+
}
|
|
82
|
+
export async function getForegroundPermissionsAsync() {
|
|
83
|
+
return expoLocation.getForegroundPermissionsAsync();
|
|
84
|
+
}
|
|
85
|
+
export async function requestForegroundPermissionsAsync() {
|
|
86
|
+
return expoLocation.requestForegroundPermissionsAsync();
|
|
87
|
+
}
|
|
88
|
+
export const useForegroundPermissions = createPermissionHook({
|
|
89
|
+
getMethod: getForegroundPermissionsAsync,
|
|
90
|
+
requestMethod: requestForegroundPermissionsAsync,
|
|
91
|
+
});
|
|
92
|
+
export async function getBackgroundPermissionsAsync() {
|
|
93
|
+
return expoLocation.getBackgroundPermissionsAsync();
|
|
94
|
+
}
|
|
95
|
+
export async function requestBackgroundPermissionsAsync() {
|
|
96
|
+
return expoLocation.requestBackgroundPermissionsAsync();
|
|
97
|
+
}
|
|
98
|
+
export const useBackgroundPermissions = createPermissionHook({
|
|
99
|
+
getMethod: getBackgroundPermissionsAsync,
|
|
100
|
+
requestMethod: requestBackgroundPermissionsAsync,
|
|
101
|
+
});
|
|
102
|
+
export async function hasServicesEnabledAsync() {
|
|
103
|
+
return expoLocation.hasServicesEnabledAsync();
|
|
104
|
+
}
|
|
105
|
+
export async function getMotionActivityPermissionsAsync() {
|
|
106
|
+
return expoLocation.getMotionActivityPermissionsAsync();
|
|
107
|
+
}
|
|
108
|
+
export async function requestMotionActivityPermissionsAsync() {
|
|
109
|
+
return expoLocation.requestMotionActivityPermissionsAsync();
|
|
110
|
+
}
|
|
111
|
+
export const useMotionActivityPermissions = createPermissionHook({
|
|
112
|
+
getMethod: getMotionActivityPermissionsAsync,
|
|
113
|
+
requestMethod: requestMotionActivityPermissionsAsync,
|
|
114
|
+
});
|
|
115
|
+
/** No location permission required — uses Play Services activity recognition / the iOS motion
|
|
116
|
+
* coprocessor directly. */
|
|
117
|
+
export async function getMotionActivityAsync() {
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
let subscriber;
|
|
120
|
+
watchMotionActivityAsync(activity => {
|
|
121
|
+
subscriber?.remove();
|
|
122
|
+
resolve(activity);
|
|
123
|
+
}, reason => {
|
|
124
|
+
subscriber?.remove();
|
|
125
|
+
reject(new Error(reason));
|
|
126
|
+
})
|
|
127
|
+
.then(sub => {
|
|
128
|
+
subscriber = sub;
|
|
129
|
+
})
|
|
130
|
+
.catch(reject);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/** Foreground-only — updates pause while the app is backgrounded. */
|
|
134
|
+
export async function watchMotionActivityAsync(callback, errorHandler) {
|
|
135
|
+
const watchId = motionActivitySubscriber.registerCallback(callback);
|
|
136
|
+
if (errorHandler)
|
|
137
|
+
locationErrorSubscriber.registerCallbackForId(watchId, errorHandler);
|
|
138
|
+
await expoLocation.watchMotionActivityImplAsync(watchId);
|
|
139
|
+
return {
|
|
140
|
+
remove() {
|
|
141
|
+
motionActivitySubscriber.unregisterCallback(watchId);
|
|
142
|
+
// forgetCallback, not unregisterCallback: the native watch was already torn down above by
|
|
143
|
+
// motionActivitySubscriber; re-issuing removeWatchAsync for the same id would hit this
|
|
144
|
+
// native module's location-permission guard and throw for a motion-activity-only caller.
|
|
145
|
+
if (errorHandler)
|
|
146
|
+
locationErrorSubscriber.forgetCallback(watchId);
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function assertValidTaskName(taskName) {
|
|
151
|
+
if (!taskName || typeof taskName !== 'string') {
|
|
152
|
+
throw new Error(`\`taskName\` must be a non-empty string. Got ${taskName} instead.`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function assertValidRegions(regions) {
|
|
156
|
+
if (!regions || regions.length === 0) {
|
|
157
|
+
throw new Error('Regions array cannot be empty. Use `stopGeofencingAsync` if you want to stop geofencing all regions');
|
|
158
|
+
}
|
|
159
|
+
for (const region of regions) {
|
|
160
|
+
if (typeof region.latitude !== 'number') {
|
|
161
|
+
throw new TypeError(`Region's latitude must be a number. Got '${region.latitude}' instead.`);
|
|
162
|
+
}
|
|
163
|
+
if (typeof region.longitude !== 'number') {
|
|
164
|
+
throw new TypeError(`Region's longitude must be a number. Got '${region.longitude}' instead.`);
|
|
165
|
+
}
|
|
166
|
+
if (typeof region.radius !== 'number') {
|
|
167
|
+
throw new TypeError(`Region's radius must be a number. Got '${region.radius}' instead.`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
export async function isBackgroundLocationAvailableAsync() {
|
|
172
|
+
const providerStatus = await getProviderStatusAsync();
|
|
173
|
+
return providerStatus.backgroundModeEnabled;
|
|
174
|
+
}
|
|
175
|
+
/** Register a task (defined with `@symbiote-native/task-manager`'s `defineTask`) to keep
|
|
176
|
+
* receiving location updates while the app is backgrounded. */
|
|
177
|
+
export async function startLocationUpdatesAsync(taskName, options = { accuracy: LocationAccuracy.Balanced }) {
|
|
178
|
+
assertValidTaskName(taskName);
|
|
179
|
+
await expoLocation.startLocationUpdatesAsync(taskName, options);
|
|
180
|
+
}
|
|
181
|
+
export async function stopLocationUpdatesAsync(taskName) {
|
|
182
|
+
assertValidTaskName(taskName);
|
|
183
|
+
await expoLocation.stopLocationUpdatesAsync(taskName);
|
|
184
|
+
}
|
|
185
|
+
export async function hasStartedLocationUpdatesAsync(taskName) {
|
|
186
|
+
assertValidTaskName(taskName);
|
|
187
|
+
return expoLocation.hasStartedLocationUpdatesAsync(taskName);
|
|
188
|
+
}
|
|
189
|
+
/** Register a task (defined with `@symbiote-native/task-manager`'s `defineTask`) to receive
|
|
190
|
+
* enter/exit events for the given regions, including while the app is backgrounded. Calling
|
|
191
|
+
* this again with a new region array replaces the regions already being watched. */
|
|
192
|
+
export async function startGeofencingAsync(taskName, regions = []) {
|
|
193
|
+
assertValidTaskName(taskName);
|
|
194
|
+
assertValidRegions(regions);
|
|
195
|
+
await expoLocation.startGeofencingAsync(taskName, { regions });
|
|
196
|
+
}
|
|
197
|
+
export async function stopGeofencingAsync(taskName) {
|
|
198
|
+
assertValidTaskName(taskName);
|
|
199
|
+
await expoLocation.stopGeofencingAsync(taskName);
|
|
200
|
+
}
|
|
201
|
+
export async function hasStartedGeofencingAsync(taskName) {
|
|
202
|
+
assertValidTaskName(taskName);
|
|
203
|
+
return expoLocation.hasStartedGeofencingAsync(taskName);
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=location.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location.js","sourceRoot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|
|
2
|
+
import type { ILocationGeocodedAddress, ILocationGeocodedLocation, ILocationLastKnownOptions, ILocationObject, ILocationOptions, ILocationPermissionResponse, ILocationProviderStatus, ILocationRegion, ILocationTaskOptions, PermissionResponse } from './types';
|
|
3
|
+
export type INativeLocationModule = {
|
|
4
|
+
addListener(eventName: string, listener: (event: unknown) => void): EventSubscription;
|
|
5
|
+
getProviderStatusAsync(): Promise<ILocationProviderStatus>;
|
|
6
|
+
enableNetworkProviderAsync(): Promise<void>;
|
|
7
|
+
getCurrentPositionAsync(options: ILocationOptions): Promise<ILocationObject>;
|
|
8
|
+
getLastKnownPositionAsync(options: ILocationLastKnownOptions): Promise<ILocationObject | null>;
|
|
9
|
+
watchPositionImplAsync(watchId: number, options: ILocationOptions): Promise<void>;
|
|
10
|
+
watchDeviceHeading(watchId: number): Promise<void>;
|
|
11
|
+
removeWatchAsync(watchId: number): Promise<void>;
|
|
12
|
+
geocodeAsync(address: string): Promise<ILocationGeocodedLocation[]>;
|
|
13
|
+
reverseGeocodeAsync(location: Pick<ILocationGeocodedLocation, 'latitude' | 'longitude'>): Promise<ILocationGeocodedAddress[]>;
|
|
14
|
+
getForegroundPermissionsAsync(): Promise<ILocationPermissionResponse>;
|
|
15
|
+
requestForegroundPermissionsAsync(): Promise<ILocationPermissionResponse>;
|
|
16
|
+
getBackgroundPermissionsAsync(): Promise<PermissionResponse>;
|
|
17
|
+
requestBackgroundPermissionsAsync(): Promise<PermissionResponse>;
|
|
18
|
+
hasServicesEnabledAsync(): Promise<boolean>;
|
|
19
|
+
getMotionActivityPermissionsAsync(): Promise<PermissionResponse>;
|
|
20
|
+
requestMotionActivityPermissionsAsync(): Promise<PermissionResponse>;
|
|
21
|
+
watchMotionActivityImplAsync(watchId: number): Promise<void>;
|
|
22
|
+
startLocationUpdatesAsync(taskName: string, options: ILocationTaskOptions): Promise<void>;
|
|
23
|
+
stopLocationUpdatesAsync(taskName: string): Promise<void>;
|
|
24
|
+
hasStartedLocationUpdatesAsync(taskName: string): Promise<boolean>;
|
|
25
|
+
startGeofencingAsync(taskName: string, options: {
|
|
26
|
+
regions: ILocationRegion[];
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
stopGeofencingAsync(taskName: string): Promise<void>;
|
|
29
|
+
hasStartedGeofencingAsync(taskName: string): Promise<boolean>;
|
|
30
|
+
};
|
|
31
|
+
export declare const expoLocation: INativeLocationModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-module.js","sourceRoot":"","sources":["../../src/core/native-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAA0B,MAAM,mBAAmB,CAAC;AAchF,MAAM,yBAAyB,GAAG,cAAc,CAAC;AA6CjD,MAAM,CAAC,MAAM,YAAY,GAAG,mBAAmB,CAC7C,yBAAyB,CAC1B,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ILocationCallback, ILocationErrorCallback, ILocationHeadingCallback, IMotionActivityCallback } from './types';
|
|
2
|
+
declare class Subscriber<TCallback extends ILocationCallback | ILocationHeadingCallback | ILocationErrorCallback | IMotionActivityCallback> {
|
|
3
|
+
private eventName;
|
|
4
|
+
private eventDataField;
|
|
5
|
+
private callbacks;
|
|
6
|
+
private eventSubscription;
|
|
7
|
+
constructor(eventName: string, eventDataField: string);
|
|
8
|
+
private maybeInitializeSubscription;
|
|
9
|
+
registerCallback(callback: TCallback): number;
|
|
10
|
+
registerCallbackForId(watchId: number, callback: TCallback): number;
|
|
11
|
+
unregisterCallback(id: number): void;
|
|
12
|
+
/** Drops the local callback without calling native removeWatchAsync — used when another
|
|
13
|
+
* subscriber already tore down the same watchId natively. */
|
|
14
|
+
forgetCallback(id: number): void;
|
|
15
|
+
private releaseSubscriptionIfIdle;
|
|
16
|
+
private trigger;
|
|
17
|
+
}
|
|
18
|
+
export declare const locationSubscriber: Subscriber<ILocationCallback>;
|
|
19
|
+
export declare const headingSubscriber: Subscriber<ILocationHeadingCallback>;
|
|
20
|
+
export declare const locationErrorSubscriber: Subscriber<ILocationErrorCallback>;
|
|
21
|
+
export declare const motionActivitySubscriber: Subscriber<IMotionActivityCallback>;
|
|
22
|
+
export declare function getCurrentWatchId(): number;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { expoLocation } from './native-module';
|
|
2
|
+
let nextWatchId = 0;
|
|
3
|
+
class Subscriber {
|
|
4
|
+
eventName;
|
|
5
|
+
eventDataField;
|
|
6
|
+
callbacks = {};
|
|
7
|
+
eventSubscription = null;
|
|
8
|
+
constructor(eventName, eventDataField) {
|
|
9
|
+
this.eventName = eventName;
|
|
10
|
+
this.eventDataField = eventDataField;
|
|
11
|
+
}
|
|
12
|
+
maybeInitializeSubscription() {
|
|
13
|
+
if (this.eventSubscription)
|
|
14
|
+
return;
|
|
15
|
+
this.eventSubscription = expoLocation.addListener(this.eventName, (event) => this.trigger(event));
|
|
16
|
+
}
|
|
17
|
+
registerCallback(callback) {
|
|
18
|
+
this.maybeInitializeSubscription();
|
|
19
|
+
const id = ++nextWatchId;
|
|
20
|
+
this.callbacks[id] = callback;
|
|
21
|
+
return id;
|
|
22
|
+
}
|
|
23
|
+
registerCallbackForId(watchId, callback) {
|
|
24
|
+
this.maybeInitializeSubscription();
|
|
25
|
+
this.callbacks[watchId] = callback;
|
|
26
|
+
return watchId;
|
|
27
|
+
}
|
|
28
|
+
unregisterCallback(id) {
|
|
29
|
+
if (!this.callbacks[id])
|
|
30
|
+
return;
|
|
31
|
+
delete this.callbacks[id];
|
|
32
|
+
void expoLocation.removeWatchAsync(id);
|
|
33
|
+
this.releaseSubscriptionIfIdle();
|
|
34
|
+
}
|
|
35
|
+
/** Drops the local callback without calling native removeWatchAsync — used when another
|
|
36
|
+
* subscriber already tore down the same watchId natively. */
|
|
37
|
+
forgetCallback(id) {
|
|
38
|
+
if (!this.callbacks[id])
|
|
39
|
+
return;
|
|
40
|
+
delete this.callbacks[id];
|
|
41
|
+
this.releaseSubscriptionIfIdle();
|
|
42
|
+
}
|
|
43
|
+
releaseSubscriptionIfIdle() {
|
|
44
|
+
if (Object.keys(this.callbacks).length === 0 && this.eventSubscription) {
|
|
45
|
+
this.eventSubscription.remove();
|
|
46
|
+
this.eventSubscription = null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
trigger(event) {
|
|
50
|
+
const callback = this.callbacks[event.watchId];
|
|
51
|
+
if (callback) {
|
|
52
|
+
callback(event[this.eventDataField]);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
void expoLocation.removeWatchAsync(event.watchId);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export const locationSubscriber = new Subscriber('Expo.locationChanged', 'location');
|
|
60
|
+
export const headingSubscriber = new Subscriber('Expo.headingChanged', 'heading');
|
|
61
|
+
export const locationErrorSubscriber = new Subscriber('Expo.locationError', 'reason');
|
|
62
|
+
export const motionActivitySubscriber = new Subscriber('Expo.motionActivityChanged', 'activity');
|
|
63
|
+
export function getCurrentWatchId() {
|
|
64
|
+
return nextWatchId;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=subscribers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribers.js","sourceRoot":"","sources":["../../src/core/subscribers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAU/C,IAAI,WAAW,GAAG,CAAC,CAAC;AAEpB,MAAM,UAAU;IAWJ;IACA;IALF,SAAS,GAA8B,EAAE,CAAC;IAC1C,iBAAiB,GAA6B,IAAI,CAAC;IAE3D,YACU,SAAiB,EACjB,cAAsB;QADtB,cAAS,GAAT,SAAS,CAAQ;QACjB,mBAAc,GAAd,cAAc,CAAQ;IAC7B,CAAC;IAEI,2BAA2B;QACjC,IAAI,IAAI,CAAC,iBAAiB;YAAE,OAAO;QACnC,IAAI,CAAC,iBAAiB,GAAG,YAAY,CAAC,WAAW,C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