@mapsindoors/react-native-maps-indoors-mapbox 2.9.1 → 2.11.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 (37) hide show
  1. package/Package.swift +87 -0
  2. package/README.md +82 -21
  3. package/android/build.gradle +2 -14
  4. package/android/src/main/java/com/mapsindoorsrn/MapboxMapView.java +4 -0
  5. package/android/src/main/java/com/mapsindoorsrn/MapsIndoorsPackage.java +10 -1
  6. package/android/src/main/java/com/mapsindoorsrn/MapsIndoorsViewManager.java +28 -2
  7. package/android/src/main/java/com/mapsindoorsrn/core/DirectionsRendererModule.java +10 -2
  8. package/android/src/main/java/com/mapsindoorsrn/core/DirectionsServiceModule.java +1 -0
  9. package/android/src/main/java/com/mapsindoorsrn/core/MPDisplayRuleModule.java +24 -0
  10. package/android/src/main/java/com/mapsindoorsrn/core/MapControlModule.java +335 -99
  11. package/android/src/main/java/com/mapsindoorsrn/core/MapsIndoorsModule.java +17 -1
  12. package/android/src/main/java/com/mapsindoorsrn/core/RouteStore.java +59 -0
  13. package/app.plugin.js +8 -86
  14. package/ios/core/DirectionsRendererBridge.m +1 -0
  15. package/ios/core/DirectionsRendererModule.swift +6 -3
  16. package/ios/core/DirectionsServiceModule.swift +7 -1
  17. package/ios/core/MPDisplayRuleBridge.m +9 -0
  18. package/ios/core/MPDisplayRuleModule.swift +18 -0
  19. package/ios/core/MapControlModule.swift +8 -4
  20. package/ios/core/MapsIndoorsBridge.m +1 -0
  21. package/ios/core/MapsIndoorsModule.swift +45 -2
  22. package/ios/core/ReactPositionProvider.swift +6 -7
  23. package/ios/core/Sources/RouteStore/RouteStore.swift +62 -0
  24. package/ios/spm-bridges/include/MapsIndoorsBridges.h +1 -0
  25. package/package.json +11 -3
  26. package/react-native-maps-indoors-mapbox.podspec +8 -11
  27. package/specs/NativeDirectionsRendererModule.ts +1 -1
  28. package/specs/NativeMPDisplayRuleModule.ts +2 -0
  29. package/specs/NativeMapsIndoorsModule.ts +1 -1
  30. package/src/core/MPBuilding.ts +2 -1
  31. package/src/core/MPDirectionsRenderer.ts +7 -1
  32. package/src/core/MPDirectionsService.ts +4 -1
  33. package/src/core/MPDisplayRule.ts +25 -0
  34. package/src/core/MPFloor.ts +25 -0
  35. package/src/core/MPSolutionConfig.ts +42 -0
  36. package/src/core/MapsIndoors.ts +39 -7
  37. package/src/core/RouteHandles.ts +76 -0
@@ -25,6 +25,7 @@ import com.mapsindoors.core.MPDataSetManagerStatus;
25
25
  import com.mapsindoors.core.MPDisplayRule;
26
26
  import com.mapsindoors.core.MPFilter;
27
27
  import com.mapsindoors.core.MPLocation;
28
+ import com.mapsindoors.core.MPLogger;
28
29
  import com.mapsindoors.core.MPPoint;
29
30
  import com.mapsindoors.core.MPQuery;
30
31
  import com.mapsindoors.core.MPSolution;
@@ -98,9 +99,23 @@ public class MapsIndoorsModule extends ReactContextBaseJavaModule {
98
99
  promise.reject("MapsIndoorsError", errorString);
99
100
  }
100
101
 
102
+ /**
103
+ * Names this wrapper as the component behind the MapsIndoors Insights session, so React Native
104
+ * apps are told apart from native ones in the rollups.
105
+ *
106
+ * The SDK snapshots the component into the session when the session starts, inside
107
+ * {@code MapsIndoors.load}, so this has to run on the same call, right before it. The version
108
+ * comes from JS, which reads it from the map package's own package.json.
109
+ */
110
+ private void setReactNativeComponent(@Nullable String sdkVersion) {
111
+ MPLogger.setCustomComponent("React Native/android SDK", sdkVersion != null ? sdkVersion : "unknown");
112
+ }
113
+
101
114
  @ReactMethod
