@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.
- package/README.md +118 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/mapsindoorsrn/MapsIndoorsPackage.java +10 -0
- package/android/src/main/java/com/mapsindoorsrn/core/BaseMapCacheProviders.java +94 -0
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsRendererModule.java +140 -49
- package/android/src/main/java/com/mapsindoorsrn/core/DirectionsServiceModule.java +16 -7
- package/android/src/main/java/com/mapsindoorsrn/core/MPDisplayRuleModule.java +1 -1
- package/android/src/main/java/com/mapsindoorsrn/core/MapControlModule.java +115 -20
- package/android/src/main/java/com/mapsindoorsrn/core/MapsIndoorsModule.java +200 -11
- package/android/src/main/java/com/mapsindoorsrn/core/RnGson.java +110 -0
- package/android/src/main/java/com/mapsindoorsrn/core/UtilsModule.java +1 -1
- package/android/src/main/java/com/mapsindoorsrn/core/models/DirectionsRendererOptionsModel.java +498 -0
- package/index.ts +25 -0
- package/ios/.swift-format +79 -0
- package/ios/core/DirectionsRendererBridge.m +11 -0
- package/ios/core/DirectionsRendererModule.swift +352 -210
- package/ios/core/DirectionsRendererOptions.swift +352 -0
- package/ios/core/MapControlModule.swift +326 -244
- package/ios/core/MapsIndoorsBridge.m +14 -1
- package/ios/core/MapsIndoorsData.swift +1 -0
- package/ios/core/MapsIndoorsModule.swift +195 -33
- package/ios/core/Sources/MainThread/CallGeneration.swift +38 -0
- package/ios/core/Sources/MainThread/MainThread.swift +25 -0
- package/ios/core/UtilsModule.swift +57 -45
- package/package.json +5 -1
- package/react-native-maps-indoors-mapbox.podspec +6 -2
- package/specs/NativeDirectionsRendererModule.ts +3 -0
- package/specs/NativeMapsIndoorsModule.ts +6 -1
- package/src/core/EventNames.ts +3 -0
- package/src/core/MPCameraPosition.ts +1 -1
- package/src/core/MPDirectionsRenderer.ts +88 -3
- package/src/core/MPDirectionsRendererOptions.ts +287 -0
- package/src/core/MPError.ts +48 -1
- package/src/core/MPLanguageTag.ts +222 -0
- package/src/core/MPLegBoundaryIcons.ts +130 -0
- package/src/core/MPRouteAnimationType.ts +24 -0
- package/src/core/MPRouteArrowStyle.ts +28 -0
- package/src/core/MPRouteMarkerDisplayRule.ts +140 -0
- package/src/core/MPRouteStampType.ts +24 -0
- package/src/core/MPRouteStopIconConfig.ts +5 -3
- package/src/core/MPSolution.ts +33 -2
- package/src/core/MPStrokeStyle.ts +22 -0
- package/src/core/MapsIndoors.ts +155 -11
- package/src/core/OnBaseMapCacheProgressListener.ts +20 -0
- package/src/core/RouteStopIconConfig.ts +5 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#import <React/RCTBridgeModule.h>
|
|
2
|
+
#import <React/RCTEventEmitter.h>
|
|
2
3
|
|
|
3
|
-
@interface RCT_EXTERN_MODULE(MapsIndoorsModule,
|
|
4
|
+
@interface RCT_EXTERN_MODULE(MapsIndoorsModule, RCTEventEmitter)
|
|
4
5
|
|
|
5
6
|
RCT_EXTERN_METHOD(loadMapsIndoors:(NSString *)apiKey
|
|
6
7
|
optionalStrings:(NSArray<NSString *> _Nullable)optionalStrings
|
|
@@ -125,4 +126,16 @@
|
|
|
125
126
|
resolver:(RCTPromiseResolveBlock) resolve
|
|
126
127
|
rejecter:(RCTPromiseRejectBlock) reject)
|
|
127
128
|
|
|
129
|
+
RCT_EXTERN_METHOD(isBaseMapCachingSupported:(RCTPromiseResolveBlock)resolve
|
|
130
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
131
|
+
|
|
132
|
+
RCT_EXTERN_METHOD(setBaseMapTilesEnabled:(BOOL)enabled
|
|
133
|
+
apiKey:(NSString *)apiKey
|
|
134
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
135
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
136
|
+
|
|
137
|
+
RCT_EXTERN_METHOD(synchronizeBaseMapTiles:(NSArray<NSString *> _Nullable)apiKeys
|
|
138
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
139
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
140
|
+
|
|
128
141
|
@end
|
|
@@ -5,8 +5,26 @@ import MapsIndoorsCore
|
|
|
5
5
|
import React
|
|
6
6
|
|
|
7
7
|
@objc(MapsIndoorsModule)
|
|
8
|
-
public class MapsIndoorsModule:
|
|
9
|
-
@objc public static func requiresMainQueueSetup() -> Bool { return false }
|
|
8
|
+
public class MapsIndoorsModule: RCTEventEmitter {
|
|
9
|
+
@objc public override static func requiresMainQueueSetup() -> Bool { return false }
|
|
10
|
+
|
|
11
|
+
/// Base override for RCTEventEmitter.
|
|
12
|
+
///
|
|
13
|
+
/// - Returns: all supported events
|
|
14
|
+
@objc open override func supportedEvents() -> [String] {
|
|
15
|
+
return MapsIndoorsData.sharedInstance.allEvents
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// Whether JavaScript currently has a listener attached to this emitter.
|
|
19
|
+
///
|
|
20
|
+
/// Base-map cache progress is only emitted while this is true: `synchronizeBaseMapTiles` is
|
|
21
|
+
/// callable without a progress listener, and RCTEventEmitter logs a warning for every event sent
|
|
22
|
+
/// with nothing listening.
|
|
23
|
+
private var hasListeners = false
|
|
24
|
+
|
|
25
|
+
public override func startObserving() { hasListeners = true }
|
|
26
|
+
|
|
27
|
+
public override func stopObserving() { hasListeners = false }
|
|
10
28
|
|
|
11
29
|
@objc public func test() {
|
|
12
30
|
print("%@.test()", String(describing: self))
|
|
@@ -14,6 +32,9 @@ public class MapsIndoorsModule: NSObject {
|
|
|
14
32
|
|
|
15
33
|
private var positionProvider: ReactPositionProvider?
|
|
16
34
|
|
|
35
|
+
/// Keeps the `cacheData` delegate alive while a dataset sync runs - see the note in `cacheData`.
|
|
36
|
+
private var datasetDelegate: DatasetDelegate?
|
|
37
|
+
|
|
17
38
|
@objc(loadMapsIndoors:optionalStrings:resolver:rejecter:)
|
|
18
39
|
func loadMapsIndoors(apiKey: String, optionalStrings: [String]?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
19
40
|
Task {
|
|
@@ -93,7 +114,7 @@ public class MapsIndoorsModule: NSObject {
|
|
|
93
114
|
let languages = solution.availableLanguages
|
|
94
115
|
return resolve(languages)
|
|
95
116
|
} else {
|
|
96
|
-
reject
|
|
117
|
+
return doReject(reject, message: "getAvailableLanguages: solution is not available. Try loading first")
|
|
97
118
|
}
|
|
98
119
|
}
|
|
99
120
|
|
|
@@ -102,7 +123,7 @@ public class MapsIndoorsModule: NSObject {
|
|
|
102
123
|
let defaultLanguage = solution.defaultLanguage
|
|
103
124
|
return resolve(defaultLanguage)
|
|
104
125
|
} else {
|
|
105
|
-
reject
|
|
126
|
+
return doReject(reject, message: "getDefaultLanguage: solution is not available. Try loading first")
|
|
106
127
|
}
|
|
107
128
|
}
|
|
108
129
|
|
|
@@ -127,26 +148,29 @@ public class MapsIndoorsModule: NSObject {
|
|
|
127
148
|
return resolve(toJSON(locations))
|
|
128
149
|
}
|
|
129
150
|
|
|
130
|
-
@objc public func getMapStyles(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
151
|
+
@objc public func getMapStyles(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
152
|
+
// `currentVenue` is read from the map control, which has to happen on the main thread.
|
|
153
|
+
onMainThread {
|
|
154
|
+
guard let mapControl = MapsIndoorsData.sharedInstance.mapView?.getMapControl() else {
|
|
155
|
+
return doReject(reject, message: "getMapStyles: Must create MapControl first")
|
|
156
|
+
}
|
|
157
|
+
guard let venue = mapControl.currentVenue else {
|
|
158
|
+
return doReject(reject, message: "getMapStyles: No current venue")
|
|
159
|
+
}
|
|
160
|
+
guard let styles = venue.styles else {
|
|
161
|
+
return doReject(reject, message: "getMapStyles: Got no styles")
|
|
162
|
+
}
|
|
140
163
|
|
|
141
|
-
|
|
142
|
-
|
|
164
|
+
let mapStyles = styles.map({ MPMapStyleCodable(withMapStyle: $0) })
|
|
165
|
+
resolve(toJSON(mapStyles))
|
|
166
|
+
}
|
|
143
167
|
}
|
|
144
168
|
|
|
145
169
|
@objc public func getSolution(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
|
146
170
|
if let solution = MPMapsIndoors.shared.solution {
|
|
147
171
|
return resolve(toJSON(MPSolutionCodable(withSolution: solution)))
|
|
148
172
|
} else {
|
|
149
|
-
return reject
|
|
173
|
+
return doReject(reject, message: "getSolution: solution is not available. Try loading first")
|
|
150
174
|
}
|
|
151
175
|
}
|
|
152
176
|
|
|
@@ -249,7 +273,7 @@ public class MapsIndoorsModule: NSObject {
|
|
|
249
273
|
@objc public func getDefaultVenue(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
250
274
|
Task {
|
|
251
275
|
guard let defaultVenue = await MPMapsIndoors.shared.venues().first else {
|
|
252
|
-
return reject
|
|
276
|
+
return doReject(reject, message: "getDefaultVenue: no venues exist. Make sure MapsIndoors is ready")
|
|
253
277
|
}
|
|
254
278
|
return resolve(toJSON(MPVenueCodable(withVenue: defaultVenue)))
|
|
255
279
|
}
|
|
@@ -258,7 +282,7 @@ public class MapsIndoorsModule: NSObject {
|
|
|
258
282
|
@objc public func checkOfflineDataAvailability(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
259
283
|
Task {
|
|
260
284
|
guard let key = MPMapsIndoors.shared.apiKey else {
|
|
261
|
-
return reject
|
|
285
|
+
return doReject(reject, message: "checkOfflineDataAvailability: API key not set")
|
|
262
286
|
}
|
|
263
287
|
|
|
264
288
|
return resolve(await MPMapsIndoors.shared.isOfflineDataAvailable(apiKey: key))
|
|
@@ -277,9 +301,17 @@ public class MapsIndoorsModule: NSObject {
|
|
|
277
301
|
return resolve(MapsIndoorsData.sharedInstance.isInitialized)
|
|
278
302
|
}
|
|
279
303
|
|
|
304
|
+
/// Sets the SDK language and reports whether the write was accepted.
|
|
305
|
+
///
|
|
306
|
+
/// `MILanguage.setLanguage` and the `MPMapsIndoors.shared.language` setter it replaces here
|
|
307
|
+
/// reach the same storage: the setter routes through `MapsIndoorsLegacy.setLanguage` to
|
|
308
|
+
/// `MILanguage.language`, which is the same provider property `setLanguage` assigns after
|
|
309
|
+
/// normalizing the tag. Same UserDefaults write, same `MILanguage` change notification, same
|
|
310
|
+
/// `languageChanged` log event - the only new thing is the return value, which a property
|
|
311
|
+
/// setter had no way to surface. JavaScript has always declared `Promise<boolean>` here and
|
|
312
|
+
/// always received `null`.
|
|
280
313
|
@objc public func setLanguage(_ language: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
|
281
|
-
|
|
282
|
-
return resolve(nil)
|
|
314
|
+
return resolve(MILanguage.setLanguage(language))
|
|
283
315
|
}
|
|
284
316
|
|
|
285
317
|
@objc public func synchronizeContent(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
@@ -328,30 +360,160 @@ public class MapsIndoorsModule: NSObject {
|
|
|
328
360
|
if dataSet == nil {
|
|
329
361
|
dataSet = datasetCacheManager.addDataSet(apiKey, cachingScope: .full)
|
|
330
362
|
}
|
|
331
|
-
|
|
363
|
+
guard let dataSet else {
|
|
332
364
|
return resolve(false)
|
|
333
365
|
}
|
|
334
366
|
|
|
335
|
-
|
|
367
|
+
// Rejected rather than queued or run alongside. The manager's delegate is a single slot, so a
|
|
368
|
+
// second call overwrote it, deallocated the first delegate - the slot is `weak` - and stranded
|
|
369
|
+
// the first promise forever: the same silent hang this delegate exists to fix, narrowed from
|
|
370
|
+
// always to on overlap. Holding the slot until the running call settles also keeps that call's
|
|
371
|
+
// completion from nilling a later call's delegate.
|
|
372
|
+
guard datasetDelegate == nil else {
|
|
373
|
+
return doReject(reject, message: "A cacheData call is already running; wait for it to finish before starting another")
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Held by the module for the length of the sync. MPDataSetCacheManager.delegate is `weak`, so a
|
|
377
|
+
// delegate constructed inline in this statement is deallocated before the download it is waiting
|
|
378
|
+
// on can finish - the callback never arrives and the promise never settles, leaving the caller
|
|
379
|
+
// waiting forever with no error (SPEX-2481).
|
|
380
|
+
let delegate = DatasetDelegate(dataset: dataSet.cacheItem) { [weak self] success in
|
|
381
|
+
self?.datasetDelegate = nil
|
|
382
|
+
resolve(success)
|
|
383
|
+
}
|
|
384
|
+
datasetDelegate = delegate
|
|
385
|
+
datasetCacheManager.delegate = delegate
|
|
386
|
+
|
|
387
|
+
datasetCacheManager.synchronizeCacheItems([dataSet.cacheItem])
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
@objc(isBaseMapCachingSupported:rejecter:)
|
|
391
|
+
func isBaseMapCachingSupported(resolve: RCTPromiseResolveBlock, reject _: RCTPromiseRejectBlock) {
|
|
392
|
+
// Answered from which provider this package is built against, not from the SDK: the provider
|
|
393
|
+
// seam that knows is SPI, and the SDK only registers an implementation once a map provider has
|
|
394
|
+
// been constructed - so asking it would report false before the first map view exists, which is
|
|
395
|
+
// exactly when an app wants to decide whether to offer offline base maps at all.
|
|
396
|
+
//
|
|
397
|
+
// The module is MapsIndoorsMapbox; the *pod* is MapsIndoorsMapbox11. canImport takes the module
|
|
398
|
+
// name, and naming the pod here silently compiles to the unsupported branch on every build -
|
|
399
|
+
// which is what a `#if` gets you when it is wrong. MapsIndoorsViewManager.swift in the Mapbox
|
|
400
|
+
// package imports this same name.
|
|
401
|
+
#if canImport(MapsIndoorsMapbox)
|
|
402
|
+
return resolve(true)
|
|
403
|
+
#else
|
|
404
|
+
return resolve(false)
|
|
405
|
+
#endif
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
@objc(setBaseMapTilesEnabled:apiKey:resolver:rejecter:)
|
|
409
|
+
func setBaseMapTilesEnabled(enabled: Bool, apiKey: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
410
|
+
let datasetCacheManager = MPMapsIndoors.shared.datasetCacheManager
|
|
411
|
+
|
|
412
|
+
if let dataSet = datasetCacheManager.dataSetWithId(apiKey) {
|
|
413
|
+
datasetCacheManager.setBaseMapTilesEnabled(enabled, cacheItem: dataSet.cacheItem)
|
|
414
|
+
} else if datasetCacheManager.addDataSet(apiKey, cachingScope: .full, baseMapTilesEnabled: enabled) == nil {
|
|
415
|
+
// Managed from here on with the same `.full` scope cacheData uses: there is nothing to flag
|
|
416
|
+
// otherwise, and base-map caching needs the dataset's venues to know what to cache around.
|
|
417
|
+
return doReject(reject, message: "Unable to manage dataset '\(apiKey)'")
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return resolve(nil)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
@objc(synchronizeBaseMapTiles:resolver:rejecter:)
|
|
424
|
+
func synchronizeBaseMapTiles(apiKeys: [String]?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
425
|
+
let datasetCacheManager = MPMapsIndoors.shared.datasetCacheManager
|
|
426
|
+
var dataSets = [MPDataSetCache]()
|
|
427
|
+
|
|
428
|
+
if let apiKeys {
|
|
429
|
+
for apiKey in apiKeys {
|
|
430
|
+
guard let dataSet = datasetCacheManager.dataSetWithId(apiKey) else {
|
|
431
|
+
// Rejected rather than skipped: an explicit list is an explicit instruction, and
|
|
432
|
+
// silently caching nothing for a key the caller named is the harder failure to spot.
|
|
433
|
+
return doReject(reject, message: "No dataset is managed for '\(apiKey)', so base-map tiles cannot be cached for it")
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
dataSets.append(dataSet)
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
let progress: @Sendable (Double) -> Void = { [weak self] fraction in
|
|
441
|
+
guard let self, self.hasListeners else { return }
|
|
442
|
+
self.sendEvent(withName: MapsIndoorsData.Event.onBaseMapCacheProgress.rawValue, body: ["progress": fraction])
|
|
443
|
+
}
|
|
336
444
|
|
|
337
|
-
|
|
445
|
+
Task {
|
|
446
|
+
do {
|
|
447
|
+
if apiKeys == nil {
|
|
448
|
+
try await datasetCacheManager.synchronizeBaseMapTiles(progress: progress)
|
|
449
|
+
} else {
|
|
450
|
+
try await datasetCacheManager.synchronizeBaseMapTiles(dataSets, progress: progress)
|
|
451
|
+
}
|
|
452
|
+
return resolve(nil)
|
|
453
|
+
} catch let e {
|
|
454
|
+
return doRejectBaseMapCache(reject, error: e)
|
|
455
|
+
}
|
|
456
|
+
}
|
|
338
457
|
}
|
|
339
458
|
}
|
|
340
459
|
|
|
460
|
+
/// Rejects a base-map caching call, preserving the one error code the React Native API documents.
|
|
461
|
+
///
|
|
462
|
+
/// 9000 is the third copy of that value: Android's `MIError.BASEMAP_CACHE_NOT_SUPPORTED`, this
|
|
463
|
+
/// literal, and core's `MPError.baseMapCachingNotSupported` in TypeScript. Nothing links them, so a
|
|
464
|
+
/// change to one has to be made to all three.
|
|
465
|
+
///
|
|
466
|
+
/// The shared `doReject` reports everything as `unknownError`, which would leave JavaScript unable to
|
|
467
|
+
/// tell "this map provider cannot cache base-map tiles" - the expected outcome on a Google Maps build,
|
|
468
|
+
/// and the one an app should handle - apart from a download that failed. The code matches the Android
|
|
469
|
+
/// SDK's `MIError.BASEMAP_CACHE_NOT_SUPPORTED`, so one check in JavaScript works on both platforms.
|
|
470
|
+
private func doRejectBaseMapCache(_ reject: RCTPromiseRejectBlock, error: Error) {
|
|
471
|
+
guard let mpError = error as? MPError, mpError == .baseMapCachingNotSupported else {
|
|
472
|
+
return doReject(reject, error: error)
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
struct BaseMapCacheError: Codable {
|
|
476
|
+
let code: Int
|
|
477
|
+
let message: String
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
let err = BaseMapCacheError(code: 9000, message: String(describing: mpError))
|
|
481
|
+
|
|
482
|
+
return reject("NativeError", toJSON(err), error)
|
|
483
|
+
}
|
|
484
|
+
|
|
341
485
|
class DatasetDelegate: NSObject, MPDataSetCacheManagerDelegate {
|
|
342
|
-
|
|
343
|
-
|
|
486
|
+
private let dataset: MPDataSetCacheItem
|
|
487
|
+
private let completion: (Bool) -> Void
|
|
488
|
+
private var hasCompleted = false
|
|
344
489
|
|
|
345
|
-
init(
|
|
346
|
-
self.promise = promise
|
|
490
|
+
init(dataset: MPDataSetCacheItem, completion: @escaping (Bool) -> Void) {
|
|
347
491
|
self.dataset = dataset
|
|
492
|
+
self.completion = completion
|
|
348
493
|
}
|
|
349
494
|
|
|
350
495
|
func dataSetManager(_ dataSetManager: MPDataSetCacheManager, didFinishSynchronizingItem item: MPDataSetCacheItem) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
496
|
+
// Only this dataset settles the promise. Any other item finishing first used to resolve it
|
|
497
|
+
// `false` and then let this one resolve it a second time.
|
|
498
|
+
guard item.cachingItemId == dataset.cachingItemId else { return }
|
|
499
|
+
|
|
500
|
+
settle(success: item.syncResult == nil)
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
func dataSetManagerDidFinishSynchronizing(_ dataSetManager: MPDataSetCacheManager) {
|
|
504
|
+
// Backstop. didFinishSynchronizingItem is the precise signal, but nothing guarantees it fires
|
|
505
|
+
// for this item, and this whole class exists because a promise hung silently when its callback
|
|
506
|
+
// never arrived. The manager-level completion settles anything still outstanding, so that
|
|
507
|
+
// failure mode cannot recur in a different shape.
|
|
508
|
+
settle(success: dataset.syncResult == nil)
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
private func settle(success: Bool) {
|
|
512
|
+
guard !hasCompleted else { return }
|
|
513
|
+
|
|
514
|
+
hasCompleted = true
|
|
515
|
+
// The manager reports a failed sync on the item rather than through a separate callback, so
|
|
516
|
+
// without this a failure would resolve `true` exactly like a success.
|
|
517
|
+
completion(success)
|
|
356
518
|
}
|
|
357
519
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CallGeneration.swift
|
|
3
|
+
// react-native-maps-indoors
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
import Foundation
|
|
7
|
+
|
|
8
|
+
/// Makes last-call-wins hold for module methods that download before they apply.
|
|
9
|
+
///
|
|
10
|
+
/// Such a call can finish after a later one, and would then overwrite the later call's result. Each
|
|
11
|
+
/// call takes a token with ``next()`` and applies only while ``isCurrent(_:)`` - a call that finished
|
|
12
|
+
/// late is stale and drops its result.
|
|
13
|
+
///
|
|
14
|
+
/// The token has to be taken *synchronously*, before the call's `Task` is created. React Native
|
|
15
|
+
/// serialises a module's methods on one queue, and ``onMainThread`` runs them on the main queue in
|
|
16
|
+
/// that same order, so taking it there makes the token follow call order. Taking it inside the `Task`
|
|
17
|
+
/// would instead number the calls by whichever one the cooperative pool happened to schedule first,
|
|
18
|
+
/// which is not the order they were made in - the newer call could take the lower token and then be
|
|
19
|
+
/// discarded in favour of the older one.
|
|
20
|
+
final class CallGeneration: @unchecked Sendable {
|
|
21
|
+
private let lock = NSLock()
|
|
22
|
+
private var current: UInt64 = 0
|
|
23
|
+
|
|
24
|
+
/// Takes the next token, invalidating every earlier one.
|
|
25
|
+
func next() -> UInt64 {
|
|
26
|
+
lock.lock()
|
|
27
|
+
defer { lock.unlock() }
|
|
28
|
+
current &+= 1
|
|
29
|
+
return current
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// Whether `token` is still the newest, i.e. no later call has taken one.
|
|
33
|
+
func isCurrent(_ token: UInt64) -> Bool {
|
|
34
|
+
lock.lock()
|
|
35
|
+
defer { lock.unlock() }
|
|
36
|
+
return token == current
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MainThread.swift
|
|
3
|
+
// react-native-maps-indoors
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
import Foundation
|
|
7
|
+
|
|
8
|
+
/// Runs `work` on the main thread, which is where the MapsIndoors map control and directions
|
|
9
|
+
/// renderer have to be used.
|
|
10
|
+
///
|
|
11
|
+
/// React Native calls this package's module methods on their own method queue
|
|
12
|
+
/// (`requiresMainQueueSetup()` is `false`). `MPMapControl` and `MPDirectionsRenderer` are main-actor
|
|
13
|
+
/// isolated in the iOS SDK, and touching either from any other thread crashes the app (SPEX-2633,
|
|
14
|
+
/// SPEX-2686), so every module method that reads or writes them does that work in here and settles
|
|
15
|
+
/// its promise from in here too.
|
|
16
|
+
///
|
|
17
|
+
/// `work` is always enqueued, even when the caller is already on the main thread. React Native calls
|
|
18
|
+
/// a module's methods one at a time on its queue, and the main queue runs blocks in the order they
|
|
19
|
+
/// were added, so the map sees calls in the order the app made them. Running inline when already on
|
|
20
|
+
/// main would let such a call overtake one that was enqueued before it.
|
|
21
|
+
func onMainThread(_ work: @escaping @MainActor () -> Void) {
|
|
22
|
+
DispatchQueue.main.async {
|
|
23
|
+
MainActor.assumeIsolated(work)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -47,40 +47,56 @@ public class UtilsModule: NSObject {
|
|
|
47
47
|
return resolve(MPGeometryUtils.distance(from: MPGeoPoint(coordinate: it.coordinate), to: MPGeoPoint(coordinate: other.coordinate)))
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
|
|
51
|
+
/// Decodes a GeoJSON geometry string into something queryable.
|
|
52
|
+
///
|
|
53
|
+
/// `JSONDecoder().decode(MPGeometry.self, ...)` always produces a *base* `MPGeometry` - Swift's
|
|
54
|
+
/// decoder is not polymorphic - so `geo is MPPolygonGeometry` and `geo as? MPPolygonGeometry`
|
|
55
|
+
/// were always false here, and the SDK's `mp_polygon` / `mp_multiPolygon` accessors are an
|
|
56
|
+
/// internal NSObject category holding associated objects that nothing sets on a freshly decoded
|
|
57
|
+
/// value, so they were always nil. Every geometry helper in this file therefore fell through to
|
|
58
|
+
/// its default branch: `geometryIsInside` always answered false, `geometryArea` always 0, and
|
|
59
|
+
/// `polygonDistanceToClosestEdge` resolved nil.
|
|
60
|
+
///
|
|
61
|
+
/// Decoding the concrete type by its GeoJSON `type` discriminator fixes all three, and mirrors
|
|
62
|
+
/// how the Android module dispatches on `geometry.getType()`.
|
|
63
|
+
private func decodeQueryableGeometry(_ geometry: String) -> (any MPGeometryQueryProtocol)? {
|
|
64
|
+
let data = Data(geometry.utf8)
|
|
65
|
+
|
|
66
|
+
guard let base = try? JSONDecoder().decode(MPGeometry.self, from: data) else {
|
|
67
|
+
return nil
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
switch base.type {
|
|
71
|
+
case "Polygon":
|
|
72
|
+
return try? JSONDecoder().decode(MPPolygonGeometry.self, from: data)
|
|
73
|
+
case "MultiPolygon":
|
|
74
|
+
return try? JSONDecoder().decode(MPMultiPolygonGeometry.self, from: data)
|
|
75
|
+
default:
|
|
76
|
+
return nil
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
50
80
|
@objc public func geometryIsInside(_ point: String, geometry: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
|
51
81
|
guard let it = try? JSONDecoder().decode(MPPoint.self, from: Data(point.utf8)) as MPPoint else {
|
|
52
82
|
return reject("Utils error", "Venue not found for current Solution", MPError.unknownError)
|
|
53
83
|
}
|
|
54
84
|
|
|
55
|
-
guard let geo =
|
|
56
|
-
|
|
85
|
+
guard let geo = decodeQueryableGeometry(geometry) else {
|
|
86
|
+
// Not a polygon or multi-polygon: nothing can be inside it.
|
|
87
|
+
return resolve(false)
|
|
57
88
|
}
|
|
58
89
|
|
|
59
|
-
|
|
60
|
-
let poly = geo.mp_polygon
|
|
61
|
-
return resolve(poly?.containsCoordinate(it.coordinate))
|
|
62
|
-
} else if geo is MPMultiPolygonGeometry {
|
|
63
|
-
let multiPoly = geo.mp_multiPolygon
|
|
64
|
-
resolve(multiPoly?.containsCoordinate(it.coordinate))
|
|
65
|
-
} else {
|
|
66
|
-
resolve(false)
|
|
67
|
-
}
|
|
90
|
+
return resolve(geo.containsCoordinate(it.coordinate))
|
|
68
91
|
}
|
|
69
92
|
|
|
70
93
|
@objc public func geometryArea(_ geometry: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
|
71
|
-
guard let geo =
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if geo is MPPolygonGeometry {
|
|
76
|
-
let poly = geo.mp_polygon
|
|
77
|
-
return resolve(poly?.area)
|
|
78
|
-
} else if geo is MPMultiPolygonGeometry {
|
|
79
|
-
let multiPoly = geo.mp_multiPolygon
|
|
80
|
-
return resolve(multiPoly?.area)
|
|
81
|
-
} else {
|
|
94
|
+
guard let geo = decodeQueryableGeometry(geometry) else {
|
|
95
|
+
// A point or line has no area.
|
|
82
96
|
return resolve(0)
|
|
83
97
|
}
|
|
98
|
+
|
|
99
|
+
return resolve(geo.area)
|
|
84
100
|
}
|
|
85
101
|
|
|
86
102
|
@objc public func polygonDistanceToClosestEdge(_ point: String, geometry: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
|
@@ -88,29 +104,25 @@ public class UtilsModule: NSObject {
|
|
|
88
104
|
return reject("Utils error", "Venue not found for current Solution", MPError.unknownError)
|
|
89
105
|
}
|
|
90
106
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return resolve(shortestDistance)
|
|
112
|
-
}
|
|
113
|
-
return resolve(nil)
|
|
107
|
+
// Handles both Polygon and MultiPolygon, and lets the SDK do the maths. The hand-rolled
|
|
108
|
+
// loop this replaces walked only the outer ring - ignoring holes - and indexed
|
|
109
|
+
// `1..<outerRing.count`, which traps on an empty ring and yields
|
|
110
|
+
// Double.greatestFiniteMagnitude for a single-coordinate ring.
|
|
111
|
+
//
|
|
112
|
+
// Like the Android module, this returns the *squared* distance.
|
|
113
|
+
guard let geo = decodeQueryableGeometry(geometry) else {
|
|
114
|
+
return reject(
|
|
115
|
+
"Utils error",
|
|
116
|
+
"Geometry is neither a Polygon nor a MultiPolygon, so it has no edges",
|
|
117
|
+
MPError.unknownError
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Both overloads behave identically here; use the MPPoint one, as the Android module does.
|
|
122
|
+
// Note the SDK answers -1 for some geometry/point combinations even once the geometry
|
|
123
|
+
// decodes correctly - that is an SDK-level question, not something this module can fix. What
|
|
124
|
+
// matters here is that a number is resolved at all, honouring Promise<number>.
|
|
125
|
+
return resolve(geo.squaredDistanceToClosestEdge(it))
|
|
114
126
|
}
|
|
115
127
|
|
|
116
128
|
@objc public func parseMapClientUrl(_ venueId: String, locationId: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
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.
|
|
4
|
+
"version": "2.9.1",
|
|
5
5
|
"description": "React Native MapsIndoors component with mapbox",
|
|
6
6
|
"react-native": "index.ts",
|
|
7
7
|
"files": [
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"index.ts",
|
|
13
13
|
"ios",
|
|
14
14
|
"react-native-maps-indoors-mapbox.podspec",
|
|
15
|
+
"!src/core/__tests__",
|
|
16
|
+
"!ios/core/Package.swift",
|
|
17
|
+
"!ios/core/Tests",
|
|
18
|
+
"!ios/core/.build",
|
|
15
19
|
"!android/build",
|
|
16
20
|
"app.plugin.js"
|
|
17
21
|
],
|
|
@@ -21,6 +21,10 @@ Pod::Spec.new do |s|
|
|
|
21
21
|
s.source = { :git => "https://github.com/github_account/react-native-maps-indoors-mapbox.git", :tag => "#{s.version}" }
|
|
22
22
|
|
|
23
23
|
s.source_files = "ios/**/*.{h,c,cc,cpp,m,mm,swift}"
|
|
24
|
+
# ios/core carries a SwiftPM manifest and unit tests for its React-free helpers (SPEX-2686). They
|
|
25
|
+
# are run with `swift test` in that repository and must not be compiled into the pod, nor must the
|
|
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/**/*"
|
|
24
28
|
s.requires_arc = true
|
|
25
29
|
|
|
26
30
|
install_modules_dependencies(s)
|
|
@@ -33,6 +37,6 @@ Pod::Spec.new do |s|
|
|
|
33
37
|
# embeds the resulting dynamic frameworks into the app bundle, so the app builds and links but
|
|
34
38
|
# dies at launch with `Library not loaded: @rpath/MapsIndoorsCore.framework/MapsIndoorsCore`.
|
|
35
39
|
# See SPEX-2429 before reintroducing SPM here.
|
|
36
|
-
s.dependency "MapsIndoorsMapbox11", "4.
|
|
37
|
-
s.dependency "MapsIndoorsCodable", "4.
|
|
40
|
+
s.dependency "MapsIndoorsMapbox11", "4.23.0"
|
|
41
|
+
s.dependency "MapsIndoorsCodable", "4.23.0"
|
|
38
42
|
end
|
|
@@ -16,6 +16,9 @@ export interface Spec extends TurboModule {
|
|
|
16
16
|
setRoute(routeString: string, stopIcons: string, legIndex: number): Promise<null>;
|
|
17
17
|
setAnimatedPolyline(animated: boolean, repeated: boolean, duration: number): Promise<null>;
|
|
18
18
|
setPolyLineColors(foregroundString: string, backgroundString: string): Promise<null>;
|
|
19
|
+
setOptions(optionsString: string): Promise<null>;
|
|
20
|
+
getOptions(): Promise<string>;
|
|
21
|
+
finishGuidance(usagePercentage: number): Promise<null>;
|
|
19
22
|
showRouteLegButtons(value: boolean): Promise<null>;
|
|
20
23
|
setDefaultRouteStopIcon(iconString: string): Promise<null>;
|
|
21
24
|
}
|
|
@@ -2,6 +2,8 @@ import type {TurboModule} from 'react-native';
|
|
|
2
2
|
import {TurboModuleRegistry} from 'react-native';
|
|
3
3
|
|
|
4
4
|
export interface Spec extends TurboModule {
|
|
5
|
+
addListener(eventName: string): void;
|
|
6
|
+
removeListeners(count: number): void;
|
|
5
7
|
loadMapsIndoors(apiKey: string, optionalStrings: Array<string> | null): Promise<null>;
|
|
6
8
|
getDefaultVenue(): Promise<string | null>;
|
|
7
9
|
getVenues(): Promise<string>;
|
|
@@ -16,7 +18,7 @@ export interface Spec extends TurboModule {
|
|
|
16
18
|
getLocationById(id: string): Promise<string | null>;
|
|
17
19
|
getLocationsByExternalIds(ids: Array<string>): Promise<string>;
|
|
18
20
|
getMapStyles(): Promise<string>;
|
|
19
|
-
getSolution(): Promise<string
|
|
21
|
+
getSolution(): Promise<string>;
|
|
20
22
|
getLocationsAsync(query: string, filter: string): Promise<string>;
|
|
21
23
|
locationDisplayRuleExists(locationId: string): Promise<boolean>;
|
|
22
24
|
displayRuleNameExists(name: string): Promise<boolean>;
|
|
@@ -38,6 +40,9 @@ export interface Spec extends TurboModule {
|
|
|
38
40
|
removeVenuesToSync(venues: Array<string>): Promise<null>;
|
|
39
41
|
getSyncedVenues(): Promise<Array<string> | null>;
|
|
40
42
|
cacheData(apiKey: string): Promise<boolean>;
|
|
43
|
+
isBaseMapCachingSupported(): Promise<boolean>;
|
|
44
|
+
setBaseMapTilesEnabled(enabled: boolean, apiKey: string): Promise<null>;
|
|
45
|
+
synchronizeBaseMapTiles(apiKeys: Array<string> | null): Promise<null>;
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
export default TurboModuleRegistry.getEnforcing<Spec>('MapsIndoorsModule');
|
package/src/core/EventNames.ts
CHANGED
|
@@ -18,4 +18,7 @@ export enum EventNames {
|
|
|
18
18
|
onLiveLocationUpdate = "onLiveLocationUpdate",
|
|
19
19
|
floorSelector = "floorSelector",
|
|
20
20
|
onLegSelected = "onLegSelected",
|
|
21
|
+
// Canonical copy. Also spelled out in iOS's MapsIndoorsData.Event and as a literal in the
|
|
22
|
+
// Android bridge; drift silently delivers no progress.
|
|
23
|
+
onBaseMapCacheProgress = "onBaseMapCacheProgress",
|
|
21
24
|
}
|