From d9e57514e090ac71e90cc19bdae8ca68c278f1ab Mon Sep 17 00:00:00 2001 From: David Gettins Date: Mon, 16 Jan 2023 16:32:16 +0000 Subject: [PATCH 1/3] fix(motion-activity-event): correct field name and update to union type Gives better code completion feedback. --- .../interfaces/MotionActivityEvent.d.ts | 57 +++++++++++-------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/declarations/interfaces/MotionActivityEvent.d.ts b/src/declarations/interfaces/MotionActivityEvent.d.ts index 2c4dd387..c7cec62a 100644 --- a/src/declarations/interfaces/MotionActivityEvent.d.ts +++ b/src/declarations/interfaces/MotionActivityEvent.d.ts @@ -1,31 +1,42 @@ declare module "react-native-background-geolocation" { /** - * The event-object provided to [[BackgroundGeolocation.onActivityChange]]. Also attached to each recorded [[Location]]. - * - * @example - * ```typescript - * BackgroundGeolocation.onActivityChange(activityChangeEvent => { - * console.log("[activitychange] ", activityChangeEvent.activity, activityChangeEvent.confidence); - * }); - * ``` - */ + * Type of activity. + */ + type MotionActivityType = + | "still" + | "walking" + | "on_foot" + | "running" + | "on_bicycle" + | "in_vehicle"; + + /** + * The event-object provided to [[BackgroundGeolocation.onActivityChange]]. Also attached to each recorded [[Location]]. + * + * @example + * ```typescript + * BackgroundGeolocation.onActivityChange(activityChangeEvent => { + * console.log("[activitychange] ", activityChangeEvent.activity, activityChangeEvent.confidence); + * }); + * ``` + */ interface MotionActivityEvent { /** - * The reported device motion activity. - * - * | Activity Name | - * |----------------| - * | `still` | - * | `walking` | - * | `on_foot` | - * | `running` | - * | `on_bicycle` | - * | `in_vehicle` | - */ - activity: string; + * The reported device motion activity. + * + * | Activity Name | + * |----------------| + * | `still` | + * | `walking` | + * | `on_foot` | + * | `running` | + * | `on_bicycle` | + * | `in_vehicle` | + */ + type: MotionActivityType; /** - * Confidence of the reported device motion activity in %. - */ + * Confidence of the reported device motion activity in %. + */ confidence: number; } } From c1462daa0c828b9447c7ecfe2f1655514bff0cc2 Mon Sep 17 00:00:00 2001 From: David Gettins Date: Mon, 16 Jan 2023 16:48:17 +0000 Subject: [PATCH 2/3] revert(motion-activity-event): correct field name and update to union type --- .../interfaces/MotionActivityEvent.d.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/declarations/interfaces/MotionActivityEvent.d.ts b/src/declarations/interfaces/MotionActivityEvent.d.ts index c7cec62a..a6b95ae3 100644 --- a/src/declarations/interfaces/MotionActivityEvent.d.ts +++ b/src/declarations/interfaces/MotionActivityEvent.d.ts @@ -1,15 +1,4 @@ declare module "react-native-background-geolocation" { - /** - * Type of activity. - */ - type MotionActivityType = - | "still" - | "walking" - | "on_foot" - | "running" - | "on_bicycle" - | "in_vehicle"; - /** * The event-object provided to [[BackgroundGeolocation.onActivityChange]]. Also attached to each recorded [[Location]]. * @@ -33,7 +22,7 @@ declare module "react-native-background-geolocation" { * | `on_bicycle` | * | `in_vehicle` | */ - type: MotionActivityType; + activity: string; /** * Confidence of the reported device motion activity in %. */ From 68b3e32cc6abd9d4558a759b90a2ecbce62ff0ea Mon Sep 17 00:00:00 2001 From: David Gettins Date: Mon, 16 Jan 2023 16:50:12 +0000 Subject: [PATCH 3/3] fix(location): add location specific motion activity event type Fixes incorrect field name and narrows type using a string union. --- src/declarations/interfaces/Location.d.ts | 4 +- .../LocationMotionActivityEvent.d.ts | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/declarations/interfaces/LocationMotionActivityEvent.d.ts diff --git a/src/declarations/interfaces/Location.d.ts b/src/declarations/interfaces/Location.d.ts index 322d28c3..77ac751d 100644 --- a/src/declarations/interfaces/Location.d.ts +++ b/src/declarations/interfaces/Location.d.ts @@ -1,5 +1,5 @@ /// -/// +/// /// /// /// @@ -216,7 +216,7 @@ declare module "react-native-background-geolocation" { /** * Device motion-activity when this location was recorded (eg: `still`, `on_foot`, `in_vehicle`). */ - activity: MotionActivityEvent; + activity: LocationMotionActivityEvent; /** * If this location was recorded due to [[ProviderChangeEvent]], this is a reference to the location-provider state. */ diff --git a/src/declarations/interfaces/LocationMotionActivityEvent.d.ts b/src/declarations/interfaces/LocationMotionActivityEvent.d.ts new file mode 100644 index 00000000..3bd02a0b --- /dev/null +++ b/src/declarations/interfaces/LocationMotionActivityEvent.d.ts @@ -0,0 +1,42 @@ +declare module "react-native-background-geolocation" { + /** + * Type of activity. + */ + type LocationMotionActivityType = + | "still" + | "walking" + | "on_foot" + | "running" + | "on_bicycle" + | "in_vehicle"; + + /** + * The `activity` field which is part of the `Location` type that gets passed to [[BackgroundGeolocation.onLocation]]. + * + * @example + * ```typescript + * BackgroundGeolocation.onLocatione(location => { + * console.log("[location] ", location.activity.type, location.activity.confidence); + * }); + * ``` + */ + interface LocationMotionActivityEvent { + /** + * The reported device motion activity. + * + * | Activity Name | + * |----------------| + * | `still` | + * | `walking` | + * | `on_foot` | + * | `running` | + * | `on_bicycle` | + * | `in_vehicle` | + */ + type: LocationMotionActivityType; + /** + * Confidence of the reported device motion activity in %. + */ + confidence: number; + } +}