@situm/react-native 3.7.6 → 3.8.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.
Files changed (41) hide show
  1. package/lib/commonjs/sdk/types/constants.js +0 -2
  2. package/lib/commonjs/sdk/types/constants.js.map +1 -1
  3. package/lib/commonjs/sdk/types/index.js +0 -1
  4. package/lib/commonjs/sdk/types/index.js.map +1 -1
  5. package/lib/commonjs/wayfinding/components/MapView.js +56 -15
  6. package/lib/commonjs/wayfinding/components/MapView.js.map +1 -1
  7. package/lib/commonjs/wayfinding/hooks/index.js +11 -9
  8. package/lib/commonjs/wayfinding/hooks/index.js.map +1 -1
  9. package/lib/commonjs/wayfinding/store/index.js +4 -10
  10. package/lib/commonjs/wayfinding/store/index.js.map +1 -1
  11. package/lib/commonjs/wayfinding/utils/mapper.js +6 -2
  12. package/lib/commonjs/wayfinding/utils/mapper.js.map +1 -1
  13. package/lib/module/sdk/types/constants.js +0 -2
  14. package/lib/module/sdk/types/constants.js.map +1 -1
  15. package/lib/module/sdk/types/index.js +0 -1
  16. package/lib/module/sdk/types/index.js.map +1 -1
  17. package/lib/module/wayfinding/components/MapView.js +56 -15
  18. package/lib/module/wayfinding/components/MapView.js.map +1 -1
  19. package/lib/module/wayfinding/hooks/index.js +13 -11
  20. package/lib/module/wayfinding/hooks/index.js.map +1 -1
  21. package/lib/module/wayfinding/store/index.js +4 -10
  22. package/lib/module/wayfinding/store/index.js.map +1 -1
  23. package/lib/module/wayfinding/utils/mapper.js +6 -2
  24. package/lib/module/wayfinding/utils/mapper.js.map +1 -1
  25. package/lib/typescript/src/sdk/types/constants.d.ts +0 -2
  26. package/lib/typescript/src/sdk/types/constants.d.ts.map +1 -1
  27. package/lib/typescript/src/sdk/types/index.d.ts +0 -2
  28. package/lib/typescript/src/sdk/types/index.d.ts.map +1 -1
  29. package/lib/typescript/src/wayfinding/components/MapView.d.ts.map +1 -1
  30. package/lib/typescript/src/wayfinding/hooks/index.d.ts.map +1 -1
  31. package/lib/typescript/src/wayfinding/store/index.d.ts +1 -0
  32. package/lib/typescript/src/wayfinding/store/index.d.ts.map +1 -1
  33. package/lib/typescript/src/wayfinding/utils/mapper.d.ts +3 -1
  34. package/lib/typescript/src/wayfinding/utils/mapper.d.ts.map +1 -1
  35. package/package.json +1 -1
  36. package/src/sdk/types/constants.ts +4 -4
  37. package/src/sdk/types/index.ts +0 -2
  38. package/src/wayfinding/components/MapView.tsx +77 -20
  39. package/src/wayfinding/hooks/index.ts +9 -15
  40. package/src/wayfinding/store/index.tsx +6 -4
  41. package/src/wayfinding/utils/mapper.ts +5 -3
@@ -20,7 +20,11 @@ import type {
20
20
  WebViewMessageEvent,
21
21
  } from "react-native-webview/lib/WebViewTypes";
22
22
 
23
- import SitumPlugin from "../../sdk";
23
+ import SitumPlugin, {
24
+ type Error,
25
+ type LocationStatus,
26
+ LocationStatusName,
27
+ } from "../../sdk";
24
28
  import useSitum from "../hooks";
25
29
  import {
26
30
  type MapViewDirectionsOptions,
@@ -157,6 +161,8 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
157
161
  useState<OnDirectionsRequestInterceptor>();
158
162
 
159
163
  // Local states
164
+ const [locationStatus, setLocationStatus] = useState<LocationStatusName>();
165
+ const [locationError, setLocationError] = useState<string>();
160
166
  const [mapLoaded, setMapLoaded] = useState<boolean>(false);
161
167
  const [buildingIdentifier, setBuildingIdentifier] = useState<string>(
162
168
  configuration.buildingIdentifier
@@ -164,10 +170,8 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
164
170
  const {
165
171
  init,
166
172
  location,
167
- locationStatus,
168
173
  directions,
169
174
  navigation,
170
-
171
175
  calculateRoute,
172
176
  startNavigation,
173
177
  stopNavigation,
@@ -266,6 +270,22 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
266
270
  );
267
271
  }, []);
268
272
 
