@situm/react-native 3.9.3 → 3.10.1

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 (57) hide show
  1. package/android/src/main/java/com/situm/plugin/PluginHelper.java +91 -69
  2. package/android/src/main/java/com/situm/plugin/SitumMapper.java +6 -6
  3. package/android/src/main/java/com/situm/plugin/SitumPlugin.java +9 -2
  4. package/android/src/main/java/com/situm/plugin/SitumPluginImpl.java +10 -0
  5. package/android/src/main/java/com/situm/plugin/utils/ReactNativeUtils.java +284 -0
  6. package/ios/SitumLocationWrapper.m +4 -0
  7. package/ios/SitumPlugin.m +43 -27
  8. package/lib/commonjs/sdk/index.js +67 -20
  9. package/lib/commonjs/sdk/index.js.map +1 -1
  10. package/lib/commonjs/sdk/nativeInterface.js.map +1 -1
  11. package/lib/commonjs/sdk/types/constants.js +9 -4
  12. package/lib/commonjs/sdk/types/constants.js.map +1 -1
  13. package/lib/commonjs/sdk/types/index.js +1 -0
  14. package/lib/commonjs/sdk/types/index.js.map +1 -1
  15. package/lib/commonjs/wayfinding/components/MapView.js +21 -4
  16. package/lib/commonjs/wayfinding/components/MapView.js.map +1 -1
  17. package/lib/commonjs/wayfinding/hooks/index.js +25 -9
  18. package/lib/commonjs/wayfinding/hooks/index.js.map +1 -1
  19. package/lib/commonjs/wayfinding/utils/mapper.js +9 -1
  20. package/lib/commonjs/wayfinding/utils/mapper.js.map +1 -1
  21. package/lib/module/sdk/index.js +67 -20
  22. package/lib/module/sdk/index.js.map +1 -1
  23. package/lib/module/sdk/nativeInterface.js.map +1 -1
  24. package/lib/module/sdk/types/constants.js +9 -4
  25. package/lib/module/sdk/types/constants.js.map +1 -1
  26. package/lib/module/sdk/types/index.js +1 -0
  27. package/lib/module/sdk/types/index.js.map +1 -1
  28. package/lib/module/wayfinding/components/MapView.js +21 -4
  29. package/lib/module/wayfinding/components/MapView.js.map +1 -1
  30. package/lib/module/wayfinding/hooks/index.js +25 -9
  31. package/lib/module/wayfinding/hooks/index.js.map +1 -1
  32. package/lib/module/wayfinding/utils/mapper.js +9 -1
  33. package/lib/module/wayfinding/utils/mapper.js.map +1 -1
  34. package/lib/typescript/src/sdk/index.d.ts +36 -4
  35. package/lib/typescript/src/sdk/index.d.ts.map +1 -1
  36. package/lib/typescript/src/sdk/nativeInterface.d.ts +1 -0
  37. package/lib/typescript/src/sdk/nativeInterface.d.ts.map +1 -1
  38. package/lib/typescript/src/sdk/types/constants.d.ts +9 -4
  39. package/lib/typescript/src/sdk/types/constants.d.ts.map +1 -1
  40. package/lib/typescript/src/sdk/types/index.d.ts +2 -0
  41. package/lib/typescript/src/sdk/types/index.d.ts.map +1 -1
  42. package/lib/typescript/src/wayfinding/components/MapView.d.ts.map +1 -1
  43. package/lib/typescript/src/wayfinding/hooks/index.d.ts.map +1 -1
  44. package/lib/typescript/src/wayfinding/types/index.d.ts +18 -2
  45. package/lib/typescript/src/wayfinding/types/index.d.ts.map +1 -1
  46. package/lib/typescript/src/wayfinding/utils/mapper.d.ts +3 -1
  47. package/lib/typescript/src/wayfinding/utils/mapper.d.ts.map +1 -1
  48. package/package.json +2 -2
  49. package/src/sdk/index.ts +84 -23
  50. package/src/sdk/nativeInterface.ts +1 -0
  51. package/src/sdk/types/constants.ts +9 -4
  52. package/src/sdk/types/index.ts +2 -0
  53. package/src/wayfinding/components/MapView.tsx +31 -5
  54. package/src/wayfinding/hooks/index.ts +50 -10
  55. package/src/wayfinding/types/index.ts +21 -2
  56. package/src/wayfinding/utils/mapper.ts +11 -2
  57. package/android/src/main/java/com/situm/plugin/utils/ReactNativeJson.java +0 -122
