@mapsindoors/react-native-maps-indoors-mapbox 2.8.1-rc.1 → 2.9.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 (45) hide show
  1. package/README.md +118 -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 +352 -210
  17. package/ios/core/DirectionsRendererOptions.swift +352 -0
  18. package/ios/core/MapControlModule.swift +326 -244
  19. package/ios/core/MapsIndoorsBridge.m +14 -1
  20. package/ios/core/MapsIndoorsData.swift +1 -0
  21. package/ios/core/MapsIndoorsModule.swift +195 -33
  22. package/ios/core/Sources/MainThread/CallGeneration.swift +38 -0
  23. package/ios/core/Sources/MainThread/MainThread.swift +25 -0
  24. package/ios/core/UtilsModule.swift +57 -45
  25. package/package.json +5 -1
  26. package/react-native-maps-indoors-mapbox.podspec +6 -2
  27. package/specs/NativeDirectionsRendererModule.ts +3 -0
  28. package/specs/NativeMapsIndoorsModule.ts +6 -1
  29. package/src/core/EventNames.ts +3 -0
  30. package/src/core/MPCameraPosition.ts +1 -1
  31. package/src/core/MPDirectionsRenderer.ts +88 -3
  32. package/src/core/MPDirectionsRendererOptions.ts +287 -0
  33. package/src/core/MPError.ts +48 -1
  34. package/src/core/MPLanguageTag.ts +222 -0
  35. package/src/core/MPLegBoundaryIcons.ts +130 -0
  36. package/src/core/MPRouteAnimationType.ts +24 -0
  37. package/src/core/MPRouteArrowStyle.ts +28 -0
  38. package/src/core/MPRouteMarkerDisplayRule.ts +140 -0
  39. package/src/core/MPRouteStampType.ts +24 -0
  40. package/src/core/MPRouteStopIconConfig.ts +5 -3
  41. package/src/core/MPSolution.ts +33 -2
  42. package/src/core/MPStrokeStyle.ts +22 -0
  43. package/src/core/MapsIndoors.ts +155 -11
  44. package/src/core/OnBaseMapCacheProgressListener.ts +20 -0
  45. package/src/core/RouteStopIconConfig.ts +5 -1
package/README.md CHANGED
@@ -2,10 +2,127 @@
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.1/index.html) to get an overview of what the MapsIndoors SDK offers.
6
6
 
7
7
  ## Changelog
8
8
 
