@rnmapbox/maps 10.2.6 → 10.2.8

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 (116) hide show
  1. package/android/build.gradle +9 -1
  2. package/android/src/main/java/com/rnmapbox/rnmbx/RNMBXPackage.kt +8 -0
  3. package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt +7 -1
  4. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/RNMBXStyleFactory.kt +180 -0
  5. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/RNMBXStyleValue.kt +4 -0
  6. package/android/src/main/java/com/rnmapbox/rnmbx/modules/CustomHttpHeaders.kt +31 -9
  7. package/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt +15 -1
  8. package/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXOfflineModuleLegacy.kt +10 -0
  9. package/android/src/main/mapbox-v11-compat/v10/com/mapbox/maps/extension/style/layers/generated/RasterParticleLayer.kt +58 -0
  10. package/android/src/main/mapbox-v11-compat/v10/com/mapbox/maps/extension/style/sources/generated/RasterArraySource.kt +20 -0
  11. package/android/src/main/mapbox-v11-compat/v10/com/rnmapbox/rnmbx/components/styles/layers/RNMBXRasterParticleLayer.kt +22 -0
  12. package/android/src/main/mapbox-v11-compat/v10/com/rnmapbox/rnmbx/components/styles/layers/RNMBXRasterParticleLayerManager.kt +59 -0
  13. package/android/src/main/mapbox-v11-compat/v10/com/rnmapbox/rnmbx/components/styles/sources/RNMBXRasterArraySource.kt +16 -0
  14. package/android/src/main/mapbox-v11-compat/v10/com/rnmapbox/rnmbx/components/styles/sources/RNMBXRasterArraySourceManager.kt +59 -0
  15. package/android/src/main/mapbox-v11-compat/v10/com/rnmapbox/rnmbx/v11compat/StyleFactory.kt +45 -0
  16. package/android/src/main/mapbox-v11-compat/v11/com/rnmapbox/rnmbx/components/styles/layers/RNMBXRasterParticleLayer.kt +38 -0
  17. package/android/src/main/mapbox-v11-compat/v11/com/rnmapbox/rnmbx/components/styles/layers/RNMBXRasterParticleLayerManager.kt +85 -0
  18. package/android/src/main/mapbox-v11-compat/v11/com/rnmapbox/rnmbx/components/styles/sources/RNMBXRasterArraySource.kt +41 -0
  19. package/android/src/main/mapbox-v11-compat/v11/com/rnmapbox/rnmbx/components/styles/sources/RNMBXRasterArraySourceManager.kt +76 -0
  20. package/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXRasterArraySourceManagerDelegate.java +54 -0
  21. package/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXRasterArraySourceManagerInterface.java +23 -0
  22. package/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXRasterParticleLayerManagerDelegate.java +66 -0
  23. package/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXRasterParticleLayerManagerInterface.java +27 -0
  24. package/ios/RNMBX/CustomHttpHeaders.swift +36 -7
  25. package/ios/RNMBX/Offline/RNMBXOfflineModuleLegacy.m +2 -0
  26. package/ios/RNMBX/Offline/RNMBXOfflineModuleLegacy.swift +5 -0
  27. package/ios/RNMBX/RNMBXCamera.swift +88 -17
  28. package/ios/RNMBX/RNMBXCameraModule.h +3 -2
  29. package/ios/RNMBX/RNMBXCameraModule.mm +8 -16
  30. package/ios/RNMBX/RNMBXCustomLocationProvider.swift +18 -24
  31. package/ios/RNMBX/RNMBXImageModule.h +3 -2
  32. package/ios/RNMBX/RNMBXImageModule.mm +8 -16
  33. package/ios/RNMBX/RNMBXImages.swift +1 -4
  34. package/ios/RNMBX/RNMBXInteractiveElement.swift +22 -15
  35. package/ios/RNMBX/RNMBXMapView.swift +68 -6
  36. package/ios/RNMBX/RNMBXModule.m +1 -0
  37. package/ios/RNMBX/RNMBXModule.swift +16 -2
  38. package/ios/RNMBX/RNMBXNativeUserLocation.swift +6 -6
  39. package/ios/RNMBX/RNMBXPointAnnotation.swift +6 -8
  40. package/ios/RNMBX/RNMBXPointAnnotationModule.h +3 -2
  41. package/ios/RNMBX/RNMBXPointAnnotationModule.mm +8 -16
  42. package/ios/RNMBX/RNMBXRasterArraySource.swift +47 -0
  43. package/ios/RNMBX/RNMBXRasterArraySourceComponentView.h +15 -0
  44. package/ios/RNMBX/RNMBXRasterArraySourceComponentView.mm +168 -0
  45. package/ios/RNMBX/RNMBXRasterArraySourceViewManager.swift +16 -0
  46. package/ios/RNMBX/RNMBXRasterParticleLayer.swift +100 -0
  47. package/ios/RNMBX/RNMBXRasterParticleLayerComponentView.h +15 -0
  48. package/ios/RNMBX/RNMBXRasterParticleLayerComponentView.mm +121 -0
  49. package/ios/RNMBX/RNMBXRasterParticleLayerViewManager.swift +17 -0
  50. package/ios/RNMBX/RNMBXShapeSource.swift +5 -4
  51. package/ios/RNMBX/RNMBXShapeSourceModule.h +3 -2
  52. package/ios/RNMBX/RNMBXShapeSourceModule.mm +8 -16
  53. package/ios/RNMBX/RNMBXSource.swift +51 -21
  54. package/ios/RNMBX/RNMBXStyle.swift +152 -27
  55. package/ios/RNMBX/RNMBXStyleValue.swift +27 -0
  56. package/ios/RNMBX/RNMBXViewport.swift +13 -13
  57. package/ios/RNMBX/RNMBXViewportModule.h +3 -2
  58. package/ios/RNMBX/RNMBXViewportModule.mm +8 -16
  59. package/ios/RNMBX/Utils/RNMBXViewResolver.mm +15 -2
  60. package/lib/commonjs/plugin/build/withMapbox.js +8 -8
  61. package/lib/commonjs/plugin/src/withMapbox.ts +18 -8
  62. package/lib/module/Mapbox.native.js +2 -0
  63. package/lib/module/Mapbox.native.js.map +1 -1
  64. package/lib/module/RNMBXModule.js +15 -1
  65. package/lib/module/RNMBXModule.js.map +1 -1
  66. package/lib/module/components/PointAnnotation.js.map +1 -1
  67. package/lib/module/components/RasterArraySource.js +67 -0
  68. package/lib/module/components/RasterArraySource.js.map +1 -0
  69. package/lib/module/components/RasterParticleLayer.js +40 -0
  70. package/lib/module/components/RasterParticleLayer.js.map +1 -0
  71. package/lib/module/modules/offline/offlineManagerLegacy.js +14 -0
  72. package/lib/module/modules/offline/offlineManagerLegacy.js.map +1 -1
  73. package/lib/module/specs/RNMBXRasterArraySourceNativeComponent.ts +22 -0
  74. package/lib/module/specs/RNMBXRasterParticleLayerNativeComponent.ts +39 -0
  75. package/lib/module/utils/MapboxStyles.js.map +1 -1
  76. package/lib/module/utils/styleMap.js +9 -0
  77. package/lib/module/utils/styleMap.js.map +1 -1
  78. package/lib/typescript/plugin/build/withMapbox.d.ts +1 -6
  79. package/lib/typescript/plugin/build/withMapbox.d.ts.map +1 -1
  80. package/lib/typescript/plugin/src/withMapbox.d.ts.map +1 -1
  81. package/lib/typescript/scripts/autogenHelpers/generateCodeWithEjs.d.mts.map +1 -1
  82. package/lib/typescript/scripts/autogenHelpers/globals.d.mts +1 -1
  83. package/lib/typescript/scripts/autogenHelpers/globals.d.mts.map +1 -1
  84. package/lib/typescript/src/Mapbox.native.d.ts +3 -1
  85. package/lib/typescript/src/Mapbox.native.d.ts.map +1 -1
  86. package/lib/typescript/src/RNMBXModule.d.ts +11 -1
  87. package/lib/typescript/src/RNMBXModule.d.ts.map +1 -1
  88. package/lib/typescript/src/components/PointAnnotation.d.ts +1 -1
  89. package/lib/typescript/src/components/PointAnnotation.d.ts.map +1 -1
  90. package/lib/typescript/src/components/RasterArraySource.d.ts +72 -0
  91. package/lib/typescript/src/components/RasterArraySource.d.ts.map +1 -0
  92. package/lib/typescript/src/components/RasterParticleLayer.d.ts +80 -0
  93. package/lib/typescript/src/components/RasterParticleLayer.d.ts.map +1 -0
  94. package/lib/typescript/src/modules/offline/offlineManagerLegacy.d.ts +11 -0
  95. package/lib/typescript/src/modules/offline/offlineManagerLegacy.d.ts.map +1 -1
  96. package/lib/typescript/src/specs/RNMBXRasterArraySourceNativeComponent.d.ts +16 -0
  97. package/lib/typescript/src/specs/RNMBXRasterArraySourceNativeComponent.d.ts.map +1 -0
  98. package/lib/typescript/src/specs/RNMBXRasterParticleLayerNativeComponent.d.ts +25 -0
  99. package/lib/typescript/src/specs/RNMBXRasterParticleLayerNativeComponent.d.ts.map +1 -0
  100. package/lib/typescript/src/utils/MapboxStyles.d.ts +44 -2
  101. package/lib/typescript/src/utils/MapboxStyles.d.ts.map +1 -1
  102. package/lib/typescript/src/utils/styleMap.d.ts.map +1 -1
  103. package/package.json +13 -1
  104. package/plugin/build/withMapbox.js +8 -8
  105. package/plugin/src/withMapbox.ts +18 -8
  106. package/rnmapbox-maps.podspec +1 -1
  107. package/src/Mapbox.native.ts +3 -0
  108. package/src/RNMBXModule.ts +25 -2
  109. package/src/components/PointAnnotation.tsx +2 -2
  110. package/src/components/RasterArraySource.tsx +134 -0
  111. package/src/components/RasterParticleLayer.tsx +117 -0
  112. package/src/modules/offline/offlineManagerLegacy.ts +14 -0
  113. package/src/specs/RNMBXRasterArraySourceNativeComponent.ts +22 -0
  114. package/src/specs/RNMBXRasterParticleLayerNativeComponent.ts +39 -0
  115. package/src/utils/MapboxStyles.ts +47 -1
  116. package/src/utils/styleMap.ts +10 -0