102
- public void loadMapsIndoors(String apiKey, ReadableArray optionalStrings, Promise promise) {
115
+ public void loadMapsIndoors(String apiKey, ReadableArray optionalStrings, @Nullable String sdkVersion, Promise promise) {
103
116
  try {
117
+ setReactNativeComponent(sdkVersion);
118
+ RouteStore.clear();
104
119
  if (optionalStrings != null) {
105
120
  List<String> venueList = new ArrayList<>();
106
121
  for (int i = 0; i < optionalStrings.size(); i++) {
@@ -352,6 +367,7 @@ public class MapsIndoorsModule extends ReactContextBaseJavaModule {
352
367
 
353
368
  @ReactMethod
354
369
  public void destroy(final Promise promise) {
370
+ RouteStore.clear();
355
371
  MapsIndoors.destroy();
356
372
  promise.resolve(null);
357
373
  }
@@ -0,0 +1,59 @@
1
+ package com.mapsindoorsrn.core;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ import com.mapsindoors.core.MPRoute;
7
+
8
+ import java.util.LinkedHashMap;
9
+ import java.util.Map;
10
+ import java.util.UUID;
11
+
12
+ /**
13
+ * Keeps the routes {@link DirectionsServiceModule#getRoute} returned, so
14
+ * {@link DirectionsRendererModule#setRoute} can render the very instance instead of parsing the copy
15
+ * that comes back from JavaScript (SPEX-2782).
16
+ *
17
+ * Only that instance carries the endpoints the SDK reports with the directions Insights events, and
18
+ * the SDK keeps them out of Gson, so a parsed copy reports none.
19
+ *
20
+ * Shared by the two modules, since neither can reach the other's instance. Holds at most
21
+ * {@link #CAPACITY} routes and forgets the least recently used, since JavaScript never says when it is
22
+ * done with one. A forgotten route still renders, from its JSON, just without endpoints. Rendering
23
+ * a kept route again is safe: the SDK resolves its endpoints once and reads them on every event.
24
+ */
25
+ final class RouteStore {
26
+ static final int CAPACITY = 10;
27
+
28
+ // Access order, so a lookup counts as use and a route the app keeps setting stays.
29
+ private static final Map<String, MPRoute> sRoutes = new LinkedHashMap<String, MPRoute>(CAPACITY + 1, 1f, true) {
30
+ @Override
31
+ protected boolean removeEldestEntry(Map.Entry<String, MPRoute> eldest) {
32
+ return size() > CAPACITY;
33
+ }
34
+ };
35
+
36
+ private RouteStore() {}
37
+
38
+ /** Keeps {@code route} and returns the key to look it up by. */
39
+ @NonNull
40
+ static synchronized String keep(@NonNull MPRoute route) {
41
+ String key = UUID.randomUUID().toString();
42
+ sRoutes.put(key, route);
43
+ return key;
44
+ }
45
+
46
+ /** The route kept under {@code key}, if it is still kept. */
47
+ @Nullable
48
+ static synchronized MPRoute get(@Nullable String key) {
49
+ return key == null ? null : sRoutes.get(key);
50
+ }
51
+
52
+ /**
53
+ * Forgets every route, when MapsIndoors loads or is destroyed: a route belongs to the solution
54
+ * that was loaded when it was requested.
55
+ */
56
+ static synchronized void clear() {
57
+ sRoutes.clear();
58
+ }
59
+ }
package/app.plugin.js CHANGED
@@ -1,6 +1,5 @@
1
1
  const {
2
2
  withProjectBuildGradle,
3
- withGradleProperties,
4
3
  withPlugins,
5
4
  withDangerousMod,
6
5
  withInfoPlist,
@@ -46,24 +45,6 @@ const {
46
45
  ]);
47
46
  };
48
47
 
49
- /**
50
- * Plugin to add mapbox private token to gradle properties
51
- * @param {*} config expo project config
52
- * @param {*} token private token to set
53
- * @returns modified config
54
- */
55
- const withGradleProps = (token) => (config) => {
56
- return withGradleProperties(config, (modConf) => {
57
- modConf.modResults.push({
58
- type: "property",
59
- key: "MAPBOX_DOWNLOADS_TOKEN",
60
- value: token,
61
- });
62
-
63
- return modConf;
64
- });
65
- };
66
-
67
48
  /**
68
49
  * Plugin to add mapsindoors maven repository
69
50
  * @param {*} config expo project config
@@ -76,19 +57,7 @@ const {
76
57
 
77
58
  `maven { url 'https://www.jitpack.io' }
78
59
  maven { url 'https://maven.mapsindoors.com/' }
79
- maven {
80
- url 'https://api.mapbox.com/downloads/v2/releases/maven'
81
- authentication {
82
- basic(BasicAuthentication)
83
- }
84
- credentials {
85
- // Do not change the username below.
86
- // This should always be 'mapbox' (not your username).
87
- username = "mapbox"
88
- // Use the secret token you stored in gradle.properties as the password
89
- password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
90
- }
91
- }`
60
+ maven { url 'https://api.mapbox.com/downloads/v2/releases/maven' }`
92
61
  );
93
62
 
94
63
  modConf.modResults.contents = content;
@@ -109,57 +78,6 @@ const {
109
78
  });
110
79
  };
111
80
 
112
- /**
113
- * Plugin to add mapsindoors user system setup
114
- * @param {*} token private token to set
115
- * @param {*} config expo project config
116
- */
117
- const withiOSSecret = (token) => (config) => {
118
- return withDangerousMod(config, [
119
- "ios",
120
- async (modConf) => {
121
- const home = path.resolve(process.env.HOME);
122
- const netrc = path.resolve(home, ".netrc");
123
-
124
- // conf to add
125
- const conf = `machine api.mapbox.com
126
- login mapbox
127
- password ${token}
128
- `;
129
-
130
- const exists = fs.existsSync(netrc);
131
-
132
- if (!exists) {
133
- // no previous conf, write new one
134
- fs.writeFileSync(netrc, conf, { flag: "w" });
135
- fs.chmodSync(netrc, 0o600);
136
- } else {
137
- // get content
138
- let content = fs.readFileSync(netrc, "utf-8");
139
- const lines = content.split("\n");
140
-
141
- // check if mapbox conf exist
142
- const found = lines.findIndex((line) =>
143
- line.includes("machine api.mapbox.com")
144
- );
145
-
146
- if (found >= 0) {
147
- // remove previous mapbox conf
148
- content = lines
149
- .filter((_, idx) => ![found, found + 1, found + 2].includes(idx))
150
- .join("\n");
151
- fs.writeFileSync(netrc, content, { flag: "w" });
152
- }
153
-
154
- // write new conf
155
- fs.writeFileSync(netrc, conf, { flag: "a+" });
156
- }
157
-
158
- return modConf;
159
- },
160
- ]);
161
- };
162
-
163
81
  /**
164
82
  * Plugin to add podfile script
165
83
  * @param {*} config expo project config
@@ -255,7 +173,7 @@ const {
255
173
  /**
256
174
  * Combine Expo configuration and properties
257
175
  * @param {*} config expo project config
258
- * @param {*} {downloadToken} Mapbox download token
176
+ * @param {*} {downloadToken} deprecated and ignored: Mapbox SDK downloads need no token
259
177
  * @param {*} {publicToken} Mapbox public token
260
178
  * @returns modified config
261
179
  */
@@ -263,12 +181,16 @@ const {
263
181
  config,
264
182
  { downloadToken, publicToken, staticPods }
265
183
  ) => {
184
+ if (downloadToken !== undefined) {
185
+ console.warn(
186
+ "@mapsindoors/react-native-maps-indoors-mapbox: `downloadToken` is deprecated and ignored. Mapbox SDK downloads need no token; remove it from your plugin config."
187
+ );
188
+ }
189
+
266
190
  const plugins = [
267
- withGradleProps(downloadToken),
268
191
  withAPIKeys(publicToken),
269
192
  withMavenRepo,
270
193
  withTokenInfoPlist(publicToken),
271
- withiOSSecret(downloadToken),
272
194
  withPodfile,
273
195
  withStaticLinkage(staticPods),
274
196
  ];
@@ -40,6 +40,7 @@
40
40
  RCT_EXTERN_METHOD(setRoute: (NSString *) routeString
41
41
  stopIcons:(NSString *) stopIcons
42
42
  legIndex: (nonnull NSNumber *) legIndex
43
+ routeId:(NSString *) routeId
43
44
  resolver:(RCTPromiseResolveBlock) resolve
44
45
  rejecter:(RCTPromiseRejectBlock) reject)
45
46
 
@@ -401,9 +401,12 @@ public class DirectionsRendererModule: RCTEventEmitter {
401
401
  }
402
402
  }
403
403
 
404
- @objc public func setRoute(_ routeString: String, stopIcons: String, legIndex: NSNumber, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
405
- // Decoded here, off the main thread: a route can be large, and none of this touches the map.
406
- guard let route = try? JSONDecoder().decode(MPRouteInternal.self, from: Data(routeString.utf8)) else {
404
+ @objc public func setRoute(_ routeString: String, stopIcons: String, legIndex: NSNumber, routeId: String?, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
405
+ // The route `getRoute` kept, when JavaScript names one: only that instance carries the endpoints
406
+ // the directions Insights events report. Otherwise decoded here, off the main thread: a route can
407
+ // be large, and none of this touches the map.
408
+ guard let route = routeId.flatMap(keptRoutes.route(for:))
409
+ ?? (try? JSONDecoder().decode(MPRouteInternal.self, from: Data(routeString.utf8))) else {
407
410
  return doReject(reject, message: "Route could not be parsed")
408
411
  }
409
412
 
@@ -9,6 +9,10 @@ import MapsIndoors
9
9
  import MapsIndoorsCodable
10
10
  import MapsIndoorsCore
11
11
 
12
+ /// The routes ``DirectionsServiceModule/getRoute`` returned, for ``DirectionsRendererModule/setRoute`` to
13
+ /// render as they are. Shared by the two modules, since neither can reach the other's instance.
14
+ let keptRoutes = RouteStore<MPRouteInternal>(capacity: 10)
15
+
12
16
  @objc(DirectionsService)
13
17
  public class DirectionsServiceModule: NSObject {
14
18
  var directionsVariables = [String: DirectionsVariables]()
@@ -110,11 +114,13 @@ public class DirectionsServiceModule: NSObject {
110
114
  Task {
111
115
  do {
112
116
  if let route = try await MPMapsIndoors.shared.directionsService.routingWith(query: query) {
113
- if let routeData = try? JSONEncoder().encode(route as? MPRouteInternal) {
117
+ let internalRoute = route as? MPRouteInternal
118
+ if let routeData = try? JSONEncoder().encode(internalRoute) {
114
119
  let routeRoute = String(data: routeData, encoding: String.Encoding.utf8)
115
120
  var map = [String: String]()
116
121
  map["route"] = routeRoute
117
122
  map["error"] = "null"
123
+ map["routeId"] = internalRoute.map(keptRoutes.keep)
118
124
  return resolve(map)
119
125
  } else {
120
126
  return doReject(reject, message: "Route could not be parsed")
@@ -579,6 +579,15 @@
579
579
  resolver:(RCTPromiseResolveBlock) resolve
580
580
  rejecter:(RCTPromiseRejectBlock) reject)
581
581
 
582
+ RCT_EXTERN_METHOD(getIconZoomFactor: (NSString *) displayRuleId
583
+ resolver:(RCTPromiseResolveBlock) resolve
584
+ rejecter:(RCTPromiseRejectBlock) reject)
585
+
586
+ RCT_EXTERN_METHOD(setIconZoomFactor: (NSString *) displayRuleId
587
+ value:(nonnull NSNumber *) value
588
+ resolver:(RCTPromiseResolveBlock) resolve
589
+ rejecter:(RCTPromiseRejectBlock) reject)
590
+
582
591
  RCT_EXTERN_METHOD(getBadgeScale: (NSString *) displayRuleId
583
592
  resolver:(RCTPromiseResolveBlock) resolve
584
593
  rejecter:(RCTPromiseRejectBlock) reject)
@@ -1454,6 +1454,24 @@ public class MPDisplayRuleModule: NSObject {
1454
1454
  return resolve(nil)
1455
1455
  }
1456
1456
 
1457
+ @objc public func getIconZoomFactor(_ displayRuleId: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
1458
+ guard let displayRule = getRule(name: displayRuleId) else {
1459
+ return doReject(reject, displayRuleId: displayRuleId)
1460
+ }
1461
+
1462
+ return resolve(displayRule.iconZoomFactor)
1463
+ }
1464
+
1465
+ @objc public func setIconZoomFactor(_ displayRuleId: String, value: NSNumber, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
1466
+ guard let displayRule = getRule(name: displayRuleId) else {
1467
+ return doReject(reject, displayRuleId: displayRuleId)
1468
+ }
1469
+
1470
+ displayRule.iconZoomFactor = value.doubleValue
1471
+
1472
+ return resolve(nil)
1473
+ }
1474
+
1457
1475
  @objc public func getBadgeScale(_ displayRuleId: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
1458
1476
  guard let displayRule = getRule(name: displayRuleId) else {
1459
1477
  return doReject(reject, displayRuleId: displayRuleId)
@@ -172,7 +172,8 @@ public class MapControlModule: RCTEventEmitter {
172
172
  rejecter reject: @escaping RCTPromiseRejectBlock
173
173
  ) {
174
174
  onMainThread {
175
- resolve(MapsIndoorsData.sharedInstance.mapView?.getMapControl()?.showUserPosition)
175
+ guard let mapControl = self.requireMapControl(reject) else { return }
176
+ resolve(mapControl.showUserPosition)
176
177
  }
177
178
  }
178
179
 
@@ -449,7 +450,8 @@ public class MapControlModule: RCTEventEmitter {
449
450
  rejecter reject: @escaping RCTPromiseRejectBlock
450
451
  ) {
451
452
  onMainThread {
452
- resolve(MapsIndoorsData.sharedInstance.mapView?.getMapControl()?.currentFloorIndex)
453
+ guard let mapControl = self.requireMapControl(reject) else { return }
454
+ resolve(mapControl.currentFloorIndex)
453
455
  }
454
456
  }
455
457
 
@@ -458,7 +460,8 @@ public class MapControlModule: RCTEventEmitter {
458
460
  rejecter reject: @escaping RCTPromiseRejectBlock
459
461
  ) {
460
462
  onMainThread {
461
- resolve(MapsIndoorsData.sharedInstance.mapView?.getMapControl()?.cameraPosition.zoom)
463
+ guard let mapControl = self.requireMapControl(reject) else { return }
464
+ resolve(mapControl.cameraPosition.zoom)
462
465
  }
463
466
  }
464
467
 
@@ -479,7 +482,8 @@ public class MapControlModule: RCTEventEmitter {
479
482
  rejecter reject: @escaping RCTPromiseRejectBlock
480
483
  ) {
481
484
  onMainThread {
482
- resolve(MapsIndoorsData.sharedInstance.mapView?.getMapControl()?.hideFloorSelector)
485
+ guard let mapControl = self.requireMapControl(reject) else { return }
486
+ resolve(mapControl.hideFloorSelector)
483
487
  }
484
488
  }
485
489
 
@@ -5,6 +5,7 @@
5
5
 
6
6
  RCT_EXTERN_METHOD(loadMapsIndoors:(NSString *)apiKey
7
7
  optionalStrings:(NSArray<NSString *> _Nullable)optionalStrings
8
+ sdkVersion:(NSString * _Nullable)sdkVersion
8
9
  resolver:(RCTPromiseResolveBlock)resolve
9
10
  rejecter:(RCTPromiseRejectBlock)reject)
10
11
 
@@ -2,6 +2,9 @@ import Foundation
2
2
  import MapsIndoors
3
3
  import MapsIndoorsCodable
4
4
  import MapsIndoorsCore
5
+ #if canImport(MapsIndoorsMapbox)
6
+ import MapsIndoorsMapbox
7
+ #endif
5
8
  import React
6
9
 
7
10
  @objc(MapsIndoorsModule)
@@ -35,8 +38,22 @@ public class MapsIndoorsModule: RCTEventEmitter {
35
38
  /// Keeps the `cacheData` delegate alive while a dataset sync runs - see the note in `cacheData`.
36
39
  private var datasetDelegate: DatasetDelegate?
37
40
 
38
- @objc(loadMapsIndoors:optionalStrings:resolver:rejecter:)
39
- func loadMapsIndoors(apiKey: String, optionalStrings: [String]?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
41
+ /// Names this wrapper as the component behind the MapsIndoors Insights session, so React Native
42
+ /// apps are told apart from native ones in the rollups.
43
+ ///
44
+ /// The SDK stamps the component into the session when the session starts, inside `load`, so this
45
+ /// has to run on the same call, right before it. The version comes from JS, which reads it from
46
+ /// the map package's own package.json.
47
+ private func setReactNativeComponent(_ sdkVersion: String?) {
48
+ MPLogger.sharedInstance.component = "React Native/iOS SDK"
49
+ MPLogger.sharedInstance.componentVersion = sdkVersion ?? "unknown"
50
+ }
51
+
52
+ @objc(loadMapsIndoors:optionalStrings:sdkVersion:resolver:rejecter:)
53
+ func loadMapsIndoors(apiKey: String, optionalStrings: [String]?, sdkVersion: String?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
54
+ setReactNativeComponent(sdkVersion)
55
+ keptRoutes.removeAll()
56
+
40
57
  Task {
41
58
  do {
42
59
  if optionalStrings != nil {
@@ -211,6 +228,7 @@ public class MapsIndoorsModule: RCTEventEmitter {
211
228
 
212
229
  positionProvider = provider
213
230
  MPMapsIndoors.shared.positionProvider = positionProvider
231
+ setOnMapControl(provider)
214
232
 
215
233
  return resolve(nil)
216
234
  }
@@ -218,10 +236,25 @@ public class MapsIndoorsModule: RCTEventEmitter {
218
236
  @objc public func removePositionProvider(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
219
237
  positionProvider = nil
220
238
  MPMapsIndoors.shared.positionProvider = nil
239
+ setOnMapControl(nil)
221
240
 
222
241
  return resolve(nil)
223
242
  }
224
243
 
244
+ /// Hands the provider to this wrapper's map control directly, not only through the SDK.
245
+ ///
246
+ /// The SDK passes `MPMapsIndoors.shared.positionProvider` on only to the map controls it has
247
+ /// registered, and every `load` clears that registry. The wrapper keeps its existing map control
248
+ /// across a reload (`initMapControl` returns early), so after a second `load` the control is no
249
+ /// longer registered, the provider's delegate is never set, and the blue dot never shows
250
+ /// (MS-3929). Setting it here wires the delegate whatever the SDK's registry holds; for a
251
+ /// registered control it is the same assignment the SDK makes.
252
+ private func setOnMapControl(_ provider: MPPositionProvider?) {
253
+ onMainThread {
254
+ MapsIndoorsData.sharedInstance.mapView?.getMapControl()?.positionProvider = provider
255
+ }
256
+ }
257
+
225
258
  @objc public func onPositionUpdate(_ positionJSON: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
226
259
  do {
227
260
  let positionResult: MPPositionResult = try fromJSON(positionJSON)
@@ -290,6 +323,7 @@ public class MapsIndoorsModule: RCTEventEmitter {
290
323
  }
291
324
 
292
325
  @objc public func destroy(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
326
+ keptRoutes.removeAll()
293
327
  Task {
294
328
  MPMapsIndoors.shared.shutdown()
295
329
  MapsIndoorsData.sharedInstance.isInitialized = false
@@ -443,6 +477,15 @@ public class MapsIndoorsModule: RCTEventEmitter {
443
477
  }
444
478
 
445
479
  Task {
480
+ // The SDK otherwise registers its base-map cache only when MapControl.create builds the
481
+ // map provider, so caching before the first map rejected with 9000 (SPEX-2895). A no-op
482
+ // once a map has registered its own. The SDK declares it @MainActor, since the Mapbox
483
+ // objects it creates belong to their creating thread; the await hops there. The token
484
+ // comes from Info.plist's MBXAccessToken, which Mapbox reads by itself.
485
+ #if canImport(MapsIndoorsMapbox)
486
+ await MPMapsIndoors.registerMapboxBaseMapCache()
487
+ #endif
488
+
446
489
  do {
447
490
  if apiKeys == nil {
448
491
  try await datasetCacheManager.synchronizeBaseMapTiles(progress: progress)
@@ -5,17 +5,16 @@ public class ReactPositionProvider: MPPositionProvider {
5
5
  public var latestPosition: MapsIndoors.MPPositionResult?
6
6
 
7
7
  public var name = "default"
8
- public var delegate: MapsIndoors.MPPositionProviderDelegate?
9
- private var mapsIndoorsData: MapsIndoorsData
10
-
11
- init() {
12
- mapsIndoorsData = MapsIndoorsData.sharedInstance
13
- }
8
+ // Weak: the delegate is the map control, which holds this provider. Strong, the pair kept each
9
+ // other, and the map, alive after the map view was gone (SPEX-2885).
10
+ public weak var delegate: MapsIndoors.MPPositionProviderDelegate?
14
11
 
15
12
  public func setLatestPosition(positionResult: MPPositionResult) {
16
13
  DispatchQueue.main.async {
17
14
  if self.latestPosition?.floorIndex != positionResult.floorIndex {
18
- let floorSelector = self.mapsIndoorsData.floorSelector
15
+ // Read per call, not kept: every new map view resets `sharedInstance`, and a kept
16
+ // instance closed the cycle provider -> data -> map view -> map control -> provider.
17
+ let floorSelector = MapsIndoorsData.sharedInstance.floorSelector
19
18
  floorSelector?.onUserPositionFloorChange(floorIndex: positionResult.floorIndex)
20
19
  }
21
20
 
@@ -0,0 +1,62 @@
1
+ //
2
+ // RouteStore.swift
3
+ // react-native-maps-indoors
4
+ //
5
+
6
+ import Foundation
7
+
8
+ /// Keeps the routes the directions service module returned, so the renderer module can render the
9
+ /// very instance instead of decoding the copy that comes back from JavaScript (SPEX-2782).
10
+ ///
11
+ /// Only that instance carries the endpoints the SDK reports with the directions Insights events,
12
+ /// and neither SDK encodes them, so a decoded copy reports none.
13
+ ///
14
+ /// Holds at most `capacity` routes and forgets the least recently used, since JavaScript never says
15
+ /// when it is done with one. A forgotten route still renders, from its JSON, just without endpoints.
16
+ /// Lookups count as use, so a route the app keeps setting stays. Rendering a kept route again is
17
+ /// safe: the SDK resolves its endpoints once and reads them on every event.
18
+ final class RouteStore<Route>: @unchecked Sendable {
19
+ private let lock = NSLock()
20
+ private let capacity: Int
21
+ private var routes: [String: Route] = [:]
22
+ /// Keys in `routes`, least recently used first.
23
+ private var order: [String] = []
24
+
25
+ init(capacity: Int) {
26
+ precondition(capacity > 0, "A RouteStore must be able to hold a route")
27
+ self.capacity = capacity
28
+ }
29
+
30
+ /// Keeps `route` and returns the key to look it up by.
31
+ func keep(_ route: Route) -> String {
32
+ let key = UUID().uuidString
33
+ lock.lock()
34
+ defer { lock.unlock() }
35
+ routes[key] = route
36
+ order.append(key)
37
+ if order.count > capacity {
38
+ routes[order.removeFirst()] = nil
39
+ }
40
+ return key
41
+ }
42
+
43
+ /// The route kept under `key`, if it is still kept.
44
+ func route(for key: String) -> Route? {
45
+ lock.lock()
46
+ defer { lock.unlock() }
47
+ guard let route = routes[key], let index = order.firstIndex(of: key) else {
48
+ return nil
49
+ }
50
+ order.append(order.remove(at: index))
51
+ return route
52
+ }
53
+
54
+ /// Forgets every route, when MapsIndoors loads or is destroyed: a route belongs to the solution that
55
+ /// was loaded when it was requested.
56
+ func removeAll() {
57
+ lock.lock()
58
+ defer { lock.unlock() }
59
+ routes.removeAll()
60
+ order.removeAll()
61
+ }
62
+ }
@@ -0,0 +1 @@
1
+ // SwiftPM requires a public headers directory; the bridge targets export no headers.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mapsindoors/react-native-maps-indoors-mapbox",
3
3
  "title": "React Native MapsIndoors Mapbox",
4
- "version": "2.9.1",
4
+ "version": "2.11.0",
5
5
  "description": "React Native MapsIndoors component with mapbox",
6
6
  "react-native": "index.ts",
7
7
  "files": [
@@ -17,10 +17,12 @@
17
17
  "!ios/core/Tests",
18
18
  "!ios/core/.build",
19
19
  "!android/build",
20
- "app.plugin.js"
20
+ "app.plugin.js",
21
+ "Package.swift"
21
22
  ],
22
23
  "scripts": {
23
- "test": "echo \"Error: no test specified\" && exit 1"
24
+ "test": "jest",
25
+ "test:watch": "jest --watch"
24
26
  },
25
27
  "repository": {
26
28
  "type": "git",
@@ -44,7 +46,10 @@
44
46
  "react-native": ">=0.75.0 <1.0.x"
45
47
  },
46
48
  "devDependencies": {
49
+ "@types/jest": "^29.5.14",
47
50
  "@types/react": "^19.0.0",
51
+ "jest": "^29.7.0",
52
+ "ts-jest": "^29.4.12",
48
53
  "typedoc": "^0.24.8",
49
54
  "typescript": "^5.0.4"
50
55
  },
@@ -58,5 +63,8 @@
58
63
  "android": {
59
64
  "javaPackageName": "com.mapsindoorsrn"
60
65
  }
66
+ },
67
+ "swiftpmConfig": {
68
+ "name": "ReactNativeMapsIndoorsMapbox"
61
69
  }
62
70
  }
@@ -24,19 +24,16 @@ Pod::Spec.new do |s|
24
24
  # ios/core carries a SwiftPM manifest and unit tests for its React-free helpers (SPEX-2686). They
25
25
  # are run with `swift test` in that repository and must not be compiled into the pod, nor must the
26
26
  # build products `swift test` leaves in .build (they include a generated `@main` test runner).
27
- s.exclude_files = "ios/core/Package.swift", "ios/core/Tests/**/*", "ios/core/.build/**/*"
27
+ s.exclude_files = "ios/core/Package.swift", "ios/core/Tests/**/*", "ios/core/.build/**/*", "ios/spm-bridges/**/*"
28
28
  s.requires_arc = true
29
29
 
30
30
  install_modules_dependencies(s)
31
31
 
32
- # MapsIndoors' iOS SDK is consumed via CocoaPods, which resolves MapsIndoorsCore and MapboxMaps
33
- # 11.x transitively and embeds them into the consuming app.
34
- #
35
- # This deliberately does *not* use the Swift Package Manager integration introduced in SPEX-889:
36
- # `spm_dependency` attaches the packages to the Pods project's own target, and nothing then
37
- # embeds the resulting dynamic frameworks into the app bundle, so the app builds and links but
38
- # dies at launch with `Library not loaded: @rpath/MapsIndoorsCore.framework/MapsIndoorsCore`.
39
- # See SPEX-2429 before reintroducing SPM here.
40
- s.dependency "MapsIndoorsMapbox11", "4.23.0"
41
- s.dependency "MapsIndoorsCodable", "4.23.0"
32
+ # CocoaPods apps get the MapsIndoors SDK as pods, which embed into the app. Do not switch to
33
+ # `spm_dependency`: it attaches the packages to the Pods project's own target, nothing embeds the
34
+ # frameworks, and the app dies at launch with `Library not loaded: @rpath/MapsIndoorsCore...`
35
+ # (SPEX-2429). Apps on React Native's SwiftPM mode (0.88+) use Package.swift instead, which must
36
+ # name the same SDK version.
37
+ s.dependency "MapsIndoorsMapbox11", "4.24.1"
38
+ s.dependency "MapsIndoorsCodable", "4.24.1"
42
39
  end
@@ -13,7 +13,7 @@ export interface Spec extends TurboModule {
13
13
  setCameraViewFitMode(cameraFitMode: number): Promise<null>;
14
14
  setCameraAnimationDuration(duration: number): Promise<null>;
15
15
  setOnLegSelectedListener(): Promise<null>;
16
- setRoute(routeString: string, stopIcons: string, legIndex: number): Promise<null>;
16
+ setRoute(routeString: string, stopIcons: string, legIndex: number, routeId: string | null): Promise<null>;
17
17
  setAnimatedPolyline(animated: boolean, repeated: boolean, duration: number): Promise<null>;
18
18
  setPolyLineColors(foregroundString: string, backgroundString: string): Promise<null>;
19
19
  setOptions(optionsString: string): Promise<null>;
@@ -33,6 +33,8 @@ export interface Spec extends TurboModule {
33
33
  setIconSize(displayRuleId: string, size: string): Promise<null>;
34
34
  getIconScale(displayRuleId: string): Promise<number | null>;
35
35
  setIconScale(displayRuleId: string, scale: number): Promise<null>;
36
+ getIconZoomFactor(displayRuleId: string): Promise<number>;
37
+ setIconZoomFactor(displayRuleId: string, factor: number): Promise<null>;
36
38
  getIconPlacement(displayRuleId: string): Promise<number | null>;
37
39
  setIconPlacement(displayRuleId: string, placement: number): Promise<null>;
38
40