9
+ ### [2.9.1] - 2026-10-15
10
+
11
+ #### Changed
12
+
13
+ - `MPRouteStopIconConfig.getImage()` returns a string instead of a `URL`, and a custom
14
+ `RouteStopIconConfig.getImage()` may return either
15
+ - Updated the MapsIndoors Android and iOS SDKs to 4.23.0
16
+ - On iOS, camera moves the SDK makes for you (`goTo`, selecting with `moveCamera`, filter, highlight
17
+ and route fits) are instant when the system's Reduce Motion setting is on
18
+ - On Android, with a custom floor selector that turns automatic floor changes off, `goTo`,
19
+ `selectLocation`, `setFilter` and `setHighlight` keep the current floor
20
+ - On iOS, `MapControl` and `MPDirectionsRenderer` promises settle once the map has applied the call,
21
+ not before
22
+ - On iOS, the `MapControl.getCurrent*` getters and `isFloorSelectorHidden` resolve `null` when there
23
+ is no map control, instead of crashing
24
+ - On iOS, `MPDirectionsRenderer.setRoute` and `setDefaultRouteStopIcon` reject when a URL icon fails
25
+ to download, instead of never settling
26
+
27
+ #### Fixed
28
+
29
+ - `MPDirectionsRenderer.setDefaultRouteStopIcon` and `setRoute` rejected an `MPRouteStopIconConfig`
30
+ stop icon with "Invalid URL" on React Native versions with a standards-compliant `URL`, such as
31
+ Expo 55, so the icon never reached the map. Labels containing `?` or `#` now work too
32
+ - Setting `MapControl.showUserPosition` no longer crashes the app on iOS. The iOS SDK now accepts
33
+ the call from React Native's module thread, where 4.20.0 required the main thread
34
+ - `MapControl` and `MPDirectionsRenderer` calls no longer crash the app on iOS. They now reach the map
35
+ on the main thread, in the order they were made
36
+ - `MPDirectionsRenderer.setRoute` and `setDefaultRouteStopIcon` with URL icons no longer overwrite a
37
+ later `setRoute`, `clear` or `setDefaultRouteStopIcon` when their download finishes last
38
+ - The published package no longer contains the core unit tests (`src/core/__tests__`)
39
+ - `MPCameraPosition.create` no longer swaps tilt and bearing, so reading the camera with
40
+ `getCurrentCameraPosition` and passing the result back to `animateCamera` keeps the map's pitch
41
+ and rotation
42
+
43
+ ### [2.9.0] - 2026-09-18
44
+
45
+ #### Added
46
+
47
+ ##### Offline base map tiles support [Mapbox]
48
+
49
+ - Offline Mapbox base-map tiles. `MapsIndoors.setBaseMapTilesEnabled(enabled, apiKey)` marks a
50
+ solution for base-map caching, and `MapsIndoors.synchronizeBaseMapTiles(onProgress?, apiKeys?)`
51
+ downloads the tiles - the outdoor map underneath MapsIndoors, which `cacheData` does not cover.
52
+ Both are needed for a map that renders with no network connection. Progress is reported through
53
+ the optional `onProgress` listener, since the download can take minutes.
54
+ `MapsIndoors.isBaseMapCachingSupported()` reports whether the map provider can cache at all
55
+
56
+ ##### Improved DirectionsRenderer
57
+
58
+ - `MPDirectionsRenderer.setOptions(options)` and `getOptions()`, which style a rendered route from a
59
+ single `MPDirectionsRendererOptions` object - line color, opacity, weight and `MPStrokeStyle`, the
60
+ background halo, the animated overlay and its `MPRouteAnimationType`, a repeating
61
+ `MPRouteStampType` stamp with its `MPRouteArrowStyle`, `MPRouteMarkerDisplayRule` styling for the
62
+ route's start and end markers, per connector `MPLegBoundaryIcons`, 3D elevation (Mapbox only) and
63
+ the camera's fit-bounds max zoom. Each option resolves on its own - the value set here, then the
64
+ solution level default from the CMS, then the SDK's built-in default - so options left out are
65
+ inherited rather than reset. This supersedes `setPolylineColors` and `setAnimatedPolyline`, which
66
+ are now deprecated
67
+ - `MPDirectionsRenderer.finishGuidance(usagePercentage?)`, which signals that guidance on the
68
+ current route has finished, optionally supplying how much of the route was travelled
69
+
70
+ ##### Enhanced Language support
71
+
72
+ - `resolveLanguageTag(tag, availableLanguages)` and `normalizeLanguageTag(tag)`, for turning a
73
+ device locale into the exact language tag a solution publishes before calling
74
+ `MapsIndoors.setLanguage`. `resolveLanguageTag('zh-Hant-TW', solution.availableLanguages)`
75
+ returns `'zh-Hant'`
76
+ - `MPSolution.resolveLanguage(language)`, the same lookup against that solution's own languages
77
+ #### Changed
78
+
79
+ - Updated the MapsIndoors Android SDK to 4.22.0 and the iOS SDK to 4.20.0, the releases that carry
80
+ the base-map tile cache
81
+ - `MPSolution.hasLanguage` now matches language tags the way the native SDKs do, instead of
82
+ requiring an exact string. Casing is ignored, the ICU underscore form is accepted (`zh_Hans`),
83
+ legacy region-only Chinese tags resolve to their script (`zh-CN` matches `zh-Hans`, `zh-TW`
84
+ matches `zh-Hant`), and a more specific tag falls back to a less specific one (`en-US` matches
85
+ `en`). It stays deliberately strict about ambiguity: bare `zh` does not match a solution that
86
+ publishes only `zh-Hans` and `zh-Hant`, because there is no way to tell which script is wanted
87
+ - `MapsIndoors.setLanguage` documents what its returned boolean means on each platform. On Android
88
+ it is `false` for a language the solution does not have, and also while the SDK is still loading
89
+ or synchronizing - in which case the change is queued rather than lost. On iOS it reports only
90
+ that the tag was accepted, with no check against the solution. Read the language back with
91
+ `getLanguage` to confirm a change took effect
92
+ - `MapsIndoors.setLanguage` resolves `false` for an empty language tag without calling into the
93
+ native SDK, matching Android's own precondition. iOS would otherwise accept it and store an
94
+ empty language
95
+
96
+ #### Fixed
97
+
98
+ - The iOS geometry helpers never decoded the polygon they were given, because
99
+ `JSONDecoder` is not polymorphic and the SDK's internal `mp_polygon` accessors are nil on a
100
+ freshly decoded value. `MPPolygon.contains` therefore always answered `false`, `getArea` always
101
+ `0`, and `distanceToClosestEdge` resolved `undefined` despite being typed `Promise<number>`. The
102
+ concrete geometry type is now decoded from the GeoJSON `type` discriminator, as on Android, so
103
+ multi-polygon geometry works by construction
104
+ - Serialising SDK models to the bridge on Android walked native memory by reflection. `MPLocation`
105
+ holds an `MPIcon` whose layer holds an `android.graphics.Bitmap`, and the buffer behind a Bitmap
106
+ carries a `Cleaner` that is linked to every other live Cleaner in the process - so the work grew
107
+ with whatever the host app had allocated, not with the map data. This only showed up on physical
108
+ devices with a real app around them
109
+ - `MapsIndoors.setLanguage` always resolved `null` on iOS, despite being typed `Promise<boolean>`.
110
+ It now resolves the native SDK's real result, as it already did on Android
111
+ - `MapsIndoors.getAvailableLanguages` and `getDefaultLanguage` rejected with an unparseable error
112
+ on iOS when called before the solution had loaded, so the `MPError` never reached the caller.
113
+ Both now reject with an `MPError`, as they already did on Android
114
+ - `MapsIndoors.getDefaultLanguage` resolved `null` on Android when no solution was loaded, despite
115
+ being typed `Promise<string>`. It now rejects with an `MPError`, matching iOS
116
+ - `MapsIndoors.getSolution` resolved `null` on Android whenever no solution was loaded - including
117
+ the moment right after a language change, which reloads the solution. Callers either crashed in
118
+ `JSON.parse` or got a solution whose `availableLanguages` was `undefined`, so `hasLanguage`
119
+ answered `false` for every tag. It now rejects with an `MPError`, matching iOS
120
+ - `MapsIndoors.getLocations` discarded a native rejection instead of propagating it, then failed
121
+ in `JSON.parse` with "Unexpected character: u". The real error now reaches the caller
122
+ - `MPError.parse` threw a `SyntaxError` when a rejection did not carry the native SDK's JSON
123
+ payload - a bridge-level or JavaScript error - replacing the real message with "JSON Parse
124
+ error: Unexpected character". It now wraps such a message as an unknown error and keeps the text
125
+
9
126
  ### [2.8.0] - 2026-08-17
10
127
 
11
128
  #### 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.23.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);