273
+ const _onMapIsReady = () => {
274
+ if (locationStatus) {
275
+ sendMessageToViewer(
276
+ webViewRef.current,
277
+ ViewerMapper.locationStatus(locationStatus)
278
+ );
279
+ }
280
+ if (locationError) {
281
+ // Right now, status and errors share message on the viewer:
282
+ sendMessageToViewer(
283
+ webViewRef.current,
284
+ ViewerMapper.locationError(locationError)
285
+ );
286
+ }
287
+ };
288
+
269
289
  /**
270
290
  * API exported to the outside world from the MapViewer
271
291
  *
@@ -351,6 +371,24 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
351
371
  ]
352
372
  );
353
373
 
374
+ useEffect(() => {
375
+ SitumPlugin.onLocationStatus((status: LocationStatus) => {
376
+ // TODO: implement status & error adapter on native SDKs.
377
+ let finalStatus = status.statusName as string;
378
+ if (Platform.OS === "ios" && finalStatus === "CALCULATING") {
379
+ finalStatus = "STARTING";
380
+ }
381
+ if (finalStatus in LocationStatusName) {
382
+ setLocationStatus(finalStatus as LocationStatusName);
383
+ }
384
+ });
385
+ SitumPlugin.onLocationError((e: Error) => {
386
+ setLocationError(e.code);
387
+ });
388
+
389
+ return () => {};
390
+ }, []);
391
+
354
392
  useEffect(() => {
355
393
  if (!error) return;
356
394
 
@@ -363,27 +401,55 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
363
401
 
364
402
  // Updated SDK location
365
403
  useEffect(() => {
366
- if (!webViewRef.current || !location) return;
404
+ if (!webViewRef.current || !location || !mapLoaded) return;
367
405
 
368
406
  sendMessageToViewer(webViewRef.current, ViewerMapper.location(location));
369
- }, [location]);
407
+ }, [location, mapLoaded]);
408
+
409
+ // locationStatus
410
+ useEffect(() => {
411
+ if (!webViewRef.current || !locationStatus || !mapLoaded) return;
412
+
413
+ sendMessageToViewer(
414
+ webViewRef.current,
415
+ ViewerMapper.locationStatus(locationStatus)
416
+ );
417
+ // Callbacks used in `useEffect` won't be invoked if the value of locationStatus
418
+ // is set but hasn't changed. Set locationStatus to null always to avoid missing
419
+ // repeated messages.
420
+ setLocationStatus(null);
421
+ }, [locationStatus, mapLoaded]);
422
+
423
+ // locationError
424
+ useEffect(() => {
425
+ if (!webViewRef.current || !locationError || !mapLoaded) return;
426
+
427
+ sendMessageToViewer(
428
+ webViewRef.current,
429
+ ViewerMapper.locationError(locationError)
430
+ );
431
+ // Callbacks used in `useEffect` won't be invoked if the value of locationStatus
432
+ // is set but hasn't changed. Set locationStatus to null always to avoid missing
433
+ // repeated messages.
434
+ setLocationError(null);
435
+ }, [locationError, mapLoaded]);
370
436
 
371
437
  // Updated SDK navigation
372
438
  useEffect(() => {
373
- if (!webViewRef.current || !navigation) return;
439
+ if (!webViewRef.current || !navigation || !mapLoaded) return;
374
440
 
375
441
  sendMessageToViewer(
376
442
  webViewRef.current,
377
443
  ViewerMapper.navigation(navigation)
378
444
  );
379
- }, [navigation]);
445
+ }, [navigation, mapLoaded]);
380
446
 
381
447
  // Updated SDK route
382
448
  useEffect(() => {
383
- if (!webViewRef.current || !directions) return;
449
+ if (!webViewRef.current || !directions || !mapLoaded) return;
384
450
 
385
451
  sendMessageToViewer(webViewRef.current, ViewerMapper.route(directions));
386
- }, [directions]);
452
+ }, [directions, mapLoaded]);
387
453
 
388
454
  // Update language
389
455
  useEffect(() => {
@@ -411,23 +477,14 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
411
477
  // eslint-disable-next-line react-hooks/exhaustive-deps
412
478
  }, [mapLoaded]);
413
479
 
414
- //locationStatus
415
- useEffect(() => {
416
- if (!webViewRef.current || !locationStatus || !mapLoaded) return;
417
-
418
- sendMessageToViewer(
419
- webViewRef.current,
420
- ViewerMapper.locationStatus(locationStatus)
421
- );
422
- }, [locationStatus, mapLoaded]);
423
-
424
480
  const handleRequestFromViewer = (event: WebViewMessageEvent) => {
425
481
  const eventParsed = JSON.parse(event.nativeEvent.data);
426
482
  switch (eventParsed.type) {
427
483
  case "app.map_is_ready":
428
484
  init();
429
- onLoad && onLoad("");
430
485
  setMapLoaded(true);
486
+ _onMapIsReady();
487
+ onLoad && onLoad("");
431
488
  break;
432
489
  case "directions.requested":
433
490
  calculateRoute(eventParsed.payload, _onDirectionsRequestInterceptor);
@@ -8,11 +8,9 @@ import {
8
8
  ErrorCode,
9
9
  ErrorType,
10
10
  type Location,
11
- type LocationStatus,
12
11
  type NavigationProgress,
13
12
  } from "../../sdk/types";
14
13
  import {
15
- LocationStatusName,
16
14
  NavigationStatus,
17
15
  NavigationUpdateType,
18
16
  } from "../../sdk/types/constants";
@@ -26,7 +24,6 @@ import {
26
24
  setDirections,
27
25
  setError,
28
26
  setLocation,
29
- setLocationStatus,
30
27
  setNavigation,
31
28
  UseSitumContext,
32
29
  } from "../store/index";
@@ -69,18 +66,15 @@ export const useSitumInternal = () => {
69
66
  );
70
67
  });
71
68
 
72
- SitumPlugin.onLocationStatus((status: LocationStatus) => {
73
- if (status.statusName in LocationStatusName) {
74
- console.debug(
75
- `Situm > hook > Positioning state updated ${status.statusName}`
76
- );
77
- dispatch(setLocationStatus(status.statusName as LocationStatusName));
78
- }
79
- });
80
-
81
- SitumPlugin.onLocationError((err: Error) => {
82
- console.error(`Situm > hook > Error while positioning: ${err}}`);
83
- });
69
+ // TODO: not working, using local state at MapView.tsx.
70
+ // SitumPlugin.onLocationStatus((status: LocationStatus) => {
71
+ // if (status.statusName in LocationStatusName) {
72
+ // console.debug(
73
+ // `Situm > hook > Positioning state updated ${status.statusName}`
74
+ // );
75
+ // dispatch(setLocationStatus(status.statusName as LocationStatusName));
76
+ // }
77
+ // });
84
78
 
85
79
  SitumPlugin.onLocationStopped(() => {
86
80
  console.debug("Situm > hook > Stopped positioning");
@@ -23,6 +23,7 @@ export interface State {
23
23
  sdkInitialized: boolean;
24
24
  user?: User;
25
25
  location?: Location;
26
+ locationStatus?: LocationStatusName;
26
27
  buildings: Building[] | null;
27
28
  currentBuilding: Building;
28
29
  pois: Poi[];
@@ -37,7 +38,8 @@ export const initialState: State = {
37
38
  webViewRef: undefined,
38
39
  sdkInitialized: false,
39
40
  user: undefined,
40
- location: { status: LocationStatusName.STOPPED },
41
+ location: null,
42
+ locationStatus: null,
41
43
  buildings: null,
42
44
  currentBuilding: undefined,
43
45
  pois: [],
@@ -67,8 +69,8 @@ const store = createStore<State>({
67
69
  setLocation: (state: State, payload: State["location"]) => {
68
70
  return { ...state, location: payload };
69
71
  },
70
- setLocationStatus: (state: State, payload: LocationStatusName) => {
71
- return { ...state, location: { ...state.location, status: payload } };
72
+ setLocationStatus: (state: State, payload: State["locationStatus"]) => {
73
+ return { ...state, locationStatus: payload };
72
74
  },
73
75
  resetLocation: (state: State) => {
74
76
  return {
@@ -123,7 +125,7 @@ export const selectLocation = (state: State) => {
123
125
  };
124
126
 
125
127
  export const selectLocationStatus = (state: State) => {
126
- return state.location?.status;
128
+ return state.locationStatus;
127
129
  };
128
130
 
129
131
  export const selectBuildings = (state: State) => {
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { AccessibilityMode } from "../../sdk";
2
+ import { AccessibilityMode, LocationStatusName } from "../../sdk";
3
3
  import type {
4
4
  Directions,
5
5
  DirectionsRequest,
@@ -128,12 +128,14 @@ const ViewerMapper = {
128
128
  accuracy: location.accuracy,
129
129
  hasBearing: location.hasBearing,
130
130
  }),
131
- status: location.status,
132
131
  });
133
132
  },
134
- locationStatus: (locationStatus: Location["status"]) => {
133
+ locationStatus: (locationStatus: LocationStatusName) => {
135
134
  return mapperWrapper("location.update_status", { status: locationStatus });
136
135
  },
136
+ locationError: (errorCode: string) => {
137
+ return mapperWrapper("location.update_status", { status: errorCode });
138
+ },
137
139
  // Directions
138
140
  route: (directions: Directions) => {
139
141
  return mapperWrapper("directions.update", directions);