@@ -15,11 +15,46 @@ public enum RemovalReason {
15
15
  case ViewRemoval, StyleChange, OnDestroy, ComponentChange, Reorder
16
16
  }
17
17
 
18
- public protocol RNMBXMapComponent: AnyObject {
18
+ /// Base protocol for all map components
19
+ public protocol RNMBXMapComponentProtocol: AnyObject {
20
+ func waitForStyleLoad() -> Bool
21
+ }
22
+
23
+ /// Default implementation: most components don't need to wait for style load
24
+ extension RNMBXMapComponentProtocol {
25
+ public func waitForStyleLoad() -> Bool {
26
+ return false
27
+ }
28
+ }
29
+
30
+ /// Protocol for components that can work without direct MapView access
31
+ public protocol RNMBXMapComponent: RNMBXMapComponentProtocol {
19
32
  func addToMap(_ map: RNMBXMapView, style: Style)
20
33
  func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool
21
-
22
- func waitForStyleLoad() -> Bool
34
+ }
35
+
36
+ /// Protocol for components that require a valid MapView instance for both add and remove operations.
37
+ /// Use this protocol when your component needs to interact with the native MapView directly.
38
+ /// The MapView parameter is guaranteed to be non-nil when these methods are called.
39
+ ///
40
+ /// This protocol inherits from RNMBXMapComponent to ensure compatibility with existing code,
41
+ /// but provides default implementations of the base protocol methods that throw errors,
42
+ /// forcing implementers to use the mapView-aware versions.
43
+ public protocol RNMBXMapAndMapViewComponent: RNMBXMapComponent {
44
+ func addToMap(_ map: RNMBXMapView, mapView: MapView, style: Style)
45
+ func removeFromMap(_ map: RNMBXMapView, mapView: MapView, reason: RemovalReason) -> Bool
46
+ }
47
+
48
+ /// Default implementations for RNMBXMapAndMapViewComponent that prevent accidental use of base protocol methods
49
+ extension RNMBXMapAndMapViewComponent {
50
+ public func addToMap(_ map: RNMBXMapView, style: Style) {
51
+ Logger.error("CRITICAL: addToMap(_:style:) called on RNMBXMapAndMapViewComponent. Use addToMap(_:mapView:style:) instead. Component: \(type(of: self))")
52
+ }
53
+
54
+ public func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool {
55
+ Logger.error("CRITICAL: removeFromMap(_:reason:) called on RNMBXMapAndMapViewComponent. Use removeFromMap(_:mapView:reason:) instead. Component: \(type(of: self))")
56
+ return false
57
+ }
23
58
  }
24
59
 
25
60
  enum CameraMode: Int {
@@ -85,7 +120,7 @@ class CameraUpdateQueue {
85
120
  open class RNMBXMapComponentBase : UIView, RNMBXMapComponent {
86
121
  private weak var _map: RNMBXMapView! = nil
87
122
  private var _mapCallbacks: [(RNMBXMapView) -> Void] = []
88
-
123
+
89
124
  weak var map : RNMBXMapView? {
90
125
  return _map;
91
126
  }
@@ -103,11 +138,7 @@ open class RNMBXMapComponentBase : UIView, RNMBXMapComponent {
103
138
  _mapCallbacks.append(callback)
104
139
  }
105
140
  }
106
-
107
- public func waitForStyleLoad() -> Bool {
108
- return false
109
- }
110
-
141
+
111
142
  public func addToMap(_ map: RNMBXMapView, style: Style) {
112
143
  _mapCallbacks.forEach { callback in
113
144
  callback(map)
@@ -115,7 +146,7 @@ open class RNMBXMapComponentBase : UIView, RNMBXMapComponent {
115
146
  _mapCallbacks = []
116
147
  _map = map
117
148
  }
118
-
149
+
119
150
  public func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool {
120
151
  _mapCallbacks = []
121
152
  _map = nil
@@ -123,8 +154,48 @@ open class RNMBXMapComponentBase : UIView, RNMBXMapComponent {
123
154
  }
124
155
  }
125
156
 
157
+ /// Base class for components that require MapView to be non-nil
158
+ open class RNMBXMapAndMapViewComponentBase : UIView, RNMBXMapAndMapViewComponent {
159
+ private weak var _map: RNMBXMapView! = nil
160
+ private var _mapCallbacks: [(RNMBXMapView) -> Void] = []
161
+
162
+ weak var map : RNMBXMapView? {
163
+ return _map;
164
+ }
165
+
166
+ func withMapView(_ callback: @escaping (_ mapView: MapView) -> Void) {
167
+ withRNMBXMapView { mapView in
168
+ callback(mapView.mapView)
169
+ }
170
+ }
171
+
172
+ func withRNMBXMapView(_ callback: @escaping (_ map: RNMBXMapView) -> Void) {
173
+ if let map = _map {
174
+ callback(map)
175
+ } else {
176
+ _mapCallbacks.append(callback)
177
+ }
178
+ }
179
+
180
+ // Uses default implementation from RNMBXMapComponentProtocol extension
181
+
182
+ public func addToMap(_ map: RNMBXMapView, mapView: MapView, style: Style) {
183
+ _mapCallbacks.forEach { callback in
184
+ callback(map)
185
+ }
186
+ _mapCallbacks = []
187
+ _map = map
188
+ }
189
+
190
+ public func removeFromMap(_ map: RNMBXMapView, mapView: MapView, reason: RemovalReason) -> Bool {
191
+ _mapCallbacks = []
192
+ _map = nil
193
+ return true
194
+ }
195
+ }
196
+
126
197
  @objc(RNMBXCamera)
127
- open class RNMBXCamera : RNMBXMapComponentBase {
198
+ open class RNMBXCamera : RNMBXMapAndMapViewComponentBase {
128
199
  var cameraAnimator: BasicCameraAnimator?
129
200
  let cameraUpdateQueue = CameraUpdateQueue()
130
201
 
@@ -519,18 +590,18 @@ open class RNMBXCamera : RNMBXMapComponentBase {
519
590
  _updateCamera()
520
591
  }
521
592
 
522
- public override func addToMap(_ map: RNMBXMapView, style: Style) {
523
- super.addToMap(map, style: style)
593
+ public override func addToMap(_ map: RNMBXMapView, mapView: MapView, style: Style) {
594
+ super.addToMap(map, mapView: mapView, style: style)
524
595
  map.reactCamera = self
525
596
  }
526
-
527
- public override func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool {
597
+
598
+ public override func removeFromMap(_ map: RNMBXMapView, mapView: MapView, reason: RemovalReason) -> Bool {
528
599
  if (reason == .StyleChange) {
529
600
  return false
530
601
  }
531
602
 
532
- map.mapView.viewport.removeStatusObserver(self)
533
- return super.removeFromMap(map, reason:reason)
603
+ mapView.viewport.removeStatusObserver(self)
604
+ return super.removeFromMap(map, mapView: mapView, reason: reason)
534
605
  }
535
606
 
536
607
  @objc public func moveBy(x: Double, y: Double, animationMode: NSNumber?, animationDuration: NSNumber?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
@@ -1,5 +1,6 @@
1
1
  #import <Foundation/Foundation.h>
2
2
  #import <UIKit/UIKit.h>
3
+ #import "RNMBXViewResolver.h"
3
4
 
4
5
  #ifdef RCT_NEW_ARCH_ENABLED
5
6
  #import "rnmapbox_maps_specs.h"
@@ -9,9 +10,9 @@
9
10
 
10
11
  @interface RNMBXCameraModule : NSObject
11
12
  #ifdef RCT_NEW_ARCH_ENABLED
12
- <NativeRNMBXCameraModuleSpec>
13
+ <NativeRNMBXCameraModuleSpec, RNMBXViewResolverDelegate>
13
14
  #else
14
- <RCTBridgeModule>
15
+ <RCTBridgeModule, RNMBXViewResolverDelegate>
15
16
  #endif
16
17
 
17
18
  @end
@@ -36,22 +36,14 @@ RCT_EXPORT_MODULE();
36
36
 
37
37
  - (void)withCamera:(nonnull NSNumber*)viewRef block:(void (^)(RNMBXCamera *))block reject:(RCTPromiseRejectBlock)reject methodName:(NSString *)methodName
38
38
  {
39
- #ifdef RCT_NEW_ARCH_ENABLED
40
- [self.viewRegistry_DEPRECATED addUIBlock:^(RCTViewRegistry *viewRegistry) {
41
- RNMBXCameraComponentView *componentView = [self.viewRegistry_DEPRECATED viewForReactTag:viewRef];
42
- RNMBXCamera *view = componentView.contentView;
43
-
44
- #else
45
- [self.bridge.uiManager
46
- addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
47
- RNMBXCamera *view = [uiManager viewForReactTag:viewRef];
48
- #endif // RCT_NEW_ARCH_ENABLED
49
- if (view != nil) {
50
- block(view);
51
- } else {
52
- reject(methodName, [NSString stringWithFormat:@"Unknown reactTag: %@", viewRef], nil);
53
- }
54
- }];
39
+ [RNMBXViewResolver withViewRef:viewRef
40
+ delegate:self
41
+ expectedClass:[RNMBXCamera class]
42
+ block:^(UIView *view) {
43
+ block((RNMBXCamera *)view);
44
+ }
45
+ reject:reject
46
+ methodName:methodName];
55
47
  }
56
48
 
57
49
  RCT_EXPORT_METHOD(updateCameraStop:(nonnull NSNumber *)viewRef
@@ -3,15 +3,15 @@ import MapboxMaps
3
3
  let TAG = "RNMBXCustomLocationProvider"
4
4
 
5
5
  @objc
6
- public class RNMBXCustomLocationProvider: UIView, RNMBXMapComponent {
6
+ public class RNMBXCustomLocationProvider: UIView, RNMBXMapAndMapViewComponent {
7
7
  var map: RNMBXMapView? = nil
8
-
8
+
9
9
  let changes : PropertyChanges<RNMBXCustomLocationProvider> = PropertyChanges()
10
-
10
+
11
11
  enum Property: String {
12
12
  case coordinate
13
13
  case heading
14
-
14
+
15
15
  func apply(locationProvider: RNMBXCustomLocationProvider) {
16
16
  switch self {
17
17
  case .coordinate: locationProvider.applyCoordinate()
@@ -19,61 +19,55 @@ public class RNMBXCustomLocationProvider: UIView, RNMBXMapComponent {
19
19
  }
20
20
  }
21
21
  }
22
-
22
+
23
23
  @objc
24
24
  public var coordinate: [Double] = [] {
25
25
  didSet { changed(.coordinate) }
26
26
  }
27
-
27
+
28
28
  @objc
29
29
  public var heading: NSNumber = 0.0 {
30
30
  didSet { changed(.heading) }
31
31
  }
32
-
32
+
33
33
  func changed(_ property: Property) {
34
34
  changes.add(name: property.rawValue, update: property.apply)
35
35
  }
36
-
36
+
37
37
  @objc
38
38
  override public func didSetProps(_ props: [String]) {
39
39
  if customLocationProvider != nil {
40
40
  changes.apply(self)
41
41
  }
42
42
  }
43
-
43
+
44
44
  var customLocationProvider: CustomLocationProvider? = nil
45
45
  #if RNMBX_11
46
46
  #else
47
47
  var defaultLocationProvider: LocationProvider?
48
48
  #endif
49
49
 
50
- public func addToMap(_ map: RNMBXMapView, style: Style) {
50
+ public func addToMap(_ map: RNMBXMapView, mapView: MapView, style: Style) {
51
51
  self.map = map
52
- if let mapView = map.mapView {
53
- installCustomeLocationProviderIfNeeded(mapView: mapView)
54
- changes.apply(self)
55
- }
52
+ installCustomeLocationProviderIfNeeded(mapView: mapView)
53
+ changes.apply(self)
56
54
  }
57
-
55
+
58
56
  private func applyCoordinate() {
59
57
  updateCoordinate(latitude: coordinate[1], longitude: coordinate[0])
60
58
  }
61
-
59
+
62
60
  private func applyHeading() {
63
61
  updateHeading(heading: heading.doubleValue)
64
62
  }
65
-
66
- public func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool {
67
- if let mapView = map.mapView {
68
- removeCustomLocationProvider(mapView: mapView)
69
- }
63
+
64
+ public func removeFromMap(_ map: RNMBXMapView, mapView: MapView, reason: RemovalReason) -> Bool {
65
+ removeCustomLocationProvider(mapView: mapView)
70
66
  self.map = nil
71
67
  return true
72
68
  }
73
69
 
74
- public func waitForStyleLoad() -> Bool {
75
- false
76
- }
70
+ // Uses default implementation from RNMBXMapComponentProtocol extension (returns false)
77
71
  }
78
72
 
79
73
  #if RNMBX_11
@@ -1,5 +1,6 @@
1
1
  #import <Foundation/Foundation.h>
2
2
  #import <UIKit/UIKit.h>
3
+ #import "RNMBXViewResolver.h"
3
4
 
4
5
  #ifdef RCT_NEW_ARCH_ENABLED
5
6
  #import "rnmapbox_maps_specs.h"
@@ -9,9 +10,9 @@
9
10
 
10
11
  @interface RNMBXImageModule : NSObject
11
12
  #ifdef RCT_NEW_ARCH_ENABLED
12
- <NativeRNMBXImageModuleSpec>
13
+ <NativeRNMBXImageModuleSpec, RNMBXViewResolverDelegate>
13
14
  #else
14
- <RCTBridgeModule>
15
+ <RCTBridgeModule, RNMBXViewResolverDelegate>
15
16
  #endif
16
17
 
17
18
  @end
@@ -27,22 +27,14 @@ RCT_EXPORT_MODULE();
27
27
 
28
28
  - (void)withImage:(nonnull NSNumber*)viewRef block:(void (^)(RNMBXImage *))block reject:(RCTPromiseRejectBlock)reject methodName:(NSString *)methodName
29
29
  {
30
- #ifdef RCT_NEW_ARCH_ENABLED
31
- [self.viewRegistry_DEPRECATED addUIBlock:^(RCTViewRegistry *viewRegistry) {
32
- RNMBXImageComponentView *componentView = [self.viewRegistry_DEPRECATED viewForReactTag:viewRef];
33
- RNMBXImage *view = componentView.contentView;
34
-
35
- #else
36
- [self.bridge.uiManager
37
- addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
38
- RNMBXImage *view = [uiManager viewForReactTag:viewRef];
39
- #endif // RCT_NEW_ARCH_ENABLED
40
- if (view != nil) {
41
- block(view);
42
- } else {
43
- reject(methodName, [NSString stringWithFormat:@"Unknown reactTag: %@", viewRef], nil);
44
- }
45
- }];
30
+ [RNMBXViewResolver withViewRef:viewRef
31
+ delegate:self
32
+ expectedClass:[RNMBXImage class]
33
+ block:^(UIView *view) {
34
+ block((RNMBXImage *)view);
35
+ }
36
+ reject:reject
37
+ methodName:methodName];
46
38
  }
47
39
 
48
40
 
@@ -74,11 +74,8 @@ open class RNMBXImages : UIView, RNMBXMapComponent {
74
74
  }
75
75
 
76
76
  // MARK: - RNMBXMapComponent
77
+ // Uses default implementation from RNMBXMapComponentProtocol extension (returns false)
77
78
 
78
- public func waitForStyleLoad() -> Bool {
79
- return false
80
- }
81
-
82
79
  public func addToMap(_ map: RNMBXMapView, style: Style) {
83
80
  self.style = style
84
81
  imageManager = map.imageManager
@@ -1,38 +1,43 @@
1
1
  import MapboxMaps
2
2
 
3
3
  @objc
4
- public class RNMBXInteractiveElement : UIView, RNMBXMapComponent {
4
+ public class RNMBXInteractiveElement : UIView, RNMBXMapAndMapViewComponent {
5
5
  weak var map : RNMBXMapView? = nil
6
+ weak var mapView : MapView? = nil
6
7
 
7
8
  static let hitboxDefault = 44.0
8
9
 
9
10
  @objc public var draggable: Bool = false
10
-
11
+
11
12
  @objc public var hasPressListener: Bool = false
12
-
13
+
13
14
  @objc public var hitbox : [String:NSNumber] = [
14
15
  "width": NSNumber(value: hitboxDefault),
15
16
  "height": NSNumber(value: hitboxDefault)
16
17
  ]
17
-
18
+
18
19
  @objc public var id: String! = nil {
19
20
  willSet {
20
21
  if id != nil && newValue != id {
21
22
  Logger.log(level:.warn, message: "Changing id from: \(optional: id) to \(optional: newValue), changing of id is not supported")
22
- if let map = map { removeFromMap(map, reason: .ComponentChange) }
23
+ if let map = map, let mapView = mapView {
24
+ removeFromMap(map, mapView: mapView, reason: .ComponentChange)
25
+ }
23
26
  }
24
27
  }
25
28
  didSet {
26
29
  if oldValue != nil && oldValue != id {
27
- if let map = map { addToMap(map, style: map.mapboxMap.style) }
30
+ if let map = map, let mapView = mapView {
31
+ addToMap(map, mapView: mapView, style: mapView.mapboxMap.style)
32
+ }
28
33
  }
29
34
  }
30
35
  }
31
-
36
+
32
37
  @objc public var onDragStart: RCTBubblingEventBlock? = nil
33
-
38
+
34
39
  @objc public var onPress: RCTBubblingEventBlock? = nil
35
-
40
+
36
41
  func getLayerIDs() -> [String] {
37
42
  return []
38
43
  }
@@ -40,24 +45,26 @@ public class RNMBXInteractiveElement : UIView, RNMBXMapComponent {
40
45
  func isDraggable() -> Bool {
41
46
  return draggable
42
47
  }
43
-
48
+
44
49
  func isTouchable() -> Bool {
45
50
  return hasPressListener
46
51
  }
47
-
48
- // MARK: - RNMBXMapComponent
49
- public func addToMap(_ map: RNMBXMapView, style: Style) {
52
+
53
+ // MARK: - RNMBXMapAndMapViewComponent
54
+ public func addToMap(_ map: RNMBXMapView, mapView: MapView, style: Style) {
50
55
  if (self.id == nil) {
51
56
  Logger.log(level: .error, message: "id is required on \(self) but not specified")
52
57
  }
53
58
  self.map = map
59
+ self.mapView = mapView
54
60
  }
55
61
 
56
- public func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool {
62
+ public func removeFromMap(_ map: RNMBXMapView, mapView: MapView, reason: RemovalReason) -> Bool {
57
63
  self.map = nil
64
+ self.mapView = nil
58
65
  return true
59
66
  }
60
-
67
+
61
68
  public func waitForStyleLoad() -> Bool {
62
69
  return true
63
70
  }
@@ -60,11 +60,11 @@ public class RNMBXMapViewFactory {
60
60
  }
61
61
 
62
62
  class FeatureEntry {
63
- let feature: RNMBXMapComponent
63
+ let feature: AnyObject // Can be RNMBXMapComponent or RNMBXMapAndMapViewComponent
64
64
  let view: UIView
65
65
  var addedToMap: Bool = false
66
66
 
67
- init(feature:RNMBXMapComponent, view: UIView, addedToMap: Bool = false) {
67
+ init(feature: AnyObject, view: UIView, addedToMap: Bool = false) {
68
68
  self.feature = feature
69
69
  self.view = view
70
70
  self.addedToMap = addedToMap
@@ -269,7 +269,27 @@ open class RNMBXMapView: UIView, RCTInvalidating {
269
269
 
270
270
  @objc public func addToMap(_ subview: UIView) {
271
271
  withMapView { mapView in
272
- if let mapComponent = subview as? RNMBXMapComponent {
272
+ // Check for RNMBXMapAndMapViewComponent first (requires MapView)
273
+ if let mapAndMapViewComponent = subview as? RNMBXMapAndMapViewComponent {
274
+ let style = mapView.mapboxMap.style
275
+ var addToMap = false
276
+ if mapAndMapViewComponent.waitForStyleLoad() {
277
+ if (self.styleLoadWaiters.hasInited()) {
278
+ addToMap = true
279
+ }
280
+ } else {
281
+ addToMap = true
282
+ }
283
+
284
+ let entry = FeatureEntry(feature: mapAndMapViewComponent, view: subview, addedToMap: false)
285
+ if (addToMap) {
286
+ mapAndMapViewComponent.addToMap(self, mapView: mapView, style: style)
287
+ entry.addedToMap = true
288
+ }
289
+ self.features.append(entry)
290
+ }
291
+ // Fallback to RNMBXMapComponent (doesn't require MapView)
292
+ else if let mapComponent = subview as? RNMBXMapComponent {
273
293
  let style = mapView.mapboxMap.style
274
294
  var addToMap = false
275
295
  if mapComponent.waitForStyleLoad() {
@@ -296,7 +316,26 @@ open class RNMBXMapView: UIView, RCTInvalidating {
296
316
  }
297
317
 
298
318
  @objc public func removeFromMap(_ subview: UIView) {
299
- if let mapComponent = subview as? RNMBXMapComponent {
319
+ // Check for RNMBXMapAndMapViewComponent first (requires MapView)
320
+ if let mapAndMapViewComponent = subview as? RNMBXMapAndMapViewComponent {
321
+ var entryIndex = features.firstIndex { $0.view == subview }
322
+ if let entryIndex = entryIndex {
323
+ var entry = features[entryIndex]
324
+ if (entry.addedToMap) {
325
+ // mapView should always be non-nil here if our invariants hold
326
+ guard let mapView = _mapView else {
327
+ Logger.error("RNMBXMapView.removeFromMap: CRITICAL - mapView is nil for component that requires it: \(type(of: subview))")
328
+ features.remove(at: entryIndex)
329
+ return
330
+ }
331
+ mapAndMapViewComponent.removeFromMap(self, mapView: mapView, reason: .OnDestroy)
332
+ entry.addedToMap = false
333
+ }
334
+ features.remove(at: entryIndex)
335
+ }
336
+ }
337
+ // Fallback to RNMBXMapComponent (doesn't require MapView)
338
+ else if let mapComponent = subview as? RNMBXMapComponent {
300
339
  var entryIndex = features.firstIndex { $0.view == subview }
301
340
  if let entryIndex = entryIndex {
302
341
  var entry = features[entryIndex]
@@ -842,16 +881,39 @@ open class RNMBXMapView: UIView, RCTInvalidating {
842
881
  private func removeAllFeaturesFromMap(reason: RemovalReason) {
843
882
  features.forEach { entry in
844
883
  if (entry.addedToMap) {
845
- entry.feature.removeFromMap(self, reason: reason)
884
+ // Handle RNMBXMapAndMapViewComponent
885
+ if let mapAndMapViewComponent = entry.feature as? RNMBXMapAndMapViewComponent {
886
+ guard let mapView = _mapView else {
887
+ Logger.error("RNMBXMapView.removeAllFeaturesFromMap: mapView is nil")
888
+ return
889
+ }
890
+ mapAndMapViewComponent.removeFromMap(self, mapView: mapView, reason: reason)
891
+ }
892
+ // Handle RNMBXMapComponent
893
+ else if let mapComponent = entry.feature as? RNMBXMapComponent {
894
+ mapComponent.removeFromMap(self, reason: reason)
895
+ }
846
896
  entry.addedToMap = false
847
897
  }
848
898
  }
849
899
  }
850
900
 
851
901
  private func addFeaturesToMap(style: Style) {
902
+ guard let mapView = _mapView else {
903
+ Logger.error("RNMBXMapView.addFeaturesToMap: mapView is nil")
904
+ return
905
+ }
906
+
852
907
  features.forEach { entry in
853
908
  if (!entry.addedToMap) {
854
- entry.feature.addToMap(self, style: style)
909
+ // Handle RNMBXMapAndMapViewComponent
910
+ if let mapAndMapViewComponent = entry.feature as? RNMBXMapAndMapViewComponent {
911
+ mapAndMapViewComponent.addToMap(self, mapView: mapView, style: style)
912
+ }
913
+ // Handle RNMBXMapComponent
914
+ else if let mapComponent = entry.feature as? RNMBXMapComponent {
915
+ mapComponent.addToMap(self, style: style)
916
+ }
855
917
  entry.addedToMap = true
856
918
  }
857
919
  }
@@ -5,6 +5,7 @@
5
5
  RCT_EXTERN_METHOD(setAccessToken:(NSString *)accessToken resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
6
6
 
7
7
  RCT_EXTERN_METHOD(addCustomHeader:(NSString *)headerName forHeaderValue:(NSString *) headerValue)
8
+ RCT_EXTERN_METHOD(addCustomHeaderWithOptions:(NSString *)headerName forHeaderValue:(NSString *) headerValue forOptions:(nullable NSDictionary *) options)
8
9
  RCT_EXTERN_METHOD(removeCustomHeader:(NSString *)headerName)
9
10
 
10
11
  RCT_EXTERN_METHOD(setTelemetryEnabled:(BOOL)telemetryEnabled)
@@ -98,9 +98,23 @@ class RNMBXModule : NSObject {
98
98
  RNMBXModule.accessToken = token
99
99
  resolver(token)
100
100
  }
101
+
102
+ @objc func addCustomHeader(_ headerName: String, forHeaderValue headerValue: String) {
103
+ addCustomHeaderWithOptions(headerName, forHeaderValue: headerValue, forOptions: nil)
104
+ }
101
105
 
102
- @objc func addCustomHeader(_ headerName: String, forHeaderValue headerValue: String ) {
103
- CustomHttpHeaders.shared.customHeaders[headerName] = headerValue
106
+ @objc func addCustomHeaderWithOptions(_ headerName: String, forHeaderValue headerValue: String, forOptions options: NSDictionary?) {
107
+ var urlRegexp: NSRegularExpression? = nil
108
+ if let pattern = options?.value(forKey: "urlRegexp") as? String {
109
+ do {
110
+ urlRegexp = try NSRegularExpression(pattern: pattern)
111
+ }
112
+ catch {
113
+ Logger.log(level: .error, message: "Invalid regex pattern: \(error.localizedDescription)")
114
+ }
115
+ }
116
+
117
+ CustomHttpHeaders.shared.customHeaders[headerName] = CustomHttpHeadersMapValue(headerValue: headerValue, options: CustomHttpHeadersOptions(urlRegexp: urlRegexp))
104
118
  }
105
119
 
106
120
  @objc func removeCustomHeader(_ headerName: String) {
@@ -1,7 +1,7 @@
1
1
  import MapboxMaps
2
2
 
3
3
  @objc
4
- public class RNMBXNativeUserLocation: UIView, RNMBXMapComponent {
4
+ public class RNMBXNativeUserLocation: UIView, RNMBXMapAndMapViewComponent {
5
5
  weak var map : RNMBXMapView! = nil
6
6
  var imageManager: ImageManager? = nil
7
7
 
@@ -200,19 +200,19 @@ public class RNMBXNativeUserLocation: UIView, RNMBXMapComponent {
200
200
  }
201
201
  }
202
202
 
203
- public func addToMap(_ map: RNMBXMapView, style: Style) {
203
+ public func addToMap(_ map: RNMBXMapView, mapView: MapView, style: Style) {
204
204
  self.map = map
205
-
205
+
206
206
  _fetchImages(map)
207
207
  _apply()
208
208
  }
209
209
 
210
- public func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool {
211
- if let location = map.mapView.location {
210
+ public func removeFromMap(_ map: RNMBXMapView, mapView: MapView, reason: RemovalReason) -> Bool {
211
+ if let location = mapView.location {
212
212
  location.options.puckType = nil
213
213
  location.options.puckType = .none
214
214
  } else {
215
- Logger.error("RNMBXNativeUserLocation.removeFromMap: location is nil")
215
+ Logger.error("[RNMBXNativeUserLocation] removeFromMap, location is null")
216
216
  }
217
217
  removeSubscriptions()
218
218
  self.map = nil
@@ -248,18 +248,16 @@ public class RNMBXPointAnnotation : RNMBXInteractiveElement {
248
248
  }
249
249
  }
250
250
 
251
- // MARK: - RNMBXMapComponent
252
-
253
- public override func addToMap(_ map: RNMBXMapView, style: Style) {
254
- super.addToMap(map, style: style)
255
- self.map = map
251
+ // MARK: - RNMBXMapAndMapViewComponent
252
+
253
+ public override func addToMap(_ map: RNMBXMapView, mapView: MapView, style: Style) {
254
+ super.addToMap(map, mapView: mapView, style: style)
256
255
  addIfPossible()
257
256
  }
258
257
 
259
- public override func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool {
258
+ public override func removeFromMap(_ map: RNMBXMapView, mapView: MapView, reason: RemovalReason) -> Bool {
260
259
  removeIfAdded()
261
- self.map = nil
262
- return true
260
+ return super.removeFromMap(map, mapView: mapView, reason: reason)
263
261
  }
264
262
 
265
263
  // MARK: - RNMBXInteractiveElement