@situm/react-native 3.0.10 → 3.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.
Files changed (77) hide show
  1. package/android/src/main/java/com/situm/plugin/PluginHelper.java +3 -2
  2. package/android/src/main/java/com/situm/plugin/SitumMapper.java +38 -59
  3. package/android/src/main/java/com/situm/plugin/SitumPlugin.java +1 -0
  4. package/android/src/main/java/com/situm/plugin/SitumPluginImpl.java +1 -1
  5. package/ios/SitumPlugin.m +8 -2
  6. package/lib/commonjs/sdk/index.js +509 -251
  7. package/lib/commonjs/sdk/index.js.map +1 -1
  8. package/lib/commonjs/sdk/nativeInterface.js.map +1 -1
  9. package/lib/commonjs/sdk/types/constants.js +31 -4
  10. package/lib/commonjs/sdk/types/constants.js.map +1 -1
  11. package/lib/commonjs/sdk/utils.js +103 -0
  12. package/lib/commonjs/sdk/utils.js.map +1 -0
  13. package/lib/commonjs/utils/requestPermission.js +9 -16
  14. package/lib/commonjs/utils/requestPermission.js.map +1 -1
  15. package/lib/commonjs/wayfinding/components/MapView.js +78 -134
  16. package/lib/commonjs/wayfinding/components/MapView.js.map +1 -1
  17. package/lib/commonjs/wayfinding/hooks/index.js +118 -278
  18. package/lib/commonjs/wayfinding/hooks/index.js.map +1 -1
  19. package/lib/commonjs/wayfinding/store/index.js +17 -6
  20. package/lib/commonjs/wayfinding/store/index.js.map +1 -1
  21. package/lib/commonjs/wayfinding/types/index.js +1 -3
  22. package/lib/commonjs/wayfinding/types/index.js.map +1 -1
  23. package/lib/commonjs/wayfinding/utils/mapper.js +128 -71
  24. package/lib/commonjs/wayfinding/utils/mapper.js.map +1 -1
  25. package/lib/module/sdk/index.js +509 -249
  26. package/lib/module/sdk/index.js.map +1 -1
  27. package/lib/module/sdk/nativeInterface.js.map +1 -1
  28. package/lib/module/sdk/types/constants.js +27 -3
  29. package/lib/module/sdk/types/constants.js.map +1 -1
  30. package/lib/module/sdk/utils.js +94 -0
  31. package/lib/module/sdk/utils.js.map +1 -0
  32. package/lib/module/utils/requestPermission.js +9 -16
  33. package/lib/module/utils/requestPermission.js.map +1 -1
  34. package/lib/module/wayfinding/components/MapView.js +77 -133
  35. package/lib/module/wayfinding/components/MapView.js.map +1 -1
  36. package/lib/module/wayfinding/hooks/index.js +119 -278
  37. package/lib/module/wayfinding/hooks/index.js.map +1 -1
  38. package/lib/module/wayfinding/store/index.js +15 -6
  39. package/lib/module/wayfinding/store/index.js.map +1 -1
  40. package/lib/module/wayfinding/types/index.js +1 -1
  41. package/lib/module/wayfinding/types/index.js.map +1 -1
  42. package/lib/module/wayfinding/utils/mapper.js +123 -72
  43. package/lib/module/wayfinding/utils/mapper.js.map +1 -1
  44. package/lib/typescript/src/sdk/index.d.ts +183 -145
  45. package/lib/typescript/src/sdk/index.d.ts.map +1 -1
  46. package/lib/typescript/src/sdk/nativeInterface.d.ts +59 -0
  47. package/lib/typescript/src/sdk/nativeInterface.d.ts.map +1 -1
  48. package/lib/typescript/src/sdk/types/constants.d.ts +24 -3
  49. package/lib/typescript/src/sdk/types/constants.d.ts.map +1 -1
  50. package/lib/typescript/src/sdk/types/index.d.ts +91 -146
  51. package/lib/typescript/src/sdk/types/index.d.ts.map +1 -1
  52. package/lib/typescript/src/sdk/utils.d.ts +53 -0
  53. package/lib/typescript/src/sdk/utils.d.ts.map +1 -0
  54. package/lib/typescript/src/utils/requestPermission.d.ts +1 -1
  55. package/lib/typescript/src/utils/requestPermission.d.ts.map +1 -1
  56. package/lib/typescript/src/wayfinding/components/MapView.d.ts +16 -28
  57. package/lib/typescript/src/wayfinding/components/MapView.d.ts.map +1 -1
  58. package/lib/typescript/src/wayfinding/hooks/index.d.ts +3 -34
  59. package/lib/typescript/src/wayfinding/hooks/index.d.ts.map +1 -1
  60. package/lib/typescript/src/wayfinding/store/index.d.ts +8 -6
  61. package/lib/typescript/src/wayfinding/store/index.d.ts.map +1 -1
  62. package/lib/typescript/src/wayfinding/types/index.d.ts +36 -17
  63. package/lib/typescript/src/wayfinding/types/index.d.ts.map +1 -1
  64. package/lib/typescript/src/wayfinding/utils/mapper.d.ts +16 -11
  65. package/lib/typescript/src/wayfinding/utils/mapper.d.ts.map +1 -1
  66. package/package.json +2 -2
  67. package/src/sdk/index.ts +467 -476
  68. package/src/sdk/nativeInterface.ts +149 -1
  69. package/src/sdk/types/constants.ts +27 -3
  70. package/src/sdk/types/index.ts +98 -158
  71. package/src/sdk/utils.ts +129 -0
  72. package/src/utils/requestPermission.ts +18 -23
  73. package/src/wayfinding/components/MapView.tsx +145 -215
  74. package/src/wayfinding/hooks/index.ts +155 -385
  75. package/src/wayfinding/store/index.tsx +19 -9
  76. package/src/wayfinding/types/index.ts +49 -15
  77. package/src/wayfinding/utils/mapper.ts +145 -104