@@ -94,6 +94,7 @@ interface NavigationAPI {
94
94
  onSuccess: (response: void) => void,
95
95
  onError: (error: Error) => void
96
96
  ) => void;
97
+ updateNavigationState: (externalNavigation: Map<string, any>) => void;
97
98
  }
98
99
 
99
100
  interface DirectionsAPI {
@@ -8,13 +8,18 @@ export enum NavigationStatus {
8
8
  export enum NavigationUpdateType {
9
9
  PROGRESS = "PROGRESS",
10
10
  OUT_OF_ROUTE = "OUT_OF_ROUTE",
11
- FINISHED = "DESTINATION_REACHED",
11
+ DESTINATION_REACHED = "DESTINATION_REACHED",
12
+ CANCELLED = "CANCELLED",
12
13
  }
13
14
 
14
15
  export enum SdkNavigationUpdateType {
15
- PROGRESS = "progress",
16
- OUT_OF_ROUTE = "userOutsideRoute",
17
- FINISHED = "destinationReached",
16
+ START = "onNavigationStart",
17
+ PROGRESS = "onNavigationProgress",
18
+ FINISHED = "onNavigationFinished",
19
+ DESTINATION_REACHED = "onNavigationDestinationReached",
20
+ OUTSIDE_ROUTE = "onUserOutsideRoute",
21
+ CANCELLATION = "onNavigationCancellation",
22
+ ERROR = "onNavigationError",
18
23
  }
19
24
 
20
25
  export enum LocationStatusName {
@@ -236,6 +236,7 @@ export type Point = {
236
236
  * @name Route
237
237
  * @description Route between two points.
238
238
  *
239
+ * @property {Poi} poiTo - The destination Poi the user is currently navigating to.
239
240
  * @property {RouteStep[]} edges - Ordered list of steps to go to the goal point
240
241
  * @property {RouteStep} firstStep - First step
241
242
  * @property {Point} from - Point where the route starts.
@@ -248,6 +249,7 @@ export type Point = {
248
249
  * @property {RouteSegment[]} segments - List of segments formed by consecutive points and a floor identifier
249
250
  */
250
251
  export type Route = {
252
+ poiTo?: Poi;
251
253
  edges: RouteStep[];
252
254
  firstStep: RouteStep;
253
255
  from: Point;
@@ -30,6 +30,7 @@ import {
30
30
  type MapViewDirectionsOptions,
31
31
  type MapViewError,
32
32
  type MapViewRef,
33
+ type NavigateToCarPayload,
33
34
  type NavigateToPointPayload,
34
35
  type NavigateToPoiPayload,
35
36
  type OnDirectionsRequestInterceptor,
@@ -200,6 +201,15 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
200
201
  );
201
202
  }, []);
202
203
 
204
+ const _navigateToCar = useCallback((payload?: NavigateToCarPayload) => {
205
+ if (!webViewRef.current) return;
206
+
207
+ sendMessageToViewer(
208
+ webViewRef.current,
209
+ ViewerMapper.navigateToCar(payload)
210
+ );
211
+ }, []);
212
+
203
213
  const _navigateToPoint = useCallback((payload: NavigateToPointPayload) => {
204
214
  if (
205
215
  !webViewRef.current ||
@@ -218,13 +228,16 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
218
228
  if (!webViewRef.current) {
219
229
  return;
220
230
  }
221
- if (SitumPlugin.navigationIsRunning()) {
222
- console.error(
223
- "Situm > hook > Navigation on course, poi selection is unavailable"
224
- );
231
+
232
+ sendMessageToViewer(webViewRef.current, ViewerMapper.selectPoi(poiId));
233
+ }, []);
234
+
235
+ const _selectCar = useCallback(() => {
236
+ if (!webViewRef.current) {
225
237
  return;
226
238
  }
227
- sendMessageToViewer(webViewRef.current, ViewerMapper.selectPoi(poiId));
239
+
240
+ sendMessageToViewer(webViewRef.current, ViewerMapper.selectCar());
228
241
  }, []);
229
242
 
230
243
  const _selectPoiCategory = useCallback((categoryId: number) => {
@@ -321,6 +334,9 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
321
334
  selectPoi(poiId: number) {
322
335
  _selectPoi(poiId);
323
336
  },
337
+ selectCar() {
338
+ _selectCar();
339
+ },
324
340
  selectPoiCategory(poiId: number) {
325
341
  _selectPoiCategory(poiId);
326
342
  },
@@ -340,6 +356,9 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
340
356
  navigateToPoi(payload): void {
341
357
  _navigateToPoi(payload);
342
358
  },
359
+ navigateToCar(payload): void {
360
+ _navigateToCar(payload);
361
+ },
343
362
  navigateToPoint(payload: NavigateToPointPayload): void {
344
363
  _navigateToPoint(payload);
345
364
  },
@@ -362,8 +381,10 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
362
381
  [
363
382
  stopNavigation,
364
383
  _navigateToPoi,
384
+ _navigateToCar,
365
385
  _navigateToPoint,
366
386
  _selectPoi,
387
+ _selectCar,
367
388
  _selectPoiCategory,
368
389
  _setDirectionsOptions,
369
390
  _setFavoritePois,
@@ -523,6 +544,11 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
523
544
  setBuildingIdentifier(eventParsed.payload.identifier.toString());
524
545
  }
525
546
  break;
547
+ case "viewer.navigation.started":
548
+ case "viewer.navigation.updated":
549
+ case "viewer.navigation.stopped":
550
+ SitumPlugin.updateNavigationState(eventParsed.payload);
551
+ break;
526
552
  default:
527
553
  break;
528
554
  }
@@ -81,8 +81,25 @@ export const useSitumInternal = () => {
81
81
  dispatch(resetLocation());
82
82
  });
83
83
 
84
+ SitumPlugin.onNavigationStart((route) => {
85
+ console.debug(
86
+ `Situm > hook > navigation started to ${route.poiTo?.poiName}`
87
+ );
88
+
89
+ dispatch(
90
+ setNavigation({
91
+ type: NavigationUpdateType.PROGRESS,
92
+ status: NavigationStatus.START,
93
+ })
94
+ );
95
+ });
96
+
84
97
  SitumPlugin.onNavigationProgress((progress: NavigationProgress) => {
85
- console.debug("Situm > hook > NavigationProgress");
98
+ console.debug(
99
+ `Situm > hook > navigation progress, remanining distance to goal ${progress.distanceToGoal.toFixed(
100
+ 2
101
+ )} m.`
102
+ );
86
103
 
87
104
  dispatch(
88
105
  setNavigation({
@@ -98,28 +115,45 @@ export const useSitumInternal = () => {
98
115
  });
99
116
 
100
117
  SitumPlugin.onNavigationOutOfRoute(() => {
118
+ console.debug("Situm > hook > user went out of route, recalculating ...");
119
+
101
120
  dispatch(
102
121
  setNavigation({
103
122
  type: NavigationUpdateType.OUT_OF_ROUTE,
104
123
  status: NavigationStatus.UPDATE,
105
124
  })
106
125
  );
107
-
108
- console.debug("Situm > hook > NavigationOutOfRoute");
109
126
  });
110
127
 
111
- SitumPlugin.onNavigationFinished(() => {
128
+ SitumPlugin.onNavigationDestinationReached((route) => {
129
+ console.debug(
130
+ `Situm > hook > destination ${route.poiTo?.poiName} was reached.`
131
+ );
132
+
112
133
  dispatch(
113
134
  setNavigation({
114
- type: NavigationUpdateType.FINISHED,
135
+ type: NavigationUpdateType.DESTINATION_REACHED,
115
136
  status: NavigationStatus.UPDATE,
116
137
  })
117
138
  );
118
- console.debug("Situm > hook > NavigationFinished");
119
139
  });
120
140
 
121
- SitumPlugin.onNavigationError((progress: NavigationProgress) => {
122
- console.debug("Situm > hook > NavigationProgress: ", progress);
141
+ SitumPlugin.onNavigationCancellation(() => {
142
+ console.debug("Situm > hook > navigation was cancelled by the user.");
143
+
144
+ dispatch(
145
+ setNavigation({
146
+ type: NavigationUpdateType.CANCELLED,
147
+ status: NavigationStatus.STOP,
148
+ })
149
+ );
150
+ });
151
+
152
+ SitumPlugin.onNavigationError((navigationError: any) => {
153
+ console.error(
154
+ "Situm > hook > ERROR while navigating: ",
155
+ JSON.stringify(navigationError)
156
+ );
123
157
  });
124
158
  }
125
159
 
@@ -235,7 +269,9 @@ export const useSitumInternal = () => {
235
269
  })
236
270
  .catch((e) => {
237
271
  console.error(
238
- `Situm > hook > Could not compute route for navigation ${e}`
272
+ `Situm > hook > Could not compute route for navigation ${JSON.stringify(
273
+ e
274
+ )}`
239
275
  );
240
276
  });
241
277
  };
@@ -253,7 +289,11 @@ export const useSitumInternal = () => {
253
289
  dispatch(setNavigation({ status: NavigationStatus.STOP }));
254
290
  })
255
291
  .catch((e) => {
256
- console.warn(`Situm > hook > Could not remove navigation updates ${e}`);
292
+ console.warn(
293
+ `Situm > hook > Could not remove navigation updates ${JSON.stringify(
294
+ e
295
+ )}`
296
+ );
257
297
  });
258
298
  };
259
299
 
@@ -34,7 +34,7 @@ export interface MapViewRef {
34
34
  /**
35
35
  * Starts navigating to the given POI.
36
36
  * @param params.identifier You can obtain the identifiers of your POIs by retrieving them with [SitumPlugin.fetchIndoorPOIsFromBuilding()](https://developers.situm.com/sdk_documentation/react-native/typedoc/classes/default.html#fetchIndoorPOIsFromBuilding).
37
- * @param params.accessibilityMode You can optionally choose the desired [AccessibilityMode](https://developers.situm.com/sdk_documentation/react-native/typedoc/enums/accessibilitymode) used to calculate the route.
37
+ * @param params.accessibilityMode You can optionally choose the desired [AccessibilityMode](https://developers.situm.com/sdk_documentation/react-native/typedoc/enums/AccessibilityMode.html) used to calculate the route.
38
38
  */
39
39
  navigateToPoi: (params: {
40
40
  identifier: number;
@@ -46,7 +46,7 @@ export interface MapViewRef {
46
46
  * @param params.lng The longitude of the destination point.
47
47
  * @param params.floorIdentifier The floorIndetifier of the destination point.
48
48
  * @param params.navigationName You can optionally set the name of the destination to be displayed on the MapView.
49
- * @param params.accessibilityMode You can optionally choose the desired [AccessibilityMode](https://developers.situm.com/sdk_documentation/react-native/typedoc/enums/accessibilitymode) used to calculate the route.
49
+ * @param params.accessibilityMode You can optionally choose the desired [AccessibilityMode](https://developers.situm.com/sdk_documentation/react-native/typedoc/enums/AccessibilityMode.html) used to calculate the route.
50
50
  */
51
51
  navigateToPoint: (params: {
52
52
  lat: number;
@@ -69,6 +69,21 @@ export interface MapViewRef {
69
69
  * This action will have the same effect as the user searching in the searchbar.
70
70
  */
71
71
  search: (searchFilter: SearchFilter) => void;
72
+
73
+ /**
74
+ * Selects a point saved as Find My Car on the map.
75
+ *
76
+ * To use it, the feature 'Find My Car' must be enabled.
77
+ */
78
+ selectCar: () => void;
79
+
80
+ /**
81
+ * Starts navigating to a point saved as find my car.
82
+ * @param params.accessibilityMode You can optionally choose the desired [AccessibilityMode](https://developers.situm.com/sdk_documentation/react-native/typedoc/enums/AccessibilityMode.html) used to calculate the route.
83
+ *
84
+ * To use it, the feature 'Find My Car' must be enabled.
85
+ */
86
+ navigateToCar: (params?: NavigateToCarPayload) => void;
72
87
  }
73
88
 
74
89
  export interface WayfindingResult {
@@ -150,6 +165,10 @@ export type NavigateToPoiPayload = {
150
165
  accessibilityMode?: AccessibilityMode;
151
166
  };
152
167
 
168
+ export type NavigateToCarPayload = {
169
+ accessibilityMode?: AccessibilityMode;
170
+ };
171
+
153
172
  export type NavigateToPointPayload = {
154
173
  lat: number;
155
174
  lng: number;
@@ -11,6 +11,7 @@ import type {
11
11
  import type {
12
12
  DirectionsMessage,
13
13
  MapViewDirectionsOptions,
14
+ NavigateToCarPayload,
14
15
  NavigateToPointPayload,
15
16
  NavigateToPoiPayload,
16
17
  Navigation,
@@ -75,8 +76,8 @@ export const createNavigationRequest = (payload: any): NavigationRequest => {
75
76
  );
76
77
  };
77
78
 
78
- const mapperWrapper = (type: string, payload: unknown) => {
79
- return JSON.stringify({ type, payload });
79
+ const mapperWrapper = (type: string, payload?: unknown) => {
80
+ return JSON.stringify({ type, payload: payload ?? {} });
80
81
  };
81
82
 
82
83
  const ViewerMapper = {
@@ -101,6 +102,9 @@ const ViewerMapper = {
101
102
  selectPoi: (poiId: number | null) => {
102
103
  return mapperWrapper(`cartography.select_poi`, { identifier: poiId });
103
104
  },
105
+ selectCar: () => {
106
+ return mapperWrapper(`cartography.select_car`);
107
+ },
104
108
  selectPoiCategory: (categoryId: number) => {
105
109
  return mapperWrapper(`cartography.select_poi_category`, {
106
110
  identifier: categoryId,
@@ -163,6 +167,11 @@ const ViewerMapper = {
163
167
  type: navigate.accessibilityMode,
164
168
  });
165
169
  },
170
+ navigateToCar: (params?: NavigateToCarPayload) => {
171
+ return mapperWrapper(`navigation.start.to_car`, {
172
+ type: params?.accessibilityMode,
173
+ });
174
+ },
166
175
  navigateToPoint: ({
167
176
  lat,
168
177
  lng,
@@ -1,122 +0,0 @@
1
- package com.situm.plugin.utils;
2
-
3
- import com.facebook.react.bridge.ReadableArray;
4
- import com.facebook.react.bridge.ReadableMap;
5
- import com.facebook.react.bridge.ReadableMapKeySetIterator;
6
- import com.facebook.react.bridge.WritableArray;
7
- import com.facebook.react.bridge.WritableMap;
8
- import com.facebook.react.bridge.WritableNativeArray;
9
- import com.facebook.react.bridge.WritableNativeMap;
10
-
11
- import org.json.JSONArray;
12
- import org.json.JSONException;
13
- import org.json.JSONObject;
14
-
15
- import java.util.Iterator;
16
-
17
- public class ReactNativeJson {
18
- public static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException {
19
- WritableMap map = new WritableNativeMap();
20
-
21
- Iterator<String> iterator = jsonObject.keys();
22
- while (iterator.hasNext()) {
23
- String key = iterator.next();
24
- Object value = jsonObject.get(key);
25
- if (value instanceof JSONObject) {
26
- map.putMap(key, convertJsonToMap((JSONObject) value));
27
- } else if (value instanceof JSONArray) {
28
- map.putArray(key, convertJsonToArray((JSONArray) value));
29
- } else if (value instanceof Boolean) {
30
- map.putBoolean(key, (Boolean) value);
31
- } else if (value instanceof Integer) {
32
- map.putInt(key, (Integer) value);
33
- } else if (value instanceof Double) {
34
- map.putDouble(key, (Double) value);
35
- } else if (value instanceof String) {
36
- map.putString(key, (String) value);
37
- } else {
38
- map.putString(key, value.toString());
39
- }
40
- }
41
- return map;
42
- }
43
-
44
- public static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSONException {
45
- WritableArray array = new WritableNativeArray();
46
-
47
- for (int i = 0; i < jsonArray.length(); i++) {
48
- Object value = jsonArray.get(i);
49
- if (value instanceof JSONObject) {
50
- array.pushMap(convertJsonToMap((JSONObject) value));
51
- } else if (value instanceof JSONArray) {
52
- array.pushArray(convertJsonToArray((JSONArray) value));
53
- } else if (value instanceof Boolean) {
54
- array.pushBoolean((Boolean) value);
55
- } else if (value instanceof Integer) {
56
- array.pushInt((Integer) value);
57
- } else if (value instanceof Double) {
58
- array.pushDouble((Double) value);
59
- } else if (value instanceof String) {
60
- array.pushString((String) value);
61
- } else {
62
- array.pushString(value.toString());
63
- }
64
- }
65
- return array;
66
- }
67
-
68
- public static JSONObject convertMapToJson(ReadableMap readableMap) throws JSONException {
69
- JSONObject object = new JSONObject();
70
- ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
71
- while (iterator.hasNextKey()) {
72
- String key = iterator.nextKey();
73
- switch (readableMap.getType(key)) {
74
- case Null:
75
- object.put(key, JSONObject.NULL);
76
- break;
77
- case Boolean:
78
- object.put(key, readableMap.getBoolean(key));
79
- break;
80
- case Number:
81
- object.put(key, readableMap.getDouble(key));
82
- break;
83
- case String:
84
- object.put(key, readableMap.getString(key));
85
- break;
86
- case Map:
87
- object.put(key, convertMapToJson(readableMap.getMap(key)));
88
- break;
89
- case Array:
90
- object.put(key, convertArrayToJson(readableMap.getArray(key)));
91
- break;
92
- }
93
- }
94
- return object;
95
- }
96
-
97
- public static JSONArray convertArrayToJson(ReadableArray readableArray) throws JSONException {
98
- JSONArray array = new JSONArray();
99
- for (int i = 0; i < readableArray.size(); i++) {
100
- switch (readableArray.getType(i)) {
101
- case Null:
102
- break;
103
- case Boolean:
104
- array.put(readableArray.getBoolean(i));
105
- break;
106
- case Number:
107
- array.put(readableArray.getDouble(i));
108
- break;
109
- case String:
110
- array.put(readableArray.getString(i));
111
- break;
112
- case Map:
113
- array.put(convertMapToJson(readableArray.getMap(i)));
114
- break;
115
- case Array:
116
- array.put(convertArrayToJson(readableArray.getArray(i)));
117
- break;
118
- }
119
- }
120
- return array;
121
- }
122
- }