@rnmapbox/maps 10.1.21 → 10.1.23

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.
@@ -13,6 +13,10 @@ def isNewArchitectureEnabled() {
13
13
  return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
14
14
  }
15
15
 
16
+ def getCoroutinesVersion(kotlinVersion) {
17
+ return kotlinVersion >= '1.9' ? '1.8.0' : '1.6.4'
18
+ }
19
+
16
20
  // expo plugin
17
21
  if (rootProject.ext.has('expoRNMapboxMapsImpl')) {
18
22
  rootProject.ext.set('RNMapboxMapsImpl', rootProject.ext.get('expoRNMapboxMapsImpl'))
@@ -21,15 +25,15 @@ if (rootProject.ext.has('expoRNMapboxMapsVersion')) {
21
25
  rootProject.ext.set('RNMapboxMapsVersion', rootProject.ext.get('expoRNMapboxMapsVersion'))
22
26
  }
23
27
 
24
-
25
28
  buildscript {
26
29
  repositories {
27
30
  google()
28
31
  mavenCentral()
29
32
  }
30
33
 
34
+ project.ext.set("kotlinVersion", rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : '1.7.21')
31
35
  dependencies {
32
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : '1.6.21'}"
36
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.kotlinVersion}"
33
37
  }
34
38
  }
35
39
 