@@ -0,0 +1,129 @@
1
+ import { logError } from "..";
2
+ import type { Error } from "./types";
3
+
4
+ type PromiseResolve<T> = (response: T) => void;
5
+ type PromiseReject = (error?: Error) => void;
6
+
7
+ /**
8
+ * Handles callbacks coming from SDKs asynchronously
9
+ *
10
+ * @param response
11
+ * @param resolve
12
+ * @param reject
13
+ * @param errorMessage
14
+ */
15
+
16
+ export const handleAsyncCallback = (
17
+ response: { success: boolean },
18
+ resolve: PromiseResolve<void>,
19
+ reject: PromiseReject,
20
+ errorMessage: string
21
+ ) => {
22
+ if (response?.success) {
23
+ resolve();
24
+ } else {
25
+ reject({
26
+ code: -1,
27
+ message: errorMessage || "Unknown error.",
28
+ });
29
+ }
30
+ };
31
+
32
+ /**
33
+ * Handles callbacks coming from SDKs synchronously
34
+ *
35
+ * @param response
36
+ * @param errorMessage
37
+ */
38
+
39
+ export const handleSyncCallback = (
40
+ r: { success: boolean },
41
+ errorMessage: string
42
+ ) => {
43
+ if (r?.success) {
44
+ return;
45
+ } else {
46
+ throw {
47
+ code: -1,
48
+ message: errorMessage || "Unknown error.",
49
+ };
50
+ }
51
+ };
52
+
53
+ /**
54
+ * Wraps all SDK API methods with a exception handling code, and defines helper functions.
55
+ *
56
+ * @param fn
57
+ * @returns
58
+ */
59
+ export const exceptionWrapper = <T>(
60
+ fn: ({
61
+ onCallback,
62
+ }: {
63
+ onCallback: (r: { success: boolean }, errorMessage: string) => void;
64
+ onSuccess: PromiseResolve<T>;
65
+ onError: PromiseReject;
66
+ }) => void
67
+ ): T => {
68
+ let returnValue: T;
69
+ try {
70
+ fn({
71
+ onCallback: handleSyncCallback,
72
+ onSuccess: (response) => {
73
+ returnValue = response;
74
+ },
75
+ onError: (error) => {
76
+ logError(error);
77
+ throw error;
78
+ },
79
+ });
80
+ } catch (error) {
81
+ logError(error);
82
+ throw error;
83
+ }
84
+ return returnValue;
85
+ };
86
+
87
+ /**
88
+ * Wraps all SDK API methods with a promise, and defines helper functions.
89
+ *
90
+ * @param fn
91
+ * @returns
92
+ */
93
+ export const promiseWrapper = <T>(
94
+ fn: ({
95
+ resolve,
96
+ reject,
97
+ onCallback,
98
+ onSuccess,
99
+ onError,
100
+ }: {
101
+ resolve: PromiseResolve<T>;
102
+ reject: PromiseReject;
103
+ onCallback: (r: { success: boolean }, errorMessage: string) => void;
104
+ onSuccess: PromiseResolve<T>;
105
+ onError: PromiseReject;
106
+ }) => void
107
+ ) => {
108
+ return new Promise<T>((resolve, reject) => {
109
+ try {
110
+ return fn({
111
+ resolve,
112
+ reject,
113
+ onCallback: (r: { success: boolean }, errorMessage: string) =>
114
+ handleAsyncCallback(r, resolve as () => void, reject, errorMessage),
115
+ onSuccess: (response) => resolve(response),
116
+ onError: (error) => {
117
+ logError(error);
118
+ reject(error);
119
+ },
120
+ });
121
+ } catch (error) {
122
+ logError(error);
123
+ reject({
124
+ code: error?.code || -1,
125
+ message: error?.message || "Unknown error.",
126
+ });
127
+ }
128
+ });
129
+ };
@@ -77,29 +77,24 @@ const checkAndroidPermissions = async () => {
77
77
  throw "Situm > permissions > ACCESS_FINE_LOCATION, BLUETOOTH_CONNECT or BLUETOOTH_SCAN permissions not granted";
78
78
  };
79
79
 
80
- export const requestPermission = () =>
81
- // eslint-disable-next-line no-async-promise-executor
82
- new Promise<void>(async (resolve, reject) => {
83
- console.log(
84
- "Situm > permissions > Retrieving permissions for platform " + Platform.OS
85
- );
86
- if (Platform.OS === "ios") {
87
- await checkIOSPermissions()
88
- .then(() => resolve())
89
- .catch((e: string) => {
90
- console.warn(e);
91
- reject(e);
92
- });
93
- } else if (Platform.OS === "android") {
94
- await checkAndroidPermissions()
95
- .then(() => resolve())
96
- .catch((e: string) => {
97
- console.warn(e);
98
- reject(e);
99
- });
100
- }
80
+ export const requestPermission = async () => {
81
+ console.debug(
82
+ "Situm > permissions > Retrieving permissions for platform " + Platform.OS
83
+ );
101
84
 
102
- reject(`Situm > permissions > Platform '${Platform.OS}' not supported`);
103
- });
85
+ if (!["ios", "android"].includes(Platform.OS)) {
86
+ throw `Situm > permissions > Platform '${Platform.OS}' not supported`;
87
+ }
88
+
89
+ return await (Platform.OS === "ios"
90
+ ? checkIOSPermissions()
91
+ : checkAndroidPermissions()
92
+ )
93
+ .then(() => null)
94
+ .catch((e: string) => {
95
+ console.warn(e);
96
+ throw e;
97
+ });
98
+ };
104
99
 
105
100
  export default requestPermission;
@@ -1,35 +1,38 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
1
  /* eslint-disable @typescript-eslint/no-empty-function */
3
- import React, { useEffect, useImperativeHandle, useRef, useState } from "react";
4
- import { Platform, StyleSheet } from "react-native";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ import React, {
4
+ useCallback,
5
+ useEffect,
6
+ useImperativeHandle,
7
+ useRef,
8
+ useState,
9
+ } from "react";
10
+ import {
11
+ Platform,
12
+ type StyleProp,
13
+ StyleSheet,
14
+ type ViewStyle,
15
+ } from "react-native";
5
16
  import WebView from "react-native-webview";
6
17
  import type {
7
18
  WebViewErrorEvent,
8
19
  WebViewMessageEvent,
9
20
  } from "react-native-webview/lib/WebViewTypes";
10
21
 
11
- import {
12
- ErrorName,
13
- NavigationStatus,
14
- NavigationUpdateType,
15
- type Poi,
16
- } from "../../";
17
- import useSitum, { useCallbackRef } from "../hooks";
18
- import { setWebViewRef } from "../store";
19
- import { useDispatch } from "../store/utils";
22
+ import SitumPlugin from "../../sdk";
23
+ import useSitum from "../hooks";
20
24
  import {
21
25
  type MapViewError,
22
26
  type MapViewRef,
23
- type NavigateToPoiType,
27
+ type NavigateToPointPayload,
28
+ type NavigateToPoiPayload,
24
29
  type OnFloorChangedResult,
25
- type OnNavigationResult,
26
30
  type OnPoiDeselectedResult,
27
31
  type OnPoiSelectedResult,
28
- type WayfindingResult,
29
32
  } from "../types";
33
+ import { ErrorName } from "../types/constants";
30
34
  import { sendMessageToViewer } from "../utils";
31
- import Mapper from "../utils/mapper";
32
-
35
+ import ViewerMapper from "../utils/mapper";
33
36
  const SITUM_BASE_DOMAIN = "https://map-viewer.situm.com";
34
37
 
35
38
  const NETWORK_ERROR_CODE = {
@@ -41,37 +44,15 @@ const NETWORK_ERROR_CODE = {
41
44
  web: 0,
42
45
  };
43
46
 
44
- export interface MapViewProps {
45
- domain?: string;
46
- user?: string;
47
- apikey?: string;
48
- configuration?: {
49
- situmUser?: string;
50
- situmApiKey?: string;
51
- remoteIdentifier?: string;
52
- buildingIdentifier?: string;
53
- enablePoiClustering?: boolean;
54
- showPoiNames?: boolean;
55
- useRemoteConfig?: boolean;
56
- minZoom?: number;
57
- maxZoom?: number;
58
- initialZoom?: number;
59
- useDashboardTheme?: boolean;
60
- language?: string;
61
- };
62
- googleApikey?: string;
63
- onLoadError?: (event: MapViewError) => void;
64
- onLoad?: (event: WayfindingResult) => void;
65
- onFloorChanged?: (event: OnFloorChangedResult) => void;
66
- onPoiSelected?: (event: OnPoiSelectedResult) => void;
67
- onPoiDeselected?: (event: OnPoiDeselectedResult) => void;
68
- onNavigationRequested?: (event: OnNavigationResult) => void;
69
- onNavigationStarted?: (event: OnNavigationResult) => void;
70
- onNavigationError?: (event: OnNavigationResult) => void;
71
- onNavigationFinished?: (event: OnNavigationResult) => void;
72
- style?: any;
73
- iOSMapViewIndex?: string;
74
- }
47
+ export type MapViewConfiguration = {
48
+ apiDomain?: string;
49
+ viewerDomain?: string;
50
+ situmApiKey: string;
51
+ remoteIdentifier?: string;
52
+ buildingIdentifier: string;
53
+ directionality?: string;
54
+ language?: string;
55
+ };
75
56
 
76
57
  const viewerStyles = StyleSheet.create({
77
58
  webview: {
@@ -80,40 +61,42 @@ const viewerStyles = StyleSheet.create({
80
61
  },
81
62
  });
82
63
 
64
+ export interface MapViewProps {
65
+ configuration: MapViewConfiguration;
66
+ style?: StyleProp<ViewStyle>;
67
+ onPoiSelected?: (event: OnPoiSelectedResult) => void;
68
+ onPoiDeselected?: (event: OnPoiDeselectedResult) => void;
69
+ onLoad?: (event: any) => void;
70
+ onLoadError?: (event: MapViewError) => void;
71
+ onFloorChanged?: (event: OnFloorChangedResult) => void;
72
+ }
73
+
83
74
  const MapView = React.forwardRef<MapViewRef, MapViewProps>(
84
75
  (
85
76
  {
86
- domain,
87
- // user,
88
- // apikey,
89
77
  configuration,
78
+ style,
90
79
  onLoad = () => {},
91
80
  onLoadError = () => {},
92
- onFloorChanged = () => {},
93
81
  onPoiSelected = () => {},
94
82
  onPoiDeselected = () => {},
95
- onNavigationRequested = () => {},
96
- onNavigationStarted = () => {},
97
- onNavigationError = () => {},
98
- onNavigationFinished = () => {},
99
- style,
100
- //iOSMapViewIndex,
83
+ onFloorChanged = () => {},
101
84
  },
102
85
  ref
103
86
  ) => {
104
- const dispatch = useDispatch();
105
- const webViewRef = useRef(null);
87
+ const webViewRef = useRef<WebView>();
88
+
106
89
  // Local states
107
90
  const [mapLoaded, setMapLoaded] = useState<boolean>(false);
108
-
91
+ const [buildingIdentifier, setBuildingIdentifier] = useState<string>(
92
+ configuration.buildingIdentifier
93
+ );
109
94
  const {
110
- user: fullUser,
111
- pois,
95
+ init,
112
96
  location,
113
97
  directions,
114
98
  navigation,
115
- currentBuilding,
116
- initializeBuildingById,
99
+
117
100
  calculateRoute,
118
101
  startNavigation,
119
102
  stopNavigation,
@@ -125,12 +108,50 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
125
108
  webViewRef.current &&
126
109
  mapLoaded &&
127
110
  location?.position?.buildingIdentifier ===
128
- configuration?.buildingIdentifier
111
+ configuration.buildingIdentifier
129
112
  ) {
130
- sendMessageToViewer(webViewRef.current, Mapper.followUser(true));
113
+ sendMessageToViewer(webViewRef.current, ViewerMapper.followUser(true));
131
114
  }
132
115
  };
133
116
 
117
+ // Helper functions used on imperative handler
118
+ // Navigation
119
+ const _navigateToPoi = useCallback((payload: NavigateToPoiPayload) => {
120
+ if (!webViewRef.current || !payload || !payload.identifier) return;
121
+
122
+ sendMessageToViewer(
123
+ webViewRef.current,
124
+ ViewerMapper.navigateToPoi(payload)
125
+ );
126
+ }, []);
127
+
128
+ const _navigateToPoint = useCallback((payload: NavigateToPointPayload) => {
129
+ if (
130
+ !webViewRef.current ||
131
+ (!payload?.lat && !payload?.lng && !payload?.floorIdentifier)
132
+ )
133
+ return;
134
+
135
+ sendMessageToViewer(
136
+ webViewRef.current,
137
+ ViewerMapper.navigateToPoint(payload)
138
+ );
139
+ }, []);
140
+
141
+ // Cartography
142
+ const _selectPoi = useCallback((poiId: number) => {
143
+ if (!webViewRef.current) {
144
+ return;
145
+ }
146
+ if (SitumPlugin.navigationIsRunning()) {
147
+ console.error(
148
+ "Situm > hook > Navigation on course, poi selection is unavailable"
149
+ );
150
+ return;
151
+ }
152
+ sendMessageToViewer(webViewRef.current, ViewerMapper.selectPoi(poiId));
153
+ }, []);
154
+
134
155
  /**
135
156
  * API exported to the outside world from the MapViewer
136
157
  *
@@ -144,51 +165,6 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
144
165
  * }}
145
166
  * onLoad={onLoad} />
146
167
  */
147
- const navigateToPoiRef = useCallbackRef(
148
- ({ poi, poiId }: { poi?: Poi; poiId?: number }) => {
149
- if (!webViewRef.current || (!poi && !poiId)) return;
150
- const validPoi = pois?.find(
151
- (p) =>
152
- p?.identifier === poiId?.toString() ||
153
- // @ts-ignore
154
- p?.identifier === poi?.id?.toString()
155
- );
156
- if (!validPoi) {
157
- console.error("Situm > hook > Invalid value as poi or poiId");
158
- return;
159
- }
160
-
161
- sendMessageToViewer(
162
- webViewRef.current,
163
- Mapper.navigateToPoi({
164
- // @ts-ignore
165
- navigationTo: poi?.id || poiId,
166
- } as NavigateToPoiType)
167
- );
168
- },
169
- [pois]
170
- );
171
-
172
- const selectPoiRef = useCallbackRef(
173
- (poiId: number) => {
174
- if (!webViewRef.current) {
175
- return;
176
- }
177
- const poi = pois?.find((p) => p?.identifier === poiId?.toString());
178
- if (!poi) {
179
- console.error("Situm > hook > Invalid value as poiId");
180
- return;
181
- }
182
- if (navigation.status !== NavigationStatus.STOP) {
183
- console.error(
184
- "Situm > hook > Navigation on course, poi selection is unavailable"
185
- );
186
- return;
187
- }
188
- sendMessageToViewer(webViewRef.current, Mapper.selectPoi(poiId));
189
- },
190
- [pois, navigation?.status]
191
- );
192
168
 
193
169
  useImperativeHandle(
194
170
  ref,
@@ -196,118 +172,102 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
196
172
  return {
197
173
  followUser() {
198
174
  webViewRef.current &&
199
- sendMessageToViewer(webViewRef.current, Mapper.followUser(true));
175
+ sendMessageToViewer(
176
+ webViewRef.current,
177
+ ViewerMapper.followUser(true)
178
+ );
200
179
  },
201
180
  unFollowUser() {
202
181
  webViewRef.current &&
203
- sendMessageToViewer(webViewRef.current, Mapper.followUser(false));
182
+ sendMessageToViewer(
183
+ webViewRef.current,
184
+ ViewerMapper.followUser(false)
185
+ );
204
186
  },
205
187
  selectPoi(poiId: number) {
206
- selectPoiRef.current(poiId);
188
+ _selectPoi(poiId);
207
189
  },
208
190
  deselectPoi() {
209
191
  webViewRef.current &&
210
- sendMessageToViewer(webViewRef.current, Mapper.selectPoi(null));
192
+ sendMessageToViewer(
193
+ webViewRef.current,
194
+ ViewerMapper.selectPoi(null)
195
+ );
196
+ },
197
+ navigateToPoi(payload): void {
198
+ _navigateToPoi(payload);
211
199
  },
212
- navigateToPoi({ poi, poiId }: { poi?: Poi; poiId?: number }): void {
213
- navigateToPoiRef.current({ poi, poiId });
200
+ navigateToPoint(payload: NavigateToPointPayload): void {
201
+ _navigateToPoint(payload);
214
202
  },
215
203
  cancelNavigation(): void {
216
204
  if (!webViewRef.current) return;
217
205
  stopNavigation();
218
- sendMessageToViewer(webViewRef.current, Mapper.cancelNavigation());
206
+ sendMessageToViewer(
207
+ webViewRef.current,
208
+ ViewerMapper.cancelNavigation()
209
+ );
219
210
  },
220
211
  };
221
212
  },
222
- [stopNavigation, navigateToPoiRef, selectPoiRef]
213
+ [stopNavigation, _navigateToPoi, _navigateToPoint, _selectPoi]
223
214
  );
224
215
 
225
216
  useEffect(() => {
226
- configuration?.buildingIdentifier &&
227
- initializeBuildingById(configuration.buildingIdentifier);
228
- // eslint-disable-next-line react-hooks/exhaustive-deps
229
- }, [configuration?.buildingIdentifier]);
217
+ if (!error) return;
230
218
 
231
- useEffect(() => {
232
- if (error) {
233
- console.error(
234
- "Error code:",
235
- error.code ? error.code : " no code provided"
236
- );
237
- console.error("Error detected:", error.message);
238
- }
219
+ console.error(
220
+ "Error code:",
221
+ error.code ? error.code : " no code provided"
222
+ );
223
+ console.error("Error detected:", error.message);
239
224
  }, [error]);
240
225
 
241
226
  // Updated SDK location
242
227
  useEffect(() => {
243
228
  if (!webViewRef.current || !location) return;
244
- //console.debug('location', location);
245
229
 
246
- sendMessageToViewer(webViewRef.current, Mapper.location(location));
230
+ sendMessageToViewer(webViewRef.current, ViewerMapper.location(location));
247
231
  }, [location]);
248
232
 
249
233
  // Updated SDK navigation
250
234
  useEffect(() => {
251
235
  if (!webViewRef.current || !navigation) return;
252
236
 
253
- sendMessageToViewer(webViewRef.current, Mapper.navigation(navigation));
254
-
255
- if (navigation.status === NavigationStatus.START) {
256
- onNavigationStarted({
257
- navigation: Mapper.routeToResult(navigation),
258
- } as OnNavigationResult);
259
- }
260
- if (navigation?.type === NavigationUpdateType.destinationReached) {
261
- onNavigationFinished({
262
- navigation: Mapper.navigationToResult(navigation),
263
- } as OnNavigationResult);
264
- }
265
- // eslint-disable-next-line react-hooks/exhaustive-deps
237
+ sendMessageToViewer(
238
+ webViewRef.current,
239
+ ViewerMapper.navigation(navigation)
240
+ );
266
241
  }, [navigation]);
267
242
 
268
243
  // Updated SDK route
269
244
  useEffect(() => {
270
245
  if (!webViewRef.current || !directions) return;
271
246
 
272
- sendMessageToViewer(webViewRef.current, Mapper.route(directions));
247
+ sendMessageToViewer(webViewRef.current, ViewerMapper.route(directions));
273
248
  }, [directions]);
274
249
 
250
+ // Update language
275
251
  useEffect(() => {
276
- if (!webViewRef.current || !configuration?.language || !mapLoaded) return;
252
+ if (!webViewRef.current || !configuration.language || !mapLoaded) return;
277
253
 
278
254
  sendMessageToViewer(
279
255
  webViewRef.current,
280
- Mapper.setLanguage(configuration.language)
256
+ ViewerMapper.setLanguage(configuration.language)
281
257
  );
282
- }, [configuration?.language, mapLoaded]);
258
+ }, [configuration.language, mapLoaded]);
283
259
 
260
+ // Update SDK configuration
284
261
  useEffect(() => {
285
262
  if (webViewRef.current && mapLoaded) {
286
263
  sendMessageToViewer(
287
264
  webViewRef.current,
288
- Mapper.initialConfiguration(
289
- style,
290
- configuration?.enablePoiClustering,
291
- configuration?.showPoiNames,
292
- configuration?.minZoom,
293
- configuration?.maxZoom,
294
- configuration?.initialZoom,
295
- configuration?.useDashboardTheme
296
- )
265
+ ViewerMapper.initialConfiguration(style)
297
266
  );
298
267
  }
299
- }, [
300
- webViewRef,
301
- mapLoaded,
302
- style,
303
- configuration?.enablePoiClustering,
304
- configuration?.showPoiNames,
305
- configuration?.minZoom,
306
- configuration?.maxZoom,
307
- configuration?.initialZoom,
308
- configuration?.useDashboardTheme,
309
- ]);
268
+ }, [webViewRef, mapLoaded, style]);
310
269
 
270
+ // Update follow user
311
271
  useEffect(() => {
312
272
  mapLoaded && sendFollowUser();
313
273
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -317,39 +277,15 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
317
277
  const eventParsed = JSON.parse(event.nativeEvent.data);
318
278
  switch (eventParsed.type) {
319
279
  case "app.map_is_ready":
320
- onLoad({
321
- status: "SUCCESS",
322
- message: "Map is ready!",
323
- } as WayfindingResult);
324
-
280
+ init();
281
+ onLoad && onLoad("");
325
282
  setMapLoaded(true);
326
283
  break;
327
284
  case "directions.requested":
328
- calculateRoute({
329
- originId: JSON.parse(event.nativeEvent.data).payload
330
- .originIdentifier,
331
- destinationId: JSON.parse(event.nativeEvent.data).payload
332
- .destinationIdentifier,
333
- directionsOptions: JSON.parse(event.nativeEvent.data).payload
334
- .directionsOptions,
335
- });
285
+ calculateRoute(eventParsed.payload);
336
286
  break;
337
287
  case "navigation.requested":
338
- startNavigation({
339
- originId: JSON.parse(event.nativeEvent.data).payload
340
- .originIdentifier,
341
- destinationId: JSON.parse(event.nativeEvent.data).payload
342
- .destinationIdentifier,
343
- directionsOptions: JSON.parse(event.nativeEvent.data).payload
344
- .directionsOptions,
345
- callback: (status, _navigation?) =>
346
- status === "success" && navigation
347
- ? onNavigationRequested({
348
- navigation: Mapper.routeToResult(_navigation),
349
- } as OnNavigationResult)
350
- : status === "error" &&
351
- onNavigationError({} as OnNavigationResult),
352
- });
288
+ startNavigation(eventParsed.payload);
353
289
  break;
354
290
  case "navigation.stopped":
355
291
  stopNavigation();
@@ -366,14 +302,12 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
366
302
  case "cartography.building_selected":
367
303
  if (
368
304
  !eventParsed.payload.identifier ||
369
- (currentBuilding &&
370
- eventParsed.payload.identifier.toString() ===
371
- currentBuilding.buildingIdentifier)
305
+ eventParsed.payload.identifier.toString() === buildingIdentifier
372
306
  ) {
373
307
  return;
308
+ } else {
309
+ setBuildingIdentifier(eventParsed.payload.identifier.toString());
374
310
  }
375
-
376
- initializeBuildingById(eventParsed.payload.identifier.toString());
377
311
  break;
378
312
  default:
379
313
  break;
@@ -384,31 +318,27 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
384
318
  <WebView
385
319
  ref={webViewRef}
386
320
  source={{
387
- uri: `${domain || SITUM_BASE_DOMAIN}/${
388
- configuration?.remoteIdentifier
321
+ uri: `${configuration.viewerDomain || SITUM_BASE_DOMAIN}/${
322
+ configuration.remoteIdentifier
389
323
  ? `id/${configuration.remoteIdentifier}`
390
324
  : ""
391
- }?email=${fullUser?.email}&apikey=${
392
- fullUser?.apiKey
325
+ }?&apikey=${
326
+ configuration.situmApiKey
393
327
  }&wl=true&global=true&mode=embed${
394
- configuration?.buildingIdentifier
328
+ configuration.buildingIdentifier
395
329
  ? `&buildingid=${configuration.buildingIdentifier}`
396
330
  : ""
397
331
  }&show=rts`,
398
332
  }}
399
- style={viewerStyles.webview}
333
+ style={StyleSheet.flatten([viewerStyles.webview, style])}
400
334
  limitsNavigationsToAppBoundDomains={true}
401
335
  javaScriptEnabled={true}
402
336
  domStorageEnabled={true}
403
337
  startInLoadingState={true}
404
338
  cacheEnabled
405
339
  onMessage={handleRequestFromViewer}
406
- // This is called on a lot of interactions with the map because of url change probably
407
- onLoadEnd={() => {
408
- if (!webViewRef.current) return;
409
- dispatch(setWebViewRef(webViewRef));
410
- }}
411
340
  onError={(evt: WebViewErrorEvent) => {
341
+ if (!onLoadError) return;
412
342
  const { nativeEvent } = evt;
413
343
  // TODO: on render error should probably still try to render an html
414
344
  if (nativeEvent.code === NETWORK_ERROR_CODE[Platform.OS]) {