@mapsindoors/react-native-maps-indoors-mapbox 2.8.0 → 2.9.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 (45) hide show
  1. package/README.md +84 -1
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/mapsindoorsrn/MapsIndoorsPackage.java +10 -0
  4. package/android/src/main/java/com/mapsindoorsrn/core/BaseMapCacheProviders.java +94 -0
  5. package/android/src/main/java/com/mapsindoorsrn/core/DirectionsRendererModule.java +140 -49
  6. package/android/src/main/java/com/mapsindoorsrn/core/DirectionsServiceModule.java +16 -7
  7. package/android/src/main/java/com/mapsindoorsrn/core/MPDisplayRuleModule.java +1 -1
  8. package/android/src/main/java/com/mapsindoorsrn/core/MapControlModule.java +115 -20
  9. package/android/src/main/java/com/mapsindoorsrn/core/MapsIndoorsModule.java +200 -11
  10. package/android/src/main/java/com/mapsindoorsrn/core/RnGson.java +110 -0
  11. package/android/src/main/java/com/mapsindoorsrn/core/UtilsModule.java +1 -1
  12. package/android/src/main/java/com/mapsindoorsrn/core/models/DirectionsRendererOptionsModel.java +498 -0
  13. package/index.ts +25 -0
  14. package/ios/.swift-format +79 -0
  15. package/ios/core/DirectionsRendererBridge.m +11 -0
  16. package/ios/core/DirectionsRendererModule.swift +162 -1
  17. package/ios/core/DirectionsRendererOptions.swift +352 -0
  18. package/ios/core/MapsIndoorsBridge.m +14 -1
  19. package/ios/core/MapsIndoorsData.swift +1 -0
  20. package/ios/core/MapsIndoorsModule.swift +180 -21
  21. package/ios/core/UtilsModule.swift +57 -45
  22. package/package.json +1 -1
  23. package/react-native-maps-indoors-mapbox.podspec +2 -2
  24. package/specs/NativeDirectionsRendererModule.ts +3 -0
  25. package/specs/NativeMapsIndoorsModule.ts +6 -1
  26. package/src/core/EventNames.ts +3 -0
  27. package/src/core/MPDirectionsRenderer.ts +76 -1
  28. package/src/core/MPDirectionsRendererOptions.ts +287 -0
  29. package/src/core/MPError.ts +48 -1
  30. package/src/core/MPLanguageTag.ts +222 -0
  31. package/src/core/MPLegBoundaryIcons.ts +130 -0
  32. package/src/core/MPRouteAnimationType.ts +24 -0
  33. package/src/core/MPRouteArrowStyle.ts +28 -0
  34. package/src/core/MPRouteMarkerDisplayRule.ts +140 -0
  35. package/src/core/MPRouteStampType.ts +24 -0
  36. package/src/core/MPSolution.ts +33 -2
  37. package/src/core/MPStrokeStyle.ts +22 -0
  38. package/src/core/MapsIndoors.ts +155 -11
  39. package/src/core/OnBaseMapCacheProgressListener.ts +20 -0
  40. package/src/core/__tests__/MPBounds.test.ts +109 -0
  41. package/src/core/__tests__/MPFilter.test.ts +76 -0
  42. package/src/core/__tests__/MPLanguageTag.test.ts +168 -0
  43. package/src/core/__tests__/MPPoint.test.ts +82 -0
  44. package/src/core/__tests__/MPSolution.test.ts +107 -0
  45. package/src/core/__tests__/MapsIndoors.language.test.ts +180 -0
package/README.md CHANGED
@@ -2,10 +2,93 @@
2
2
 
3
3
  ## Documentation
4
4
 
5
- Visit [our reference document site](https://app.mapsindoors.com/mapsindoors/reference/react-native/mapbox/2.8.0/index.html) to get an overview of what the MapsIndoors SDK offers.
5
+ Visit [our reference document site](https://app.mapsindoors.com/mapsindoors/reference/react-native/mapbox/2.9.0/index.html) to get an overview of what the MapsIndoors SDK offers.
6
6
 
7
7
  ## Changelog
8
8
 
9
+ ### [2.9.0] - 2026-09-17
10
+
11
+ #### Added
12
+
13
+ ##### Offline base map tiles support [Mapbox]
14
+
15
+ - Offline Mapbox base-map tiles. `MapsIndoors.setBaseMapTilesEnabled(enabled, apiKey)` marks a
16
+ solution for base-map caching, and `MapsIndoors.synchronizeBaseMapTiles(onProgress?, apiKeys?)`
17
+ downloads the tiles - the outdoor map underneath MapsIndoors, which `cacheData` does not cover.
18
+ Both are needed for a map that renders with no network connection. Progress is reported through
19
+ the optional `onProgress` listener, since the download can take minutes.
20
+ `MapsIndoors.isBaseMapCachingSupported()` reports whether the map provider can cache at all
21
+
22
+ ##### Improved DirectionsRenderer
23
+
24
+ - `MPDirectionsRenderer.setOptions(options)` and `getOptions()`, which style a rendered route from a
25
+ single `MPDirectionsRendererOptions` object - line color, opacity, weight and `MPStrokeStyle`, the
26
+ background halo, the animated overlay and its `MPRouteAnimationType`, a repeating
27
+ `MPRouteStampType` stamp with its `MPRouteArrowStyle`, `MPRouteMarkerDisplayRule` styling for the
28
+ route's start and end markers, per connector `MPLegBoundaryIcons`, 3D elevation (Mapbox only) and
29
+ the camera's fit-bounds max zoom. Each option resolves on its own - the value set here, then the
30
+ solution level default from the CMS, then the SDK's built-in default - so options left out are
31
+ inherited rather than reset. This supersedes `setPolylineColors` and `setAnimatedPolyline`, which
32
+ are now deprecated
33
+ - `MPDirectionsRenderer.finishGuidance(usagePercentage?)`, which signals that guidance on the
34
+ current route has finished, optionally supplying how much of the route was travelled
35
+
36
+ ##### Enhanced Language support
37
+
38
+ - `resolveLanguageTag(tag, availableLanguages)` and `normalizeLanguageTag(tag)`, for turning a
39
+ device locale into the exact language tag a solution publishes before calling
40
+ `MapsIndoors.setLanguage`. `resolveLanguageTag('zh-Hant-TW', solution.availableLanguages)`
41
+ returns `'zh-Hant'`
42
+ - `MPSolution.resolveLanguage(language)`, the same lookup against that solution's own languages
43
+ #### Changed
44
+
45
+ - Updated the MapsIndoors Android SDK to 4.22.0 and the iOS SDK to 4.20.0, the releases that carry
46
+ the base-map tile cache
47
+ - `MPSolution.hasLanguage` now matches language tags the way the native SDKs do, instead of
48
+ requiring an exact string. Casing is ignored, the ICU underscore form is accepted (`zh_Hans`),
49
+ legacy region-only Chinese tags resolve to their script (`zh-CN` matches `zh-Hans`, `zh-TW`
50
+ matches `zh-Hant`), and a more specific tag falls back to a less specific one (`en-US` matches
51
+ `en`). It stays deliberately strict about ambiguity: bare `zh` does not match a solution that
52
+ publishes only `zh-Hans` and `zh-Hant`, because there is no way to tell which script is wanted
53
+ - `MapsIndoors.setLanguage` documents what its returned boolean means on each platform. On Android
54
+ it is `false` for a language the solution does not have, and also while the SDK is still loading
55
+ or synchronizing - in which case the change is queued rather than lost. On iOS it reports only
56
+ that the tag was accepted, with no check against the solution. Read the language back with
57
+ `getLanguage` to confirm a change took effect
58
+ - `MapsIndoors.setLanguage` resolves `false` for an empty language tag without calling into the
59
+ native SDK, matching Android's own precondition. iOS would otherwise accept it and store an
60
+ empty language
61
+
62
+ #### Fixed
63
+
64
+ - The iOS geometry helpers never decoded the polygon they were given, because
65
+ `JSONDecoder` is not polymorphic and the SDK's internal `mp_polygon` accessors are nil on a
66
+ freshly decoded value. `MPPolygon.contains` therefore always answered `false`, `getArea` always
67
+ `0`, and `distanceToClosestEdge` resolved `undefined` despite being typed `Promise<number>`. The
68
+ concrete geometry type is now decoded from the GeoJSON `type` discriminator, as on Android, so
69
+ multi-polygon geometry works by construction
70
+ - Serialising SDK models to the bridge on Android walked native memory by reflection. `MPLocation`
71
+ holds an `MPIcon` whose layer holds an `android.graphics.Bitmap`, and the buffer behind a Bitmap
72
+ carries a `Cleaner` that is linked to every other live Cleaner in the process - so the work grew
73
+ with whatever the host app had allocated, not with the map data. This only showed up on physical
74
+ devices with a real app around them
75
+ - `MapsIndoors.setLanguage` always resolved `null` on iOS, despite being typed `Promise<boolean>`.
76
+ It now resolves the native SDK's real result, as it already did on Android
77
+ - `MapsIndoors.getAvailableLanguages` and `getDefaultLanguage` rejected with an unparseable error
78
+ on iOS when called before the solution had loaded, so the `MPError` never reached the caller.
79
+ Both now reject with an `MPError`, as they already did on Android
80
+ - `MapsIndoors.getDefaultLanguage` resolved `null` on Android when no solution was loaded, despite
81
+ being typed `Promise<string>`. It now rejects with an `MPError`, matching iOS
82
+ - `MapsIndoors.getSolution` resolved `null` on Android whenever no solution was loaded - including
83
+ the moment right after a language change, which reloads the solution. Callers either crashed in
84
+ `JSON.parse` or got a solution whose `availableLanguages` was `undefined`, so `hasLanguage`
85
+ answered `false` for every tag. It now rejects with an `MPError`, matching iOS
86
+ - `MapsIndoors.getLocations` discarded a native rejection instead of propagating it, then failed
87
+ in `JSON.parse` with "Unexpected character: u". The real error now reaches the caller
88
+ - `MPError.parse` threw a `SyntaxError` when a rejection did not carry the native SDK's JSON
89
+ payload - a bridge-level or JavaScript error - replacing the real message with "JSON Parse
90
+ error: Unexpected character". It now wraps such a message as an unknown error and keeps the text
91
+
9
92
  ### [2.8.0] - 2026-08-17
10
93
 
11
94
  #### Changed
@@ -106,7 +106,7 @@ dependencies {
106
106
  }
107
107
 
108
108
  implementation 'com.mapbox.maps:android-ndk27:11.16.1'
109
- implementation 'com.mapspeople.mapsindoors:mapbox-ndk27:4.18.6'
109
+ implementation 'com.mapspeople.mapsindoors:mapbox-ndk27:4.22.0'
110
110
  implementation 'com.facebook.react:react-native:+' // From node_modules
111
111
  implementation 'androidx.core:core-ktx:1.3.2'
112
112
  implementation 'com.github.bumptech.glide:glide:4.16.0'
@@ -11,6 +11,9 @@ import com.facebook.react.module.model.ReactModuleInfoProvider;
11
11
  import com.facebook.react.uimanager.ViewManager;
12
12
  import com.mapsindoors.core.OnResultReadyListener;
13
13
  import com.mapsindoors.core.errors.MIError;
14
+ import com.mapsindoors.mapbox.MPMapboxBaseMapCacheProvider;
15
+ import com.mapsindoors.mapbox.MPMapboxStyleSource;
16
+ import com.mapsindoorsrn.core.BaseMapCacheProviders;
14
17
  import com.mapsindoorsrn.core.DirectionsRendererModule;
15
18
  import com.mapsindoorsrn.core.DirectionsServiceModule;
16
19
  import com.mapsindoorsrn.core.MPDisplayRuleModule;
@@ -28,6 +31,13 @@ public class MapsIndoorsPackage extends TurboReactPackage implements OnResultRea
28
31
  private MapsIndoorsViewManager viewManager;
29
32
  private ReactApplicationContext mContext;
30
33
 
34
+ public MapsIndoorsPackage() {
35
+ // The style is an explicit choice with no default in the SDK, because caching the wrong
36
+ // style is silent until the device goes offline. MapsIndoorsDefault is the right one here:
37
+ // the React Native MapView always renders the MapsIndoors style.
38
+ BaseMapCacheProviders.setFactory(() -> new MPMapboxBaseMapCacheProvider(MPMapboxStyleSource.MapsIndoorsDefault.INSTANCE));
39
+ }
40
+
31
41
  private MapControlModule getOrCreateMapControlModule(ReactApplicationContext context) {
32
42
  if (mapControlModule == null) {
33
43
  synchronized (this) {
@@ -0,0 +1,94 @@
1
+ package com.mapsindoorsrn.core;
2
+
3
+ import android.content.Context;
4
+
5
+ import androidx.annotation.NonNull;
6
+ import androidx.annotation.Nullable;
7
+
8
+ import com.mapsindoors.core.MPDataSetCacheManager;
9
+ import com.mapsindoors.core.models.MPIMapProviderBaseMapCache;
10
+
11
+ /**
12
+ * The seam that lets the shared React Native core reach the map provider's base-map tile cache.
13
+ *
14
+ * <p>A {@link MPIMapProviderBaseMapCache} implementation is map-provider specific — {@code
15
+ * MPMapboxBaseMapCacheProvider} caches into Mapbox's tile store, {@code MPGoogleBaseMapCacheProvider}
16
+ * reports that Google Maps cannot cache at all — and this core module is compiled into both the Mapbox
17
+ * and the Google Maps React Native package. It therefore cannot name either implementation. Each
18
+ * package's {@code MapsIndoorsPackage} installs a factory here instead, and {@link
19
+ * #ensureRegistered(Context)} builds from it on first use.</p>
20
+ *
21
+ * <p>Registration is deferred rather than done at app start for two reasons: it avoids initializing
22
+ * {@link MPDataSetCacheManager} in apps that never cache anything, and the registration is held by the
23
+ * manager instance, so it has to be re-done after {@code MapsIndoors.destroy()} tears that instance
24
+ * down.</p>
25
+ */
26
+ public final class BaseMapCacheProviders {
27
+
28
+ /**
29
+ * Builds the base-map tile cache for the map provider the hosting package renders with.
30
+ */
31
+ public interface Factory {
32
+ /**
33
+ * Creates a new base-map tile cache. Called at most once per {@link MPDataSetCacheManager}
34
+ * instance, never with a map view in existence — an implementation must not need one.
35
+ *
36
+ * @return The map provider's base-map tile cache
37
+ */
38
+ @NonNull
39
+ MPIMapProviderBaseMapCache create();
40
+ }
41
+
42
+ @Nullable
43
+ private static volatile Factory sFactory;
44
+
45
+ private BaseMapCacheProviders() { }
46
+
47
+ /**
48
+ * Installs the factory for the map provider in use. Called by each map package's
49
+ * {@code MapsIndoorsPackage} as the package is constructed.
50
+ *
51
+ * @param factory The factory to build base-map tile caches from, or null to uninstall the current
52
+ * one
53
+ */
54
+ public static void setFactory(@Nullable Factory factory) {
55
+ sFactory = factory;
56
+ }
57
+
58
+ /**
59
+ * Makes sure a base-map tile cache is registered with the SDK, building one from the installed
60
+ * factory if there isn't one already.
61
+ *
62
+ * <p>Idempotent, and safe to call on every base-map operation: an already-registered provider is
63
+ * returned as-is rather than replaced, so caching already in flight is never orphaned.</p>
64
+ *
65
+ * @param context Context to initialize {@link MPDataSetCacheManager} with, if it isn't already
66
+ * @return The registered base-map tile cache, or null if no factory has been installed. A null
67
+ * return is not an error to report on its own — the SDK reports
68
+ * {@code MIError.BASEMAP_CACHE_NOT_REGISTERED} for the operation that needed it
69
+ */
70
+ @Nullable
71
+ public static synchronized MPIMapProviderBaseMapCache ensureRegistered(@NonNull Context context) {
72
+ if (!MPDataSetCacheManager.isInitialized()) {
73
+ MPDataSetCacheManager.initialize(context);
74
+ }
75
+
76
+ final MPDataSetCacheManager manager = MPDataSetCacheManager.getInstance();
77
+ final MPIMapProviderBaseMapCache registered = manager.getBaseMapCacheProvider();
78
+
79
+ if (registered != null) {
80
+ return registered;
81
+ }
82
+
83
+ final Factory factory = sFactory;
84
+
85
+ if (factory == null) {
86
+ return null;
87
+ }
88
+
89
+ final MPIMapProviderBaseMapCache provider = factory.create();
90
+ manager.setBaseMapCacheProvider(provider);
91
+
92
+ return provider;
93
+ }
94
+ }
@@ -22,6 +22,8 @@ import com.google.gson.Gson;
22
22
  import com.google.gson.reflect.TypeToken;
23
23
  import com.mapsindoors.core.MPCameraViewFitMode;
24
24
  import com.mapsindoors.core.MPDirectionsRenderer;
25
+ import com.mapsindoors.core.MPDirectionsRendererConfig;
26
+ import com.mapsindoors.core.MPDirectionsRendererOptions;
25
27
  import com.mapsindoors.core.MPRoute;
26
28
  import com.mapsindoors.core.MPRouteStopIconProvider;
27
29
  import com.mapsindoors.core.MapControl;
@@ -31,6 +33,7 @@ import com.mapsindoors.core.errors.MIErrorEnum;
31
33
  import com.mapsindoors.core.errors.MapsIndoorsException;
32
34
  import com.mapsindoorsrn.core.models.BitmapStopIconConfig;
33
35
  import com.facebook.react.module.annotations.ReactModule;
36
+ import com.mapsindoorsrn.core.models.DirectionsRendererOptionsModel;
34
37
  import com.mapsindoorsrn.core.models.MPError;
35
38
  import com.mapsindoorsrn.core.models.RouteStopIconConfigModel;
36
39
 
@@ -48,8 +51,16 @@ public class DirectionsRendererModule extends ReactContextBaseJavaModule impleme
48
51
 
49
52
  private MapControl mMapControl;
50
53
  private MPDirectionsRenderer mRenderer;
54
+ /**
55
+ * The renderer's solution served styling, snapshotted before the first runtime override is
56
+ * applied. Options the app leaves out resolve against this, so they stay inherited from the
57
+ * solution instead of being reset - and instead of accumulating the previous override, which
58
+ * setting a fresh set of options is meant to clear.
59
+ */
60
+ private MPDirectionsRendererConfig mSolutionConfig;
61
+ private boolean mSolutionConfigCaptured;
51
62
  private final ReactApplicationContext mCtx;
52
- private final Gson gson = new Gson();
63
+ private final Gson gson = RnGson.create();
53
64
 
54
65
 
55
66
  public DirectionsRendererModule(@NonNull ReactApplicationContext reactContext, MapControlModule mapControl) {
@@ -113,7 +124,7 @@ public class DirectionsRendererModule extends ReactContextBaseJavaModule impleme
113
124
  try {
114
125
  mRenderer.selectLegIndex(legIndex);
115
126
  } catch (IllegalStateException e) {
116
- promise.reject(e.getMessage(), new Gson().toJson(MPError.fromMIError(new MIError(MIErrorEnum.ROUTING_UNKNOWN_ERROR, e.getMessage()))));
127
+ promise.reject(e.getMessage(), gson.toJson(MPError.fromMIError(new MIError(MIErrorEnum.ROUTING_UNKNOWN_ERROR, e.getMessage()))));
117
128
  return;
118
129
  }
119
130
  promise.resolve(null);
@@ -214,46 +225,116 @@ public class DirectionsRendererModule extends ReactContextBaseJavaModule impleme
214
225
  }
215
226
  }
216
227
 
228
+ @ReactMethod
229
+ public void setOptions(String optionsString, final Promise promise) {
230
+ if (mRenderer != null) {
231
+ DirectionsRendererOptionsModel options;
232
+ try {
233
+ options = gson.fromJson(optionsString, DirectionsRendererOptionsModel.class);
234
+ } catch (Exception e) {
235
+ promise.reject("Options could not be parsed", e);
236
+ return;
237
+ }
238
+ if (options == null) {
239
+ promise.reject("Options could not be parsed", new MapsIndoorsException("Options could not be parsed"));
240
+ return;
241
+ }
242
+ if (!mSolutionConfigCaptured) {
243
+ mSolutionConfig = mRenderer.getConfig();
244
+ mSolutionConfigCaptured = true;
245
+ }
246
+ try {
247
+ // The config carries the styling the renderer resolves against the solution config,
248
+ // the options the polyline styling and animation timing. Both are built before
249
+ // either is applied, because parsing a colour can throw - applying the config first
250
+ // would leave the route restyled by a call the promise reports as failed.
251
+ MPDirectionsRendererConfig config = options.toMPDirectionsRendererConfig(mSolutionConfig);
252
+ MPDirectionsRendererOptions rendererOptions = options.toMPDirectionsRendererOptions();
253
+ mRenderer.setConfig(config);
254
+ mRenderer.setOptions(rendererOptions);
255
+ } catch (IllegalArgumentException e) {
256
+ promise.reject(e);
257
+ return;
258
+ }
259
+ promise.resolve(null);
260
+ } else {
261
+ rejectPromise(promise);
262
+ }
263
+ }
264
+
265
+ @ReactMethod
266
+ public void getOptions(final Promise promise) {
267
+ if (mRenderer != null) {
268
+ promise.resolve(gson.toJson(DirectionsRendererOptionsModel.from(mRenderer.getOptions(), mRenderer.getConfig())));
269
+ } else {
270
+ rejectPromise(promise);
271
+ }
272
+ }
273
+
274
+ @ReactMethod
275
+ public void finishGuidance(double usagePercentage, final Promise promise) {
276
+ if (mRenderer != null) {
277
+ // A negative value means the app did not supply a figure, so the SDK derives it from
278
+ // the route's own progress.
279
+ if (usagePercentage < 0) {
280
+ mRenderer.finishGuidance();
281
+ } else {
282
+ mRenderer.finishGuidance(usagePercentage);
283
+ }
284
+ promise.resolve(null);
285
+ } else {
286
+ rejectPromise(promise);
287
+ }
288
+ }
289
+
217
290
  @ReactMethod
218
291
  public void setRoute(String routeString, String icons, int legIndex, final Promise promise) {
219
292
  if (mRenderer != null) {
220
293
  Context ctx = mCtx.getApplicationContext();
221
- MPRoute route = new Gson().fromJson(routeString, MPRoute.class);
294
+ MPRoute route = gson.fromJson(routeString, MPRoute.class);
222
295
  if (icons != null) {
223
296
  new Handler().post(()-> {
224
- HashMap<Integer, String> iconsMap = gson.fromJson(icons, new TypeToken<HashMap<Integer, String>>(){}.getType());
225
- HashMap<Integer, MPRouteStopIconProvider> iconConfigs = new HashMap<>();
226
- for (Map.Entry<Integer, String> mapEntry : iconsMap.entrySet()) {
227
- String icon = mapEntry.getValue();
228
- if (icon == null) {
229
- iconConfigs.put(mapEntry.getKey(), null);
230
- } else if (isUrl(icon)) {
231
- FutureTarget<Bitmap> futureTarget = Glide.with(ctx).asBitmap().load(icon).submit();
232
- try {
233
- BitmapStopIconConfig iconConfig = new BitmapStopIconConfig(futureTarget.get());
234
- iconConfigs.put(mapEntry.getKey(), iconConfig);
235
- } catch (Exception e) {
236
- promise.reject("something went wrong loading the image for " + icon, e);
237
- return;
297
+ // Posted to the main looper, so this body is off React Native's stack: a throw
298
+ // here takes the host app down instead of rejecting this call (MS-3983). Error
299
+ // handling matches the guards in MapsIndoorsModule.
300
+ try {
301
+ HashMap<Integer, String> iconsMap = gson.fromJson(icons, new TypeToken<HashMap<Integer, String>>(){}.getType());
302
+ HashMap<Integer, MPRouteStopIconProvider> iconConfigs = new HashMap<>();
303
+ for (Map.Entry<Integer, String> mapEntry : iconsMap.entrySet()) {
304
+ String icon = mapEntry.getValue();
305
+ if (icon == null) {
306
+ iconConfigs.put(mapEntry.getKey(), null);
307
+ } else if (isUrl(icon)) {
308
+ FutureTarget<Bitmap> futureTarget = Glide.with(ctx).asBitmap().load(icon).submit();
309
+ try {
310
+ BitmapStopIconConfig iconConfig = new BitmapStopIconConfig(futureTarget.get());
311
+ iconConfigs.put(mapEntry.getKey(), iconConfig);
312
+ } catch (Exception e) {
313
+ promise.reject("something went wrong loading the image for " + icon, e);
314
+ return;
315
+ }
316
+ }else {
317
+ String json = icon.substring(0, icon.length() - 1);
318
+ RouteStopIconConfigModel iconConfig = gson.fromJson(json, RouteStopIconConfigModel.class);
319
+ iconConfigs.put(mapEntry.getKey(), iconConfig.toMPRouteStopIconConfig(ctx));
238
320
  }
239
- }else {
240
- String json = icon.substring(0, icon.length() - 1);
241
- RouteStopIconConfigModel iconConfig = gson.fromJson(json, RouteStopIconConfigModel.class);
242
- iconConfigs.put(mapEntry.getKey(), iconConfig.toMPRouteStopIconConfig(ctx));
243
321
  }
244
- }
245
322
 
246
- mRenderer.setRoute(route, iconConfigs);
247
- if (legIndex != 0) {
248
- try {
249
- mRenderer.selectLegIndex(legIndex);
250
- } catch (IllegalStateException e) {
251
- promise.reject(e.getMessage(), new Gson().toJson(MPError.fromMIError(new MIError(MIErrorEnum.ROUTING_UNKNOWN_ERROR, e.getMessage()))));
252
- return;
253
- }
254
- }
323
+ mRenderer.setRoute(route, iconConfigs);
324
+ if (legIndex != 0) {
325
+ try {
326
+ mRenderer.selectLegIndex(legIndex);
327
+ } catch (IllegalStateException e) {
328
+ promise.reject(e.getMessage(), gson.toJson(MPError.fromMIError(new MIError(MIErrorEnum.ROUTING_UNKNOWN_ERROR, e.getMessage()))));
329
+ return;
330
+ }
331
+ }
255
332
 
256
- promise.resolve(null);
333
+ promise.resolve(null);
334
+ } catch (Exception | StackOverflowError t) {
335
+ RnGson.rejectSerialisationFailure(promise, "DirectionsRendererError",
336
+ "Could not set the route: " + t);
337
+ }
257
338
  });
258
339
  }else {
259
340
  mRenderer.setRoute(route);
@@ -271,24 +352,32 @@ public class DirectionsRendererModule extends ReactContextBaseJavaModule impleme
271
352
  if (iconString != null) {
272
353
  //Handle icon
273
354
  new Handler().post(()-> {
274
- Context ctx = mCtx.getApplicationContext();
275
- if (iconString == null || iconString.equals("null") || iconString.isEmpty()) {
276
- mRenderer.setDefaultRouteStopIconConfig(null);
277
- promise.resolve(null);
278
- } else if (isUrl(iconString)) {
279
- FutureTarget<Bitmap> futureTarget = Glide.with(ctx).asBitmap().load(iconString).submit();
280
- try {
281
- BitmapStopIconConfig iconConfig = new BitmapStopIconConfig(futureTarget.get());
282
- mRenderer.setDefaultRouteStopIconConfig(iconConfig);
355
+ // Posted to the main looper, so this body is off React Native's stack: a throw
356
+ // here takes the host app down instead of rejecting this call (MS-3983). Error
357
+ // handling matches the guards in MapsIndoorsModule.
358
+ try {
359
+ Context ctx = mCtx.getApplicationContext();
360
+ if (iconString == null || iconString.equals("null") || iconString.isEmpty()) {
361
+ mRenderer.setDefaultRouteStopIconConfig(null);
362
+ promise.resolve(null);
363
+ } else if (isUrl(iconString)) {
364
+ FutureTarget<Bitmap> futureTarget = Glide.with(ctx).asBitmap().load(iconString).submit();
365
+ try {
366
+ BitmapStopIconConfig iconConfig = new BitmapStopIconConfig(futureTarget.get());
367
+ mRenderer.setDefaultRouteStopIconConfig(iconConfig);
368
+ promise.resolve(null);
369
+ } catch (Exception e) {
370
+ promise.reject("something went wrong loading the image", e);
371
+ }
372
+ } else {
373
+ String json = iconString.substring(0, iconString.length() - 1);
374
+ RouteStopIconConfigModel iconConfig = gson.fromJson(json, RouteStopIconConfigModel.class);
375
+ mRenderer.setDefaultRouteStopIconConfig(iconConfig.toMPRouteStopIconConfig(ctx));
283
376
  promise.resolve(null);
284
- } catch (Exception e) {
285
- promise.reject("something went wrong loading the image", e);
286
- }
287
- } else {
288
- String json = iconString.substring(0, iconString.length() - 1);
289
- RouteStopIconConfigModel iconConfig = gson.fromJson(json, RouteStopIconConfigModel.class);
290
- mRenderer.setDefaultRouteStopIconConfig(iconConfig.toMPRouteStopIconConfig(ctx));
291
- promise.resolve(null);
377
+ }
378
+ } catch (Exception | StackOverflowError t) {
379
+ RnGson.rejectSerialisationFailure(promise, "DirectionsRendererError",
380
+ "Could not set the default route stop icon: " + t);
292
381
  }
293
382
  });
294
383
  }else {
@@ -305,6 +394,8 @@ public class DirectionsRendererModule extends ReactContextBaseJavaModule impleme
305
394
  if (mapControl != null) {
306
395
  mMapControl = mapControl;
307
396
  mRenderer = new MPDirectionsRenderer(mMapControl);
397
+ mSolutionConfig = null;
398
+ mSolutionConfigCaptured = false;
308
399
  }
309
400
  }
310
401
 
@@ -28,7 +28,7 @@ public class DirectionsServiceModule extends ReactContextBaseJavaModule {
28
28
  private HashMap<String, MPDirectionsService> serviceMap = new HashMap<>();
29
29
  private static final String NO_DS = "This DirectionsService is not available";
30
30
 
31
- private final Gson gson = new Gson();
31
+ private final Gson gson = RnGson.create();
32
32
  public DirectionsServiceModule(@NonNull ReactApplicationContext reactContext) {
33
33
  super(reactContext);
34
34
  }
@@ -101,12 +101,21 @@ public class DirectionsServiceModule extends ReactContextBaseJavaModule {
101
101
  MPDirectionsService service = serviceMap.get(id);
102
102
  if (service != null) {
103
103
  service.setRouteResultListener((route, error) -> {
104
- WritableMap map = Arguments.createMap();
105
- if (route != null) {
106
- map.putString("route", gson.toJson(route));
107
- }
108
- if (error != null) {
109
- map.putString("error", gson.toJson(error));
104
+ // Delivered on the SDK's thread, outside React Native's try/catch, so an unhandled
105
+ // throw takes the host app down instead of failing this call (MS-3983). MIError
106
+ // carries an untyped tag, so the error branch is as exposed as the route branch.
107
+ final WritableMap map = Arguments.createMap();
108
+ try {
109
+ if (route != null) {
110
+ map.putString("route", gson.toJson(route));
111
+ }
112
+ if (error != null) {
113
+ map.putString("error", gson.toJson(error));
114
+ }
115
+ } catch (Exception | StackOverflowError t) {
116
+ RnGson.rejectSerialisationFailure(promise, "DirectionsServiceError",
117
+ "Could not serialise the route result: " + t);
118
+ return;
110
119
  }
111
120
  promise.resolve(map);
112
121
  });
@@ -25,7 +25,7 @@ import com.mapsindoorsrn.core.models.MPError;
25
25
  public class MPDisplayRuleModule extends ReactContextBaseJavaModule {
26
26
  public static final String NAME = "DisplayRule";
27
27
 
28
- private final Gson gson = new Gson();
28
+ private final Gson gson = RnGson.create();
29
29
 
30
30
  public MPDisplayRuleModule(@NonNull ReactApplicationContext reactContext) {
31
31
  super(reactContext);