@@ -142,9 +146,8 @@ dependencies {
142
146
  // React Native
143
147
  implementation "com.facebook.react:react-native:+"
144
148
 
145
- // kotlin coroutines
146
- implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${safeExtGet('kotlinxCoroutinesCoreVersion', '1.8.0')}"
147
- implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${safeExtGet('kotlinxCoroutinesAndroidVersion', '1.8.0')}"
149
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${safeExtGet('kotlinxCoroutinesCoreVersion', getCoroutinesVersion(project.kotlinVersion))}"
150
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${safeExtGet('kotlinxCoroutinesAndroidVersion', getCoroutinesVersion(project.kotlinVersion))}"
148
151
 
149
152
  // Mapbox SDK
150
153
  customizableDependencies('RNMapboxMapsLibs') {
@@ -171,7 +171,7 @@ open class RNMBXMapView: UIView {
171
171
  }()
172
172
 
173
173
  var _mapView: MapView! = nil
174
- func createMapView() {
174
+ func createMapView() -> MapView {
175
175
  if let mapViewImpl = mapViewImpl, let mapViewInstance = createAndAddMapViewImpl(mapViewImpl, self) {
176
176
  _mapView = mapViewInstance
177
177
  } else {
@@ -192,6 +192,7 @@ open class RNMBXMapView: UIView {
192
192
  _mapView.gestures.delegate = self
193
193
  setupEvents()
194
194
  afterMapViewAdded()
195
+ return _mapView
195
196
  }
196
197
 
197
198
  func createAndAddMapViewImpl(_ impl: String, _ view: RNMBXMapView) -> MapView? {
@@ -203,17 +204,20 @@ open class RNMBXMapView: UIView {
203
204
  }
204
205
  }
205
206
 
207
+ @available(*, deprecated, renamed: "withMapView", message: "mapView can be nil if the map initialization has not finished, use withMapView instead")
206
208
  public var mapView : MapView! {
207
209
  get { return _mapView }
208
210
  }
211
+
212
+ @available(*, deprecated, renamed: "withMapboxMap", message: "mapboxMap can be nil if the map initialization has not finished, use withMapboxMap instead")
209
213
  var mapboxMap: MapboxMap! {
210
- get { _mapView.mapboxMap }
214
+ get { _mapView?.mapboxMap }
211
215
  }
212
216
 
213
217
  @objc public func addToMap(_ subview: UIView) {
214
- withMapView {
218
+ withMapView { mapView in
215
219
  if let mapComponent = subview as? RNMBXMapComponent {
216
- let style = self.mapView.mapboxMap.style
220
+ let style = mapView.mapboxMap.style
217
221
  var addToMap = false
218
222
  if mapComponent.waitForStyleLoad() {
219
223
  if (self.styleLoaded) {
@@ -303,7 +307,7 @@ open class RNMBXMapView: UIView {
303
307
 
304
308
  // MARK: - React Native properties
305
309
  let changes : PropertyChanges<RNMBXMapView> = PropertyChanges()
306
- var mapViewWaiters : [()->Void] = []
310
+ var mapViewWaiters : [(_: MapView)->Void] = []
307
311
 
308
312
  enum Property : String {
309
313
  case projection
@@ -363,14 +367,24 @@ open class RNMBXMapView: UIView {
363
367
  changes.add(name: property.rawValue, update: property.apply)
364
368
  }
365
369
 
366
- func withMapView(callback: @escaping () -> Void) {
367
- if _mapView != nil {
368
- callback()
370
+ func withMapView(callback: @escaping (_: MapView) -> Void) {
371
+ if let mapView = _mapView {
372
+ callback(mapView)
369
373
  } else {
370
374
  mapViewWaiters.append(callback)
371
375
  }
372
376
  }
373
377
 
378
+ func withMapboxMap(callback: @escaping (_: MapboxMap) -> Void) {
379
+ if let mapboxMap = _mapView?.mapboxMap {
380
+ callback(mapboxMap)
381
+ } else {
382
+ mapViewWaiters.append { mapView in
383
+ callback(mapView.mapboxMap)
384
+ }
385
+ }
386
+ }
387
+
374
388
  var projection: StyleProjection?
375
389
 
376
390
  @objc public func setReactProjection(_ value: String?) {
@@ -698,9 +712,9 @@ open class RNMBXMapView: UIView {
698
712
 
699
713
  @objc override public func didSetProps(_ props: [String]) {
700
714
  if (_mapView == nil) {
701
- createMapView()
715
+ let view = createMapView()
702
716
 
703
- mapViewWaiters.forEach { $0() }
717
+ mapViewWaiters.forEach { $0(view) }
704
718
  mapViewWaiters.removeAll()
705
719
  }
706
720
  changes.apply(self)
@@ -23,25 +23,6 @@ open class RNMBXMapViewManager: RCTViewManager {
23
23
  }
24
24
  }
25
25
 
26
- // MARK: helpers
27
-
28
- extension RNMBXMapViewManager {
29
- static func withMapboxMap(
30
- _ view: RNMBXMapView,
31
- name: String,
32
- rejecter: @escaping RCTPromiseRejectBlock,
33
- fn: @escaping (_: MapboxMap) -> Void) -> Void
34
- {
35
- guard let mapboxMap = view.mapboxMap else {
36
- RNMBXLogError("MapboxMap is not yet available");
37
- rejecter(name, "Map not loaded yet", nil)
38
- return;
39
- }
40
-
41
- fn(mapboxMap)
42
- }
43
- }
44
-
45
26
  // MARK: - react methods
46
27
 
47
28
  extension RNMBXMapViewManager {
@@ -76,12 +57,12 @@ extension RNMBXMapViewManager {
76
57
  }
77
58
 
78
59
  @objc public static func getCenter(_ view: RNMBXMapView, resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
79
- withMapboxMap(view, name: "getCenter", rejecter:rejecter) { map in
80
- resolver(["center": [
81
- map.cameraState.center.longitude,
82
- map.cameraState.center.latitude
83
- ]])
84
- }
60
+ view.withMapboxMap { map in
61
+ resolver(["center": [
62
+ map.cameraState.center.longitude,
63
+ map.cameraState.center.latitude
64
+ ]])
65
+ }
85
66
  }
86
67
 
87
68
  @objc public static func getCoordinateFromView(
@@ -89,10 +70,10 @@ extension RNMBXMapViewManager {
89
70
  atPoint point: CGPoint,
90
71
  resolver: @escaping RCTPromiseResolveBlock,
91
72
  rejecter: @escaping RCTPromiseRejectBlock) {
92
- withMapboxMap(view, name: "getCoordinateFromView", rejecter:rejecter) { map in
93
- let coordinates = map.coordinate(for: point)
94
- resolver(["coordinateFromView": [coordinates.longitude, coordinates.latitude]])
95
- }
73
+ view.withMapboxMap { map in
74
+ let coordinates = map.coordinate(for: point)
75
+ resolver(["coordinateFromView": [coordinates.longitude, coordinates.latitude]])
76
+ }
96
77
 
97
78
  }
98
79
 
@@ -101,12 +82,11 @@ extension RNMBXMapViewManager {
101
82
  atCoordinate coordinate: [NSNumber],
102
83
  resolver: @escaping RCTPromiseResolveBlock,
103
84
  rejecter: @escaping RCTPromiseRejectBlock) {
104
- withMapboxMap(view, name: "getPointInView", rejecter:rejecter) { map in
105
- let coordinate = CLLocationCoordinate2DMake(coordinate[1].doubleValue, coordinate[0].doubleValue)
106
- let point = map.point(for: coordinate)
107
- resolver(["pointInView": [(point.x), (point.y)]])
108
- }
109
-
85
+ view.withMapboxMap { map in
86
+ let coordinate = CLLocationCoordinate2DMake(coordinate[1].doubleValue, coordinate[0].doubleValue)
87
+ let point = map.point(for: coordinate)
88
+ resolver(["pointInView": [(point.x), (point.y)]])
89
+ }
110
90
  }
111
91
 
112
92
  @objc public static func setHandledMapChangedEvents(
@@ -124,10 +104,9 @@ extension RNMBXMapViewManager {
124
104
  _ view: RNMBXMapView,
125
105
  resolver: @escaping RCTPromiseResolveBlock,
126
106
  rejecter: @escaping RCTPromiseRejectBlock) {
127
- withMapboxMap(view, name: "getZoom", rejecter:rejecter) { map in
128
- resolver(["zoom": map.cameraState.zoom])
129
- }
130
-
107
+ view.withMapboxMap { map in
108
+ resolver(["zoom": map.cameraState.zoom])
109
+ }
131
110
  }
132
111
 
133
112
  @objc public static func getVisibleBounds(
@@ -148,27 +127,26 @@ extension RNMBXMapViewManager {
148
127
  withLayerIDs layerIDs: [String]?,
149
128
  resolver: @escaping RCTPromiseResolveBlock,
150
129
  rejecter: @escaping RCTPromiseRejectBlock) -> Void {
151
- withMapboxMap(view, name: "queryRenderedFeaturesAtPoint", rejecter:rejecter) { map in
152
- let point = CGPoint(x: CGFloat(point[0].floatValue), y: CGFloat(point[1].floatValue))
153
-
154
- logged("queryRenderedFeaturesAtPoint.option", rejecter: rejecter) {
155
- let options = try RenderedQueryOptions(layerIds: (layerIDs ?? []).isEmpty ? nil : layerIDs, filter: filter?.asExpression())
156
-
157
- map.queryRenderedFeatures(with: point, options: options) { result in
158
- switch result {
159
- case .success(let features):
160
- resolver([
161
- "data": ["type": "FeatureCollection", "features": features.compactMap { queriedFeature in
162
- logged("queryRenderedFeaturesAtPoint.feature.toJSON") { try queriedFeature.feature.toJSON() }
163
- }]
164
- ])
165
- case .failure(let error):
166
- rejecter("queryRenderedFeaturesAtPoint","failed to query features", error)
167
- }
130
+ view.withMapboxMap { map in
131
+ let point = CGPoint(x: CGFloat(point[0].floatValue), y: CGFloat(point[1].floatValue))
132
+
133
+ logged("queryRenderedFeaturesAtPoint.option", rejecter: rejecter) {
134
+ let options = try RenderedQueryOptions(layerIds: (layerIDs ?? []).isEmpty ? nil : layerIDs, filter: filter?.asExpression())
135
+
136
+ map.queryRenderedFeatures(with: point, options: options) { result in
137
+ switch result {
138
+ case .success(let features):
139
+ resolver([
140
+ "data": ["type": "FeatureCollection", "features": features.compactMap { queriedFeature in
141
+ logged("queryRenderedFeaturesAtPoint.feature.toJSON") { try queriedFeature.feature.toJSON() }
142
+ }]
143
+ ])
144
+ case .failure(let error):
145
+ rejecter("queryRenderedFeaturesAtPoint","failed to query features", error)
168
146
  }
169
147
  }
170
- }
171
-
148
+ }
149
+ }
172
150
  }
173
151
 
174
152
  @objc public static func queryRenderedFeaturesInRect(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rnmapbox/maps",
3
3
  "description": "A Mapbox react native module for creating custom maps",
4
- "version": "10.1.21",
4
+ "version": "10.1.23",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },