@rnmapbox/maps 10.2.5 → 10.2.7

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/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt +4 -4
  2. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/RNMBXStyle.kt +1 -1
  3. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/RNMBXStyleFactory.kt +0 -1
  4. package/android/src/main/java/com/rnmapbox/rnmbx/components/styles/RNMBXStyleValue.kt +6 -2
  5. package/android/src/main/java/com/rnmapbox/rnmbx/modules/CustomHttpHeaders.kt +31 -9
  6. package/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt +15 -1
  7. package/android/src/main/java/com/rnmapbox/rnmbx/utils/ConvertUtils.kt +239 -0
  8. package/android/src/main/java/com/rnmapbox/rnmbx/utils/GeoJSONUtils.kt +5 -2
  9. package/android/src/main/mapbox-v11-compat/v10/com/rnmapbox/rnmbx/v11compat/StyleFactory.kt +29 -0
  10. package/android/src/test/kotlin/com/rnmapbox/rnmbx/components/styles/RNMBXStyleValueTest.kt +2 -2
  11. package/ios/RNMBX/CustomHttpHeaders.swift +36 -7
  12. package/ios/RNMBX/RNMBXCustomLocationProvider.swift +4 -1
  13. package/ios/RNMBX/RNMBXCustomLocationProviderComponentView.mm +12 -2
  14. package/ios/RNMBX/RNMBXFabricPropConvert.h +12 -4
  15. package/ios/RNMBX/RNMBXFabricPropConvert.mm +4 -0
  16. package/ios/RNMBX/RNMBXMapViewComponentView.mm +2 -0
  17. package/ios/RNMBX/RNMBXModule.m +1 -0
  18. package/ios/RNMBX/RNMBXModule.swift +16 -2
  19. package/ios/RNMBX/Utils/RNMBXViewResolver.mm +15 -2
  20. package/lib/commonjs/plugin/build/withMapbox.js +8 -8
  21. package/lib/commonjs/plugin/src/withMapbox.ts +8 -8
  22. package/lib/module/RNMBXModule.js +15 -1
  23. package/lib/module/RNMBXModule.js.map +1 -1
  24. package/lib/module/components/MapView.js +1 -1
  25. package/lib/typescript/plugin/build/withMapbox.d.ts +1 -6
  26. package/lib/typescript/plugin/build/withMapbox.d.ts.map +1 -1
  27. package/lib/typescript/src/RNMBXModule.d.ts +11 -1
  28. package/lib/typescript/src/RNMBXModule.d.ts.map +1 -1
  29. package/lib/typescript/src/components/MapView.d.ts +1 -1
  30. package/package.json +1 -1
  31. package/plugin/build/withMapbox.js +8 -8
  32. package/plugin/src/withMapbox.ts +8 -8
  33. package/src/RNMBXModule.ts +29 -3
  34. package/src/components/MapView.tsx +1 -1
  35. package/android/src/main/java/com/rnmapbox/rnmbx/utils/ConvertUtils.java +0 -253
  36. package/android/src/main/mapbox-v11-compat/v10/com/rnmapbox/rnmbx/v11compat/Layers.kt +0 -35
  37. package/android/src/main/mapbox-v11-compat/v11/com/rnmapbox/rnmbx/v11compat/Layers.kt +0 -1
@@ -937,7 +937,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
937
937
  }
938
938
 
939
939
  fun queryRenderedFeaturesInRect(rect: RectF?, filter: Expression?, layerIDs: List<String>?, response: CommandResponse) {
940
- val size = mMap!!.getMapOptions().size
940
+ val size = mMap.getMapOptions().size
941
941
  val screenBox = if (rect == null) ScreenBox(ScreenCoordinate(0.0, 0.0), ScreenCoordinate(size?.width!!.toDouble(), size?.height!!.toDouble())) else ScreenBox(
942
942
  ScreenCoordinate(rect.right.toDouble(), rect.bottom.toDouble() ),
943
943
  ScreenCoordinate(rect.left.toDouble(), rect.top.toDouble()),
@@ -962,7 +962,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
962
962
  }
963
963
 
964
964
  fun querySourceFeatures(sourceId: String, filter: Expression?, sourceLayerIDs: List<String>?, response: CommandResponse) {
965
- mMap?.querySourceFeatures(
965
+ mMap.querySourceFeatures(
966
966
  sourceId,
967
967
  SourceQueryOptions(sourceLayerIDs, (filter ?: Value.nullValue()) as Value),
968
968
  ) { features ->
@@ -982,7 +982,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
982
982
  }
983
983
 
984
984
  fun getVisibleBounds(response: CommandResponse) {
985
- val bounds = mMap!!.coordinateBoundsForCamera(mMap!!.cameraState.toCameraOptions())
985
+ val bounds = mMap.coordinateBoundsForCamera(mMap.cameraState.toCameraOptions())
986
986
 
987
987
  response.success {
988
988
  it.putArray("visibleBounds", bounds.toReadableArray())
@@ -1009,7 +1009,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
1009
1009
  }
1010
1010
 
1011
1011
  fun queryTerrainElevation(longitude: Double, latitude: Double, response: CommandResponse) {
1012
- val result = mMap?.getElevation(Point.fromLngLat(longitude, latitude))
1012
+ val result = mMap.getElevation(Point.fromLngLat(longitude, latitude))
1013
1013
 
1014
1014
  if (result != null) {
1015
1015
  response.success {
@@ -32,7 +32,7 @@ class RNMBXStyle(private val mContext: Context, reactStyle: ReadableMap?, map: M
32
32
  fun getStyleValueForKey(styleKey: String): RNMBXStyleValue {
33
33
  val styleValueConfig = mReactStyle!!.getMap(styleKey)
34
34
  if (styleValueConfig != null) {
35
- return RNMBXStyleValue(styleValueConfig)
35
+ return RNMBXStyleValue(styleKey, styleValueConfig)
36
36
  } else {
37
37
  Logger.e("RNMBXStyle", "Value for ${styleKey} not found")
38
38
  throw Exception("RNMBXStyle - Value for ${styleKey} not found")
@@ -28,7 +28,6 @@ import com.rnmapbox.rnmbx.utils.DownloadMapImageTask.OnAllImagesLoaded
28
28
  import com.rnmapbox.rnmbx.utils.Logger
29
29
 
30
30
  import com.rnmapbox.rnmbx.v11compat.light.*;
31
- import com.rnmapbox.rnmbx.v11compat.layers.*;
32
31
  import com.rnmapbox.rnmbx.v11compat.stylefactory.*;
33
32
 
34
33
  import java.util.List;
@@ -13,8 +13,9 @@ import com.rnmapbox.rnmbx.utils.ExpressionParser
13
13
  import com.rnmapbox.rnmbx.utils.Logger
14
14
  import java.util.ArrayList
15
15
 
16
- class RNMBXStyleValue(config: ReadableMap) {
16
+ class RNMBXStyleValue(key: String?, config: ReadableMap) {
17
17
  val type: String?
18
+ val key: String?
18
19
  private var isExpression = false
19
20
  private var mExpression: Expression? = null
20
21
  private val mPayload: ReadableMap?
@@ -202,6 +203,7 @@ class RNMBXStyleValue(config: ReadableMap) {
202
203
  }
203
204
 
204
205
  init {
206
+ this.key = key
205
207
  type = config.getString("styletype")
206
208
  mPayload = config.getMap("stylevalue")
207
209
  isAddImage = false
@@ -231,7 +233,9 @@ class RNMBXStyleValue(config: ReadableMap) {
231
233
  val dynamic = mPayload!!.getDynamic("value")
232
234
  if (isExpression(dynamic)) {
233
235
  isExpression = true
234
- mExpression = ExpressionParser.fromTyped(mPayload)
236
+ Logger.logged("$key ExpressionParser.fromTyped") {
237
+ mExpression = ExpressionParser.fromTyped(mPayload)
238
+ }
235
239
  }
236
240
  }
237
241
  }
@@ -1,36 +1,58 @@
1
1
  package com.rnmapbox.rnmbx.modules
2
2
 
3
3
  import com.mapbox.common.*
4
-
5
4
  import com.rnmapbox.rnmbx.v11compat.httpinterceptor.*
6
5
 
6
+ data class CustomHttpHeadersOptions(val urlRegexp: Regex?)
7
+
8
+ data class CustomHttpHeadersMapValue(
9
+ val headerValue: String,
10
+ val options: CustomHttpHeadersOptions?
11
+ )
12
+
7
13
  object CustomHttpHeaders : HttpServiceBase() {
14
+ const val LOG_TAG = "CustomHttpHeaders"
15
+
8
16
  init {}
9
17
 
10
- val map = mutableMapOf<String, String>()
18
+ val map = mutableMapOf<String, CustomHttpHeadersMapValue>()
11
19
 
12
- fun addCustomHeader(headerName: String, headerValue: String) {
20
+ fun addCustomHeader(headerName: String, headerValue: String, options: CustomHttpHeadersOptions? = null) {
13
21
  HttpServiceFactory.getInstance().setInterceptor(
14
22
  this
15
23
  )
16
- map.put(headerName, headerValue)
24
+ map.put(headerName, CustomHttpHeadersMapValue(headerValue = headerValue, options = options))
17
25
  }
18
26
 
19
27
  fun removeCustomHeader(headerName: String) {
20
28
  map.remove(headerName)
21
29
  }
22
30
 
23
- override fun onRequest(request: HttpRequest): HttpRequest {
31
+ fun getCustomRequestHeaders(customRequestHeaders: MutableMap<String, CustomHttpHeadersMapValue>, httpRequest: HttpRequest): HashMap<String, String> {
32
+ val headers = hashMapOf<String, String>()
24
33
  for (entry in map.entries.iterator()) {
25
- request.headers[entry.key] = entry.value
34
+ val urlRegexp = entry.value.options?.urlRegexp
35
+ if (urlRegexp != null) {
36
+ val destination = httpRequest.headers.getOrDefault("location", httpRequest.url)
37
+ if (urlRegexp.matches(destination)) {
38
+ headers[entry.key] = entry.value.headerValue
39
+ }
40
+ }
41
+ else {
42
+ headers[entry.key] = entry.value.headerValue
43
+ }
26
44
  }
45
+ return headers
46
+ }
47
+
48
+ override fun onRequest(request: HttpRequest): HttpRequest {
49
+ request.headers.remove("Authorization")
50
+ request.headers.putAll(getCustomRequestHeaders(map, request))
27
51
  return request
28
52
  }
29
53
 
30
54
  override fun onDownload(download: DownloadOptions): DownloadOptions {
31
- for (entry in map.entries.iterator()) {
32
- download.request.headers[entry.key] = entry.value
33
- }
55
+ download.request.headers.putAll(getCustomRequestHeaders(map, download.request))
34
56
  return download
35
57
  }
36
58
 
@@ -1,6 +1,7 @@
1
1
  package com.rnmapbox.rnmbx.modules
2
2
 
3
3
  import android.os.Handler
4
+ import androidx.annotation.Nullable
4
5
  import com.facebook.react.bridge.Promise
5
6
  import com.mapbox.maps.extension.style.layers.properties.generated.LineJoin
6
7
  import com.facebook.react.module.annotations.ReactModule
@@ -11,6 +12,8 @@ import com.rnmapbox.rnmbx.events.constants.EventTypes
11
12
  import com.rnmapbox.rnmbx.modules.RNMBXOfflineModule
12
13
  import com.rnmapbox.rnmbx.modules.RNMBXLocationModule
13
14
  import com.facebook.react.bridge.ReactMethod
15
+ import com.facebook.react.bridge.ReadableMap
16
+ import com.facebook.react.bridge.buildReadableMap
14
17
  import com.facebook.react.common.MapBuilder
15
18
  import com.mapbox.bindgen.None
16
19
  import com.mapbox.common.*
@@ -24,6 +27,7 @@ import java.util.HashMap
24
27
 
25
28
  import com.rnmapbox.rnmbx.v11compat.resourceoption.*
26
29
  import com.rnmapbox.rnmbx.v11compat.mapboxmap.*
30
+ import java.util.regex.PatternSyntaxException
27
31
 
28
32
  @ReactModule(name = RNMBXModule.REACT_CLASS)
29
33
  class RNMBXModule(private val mReactContext: ReactApplicationContext) : ReactContextBaseJavaModule(
@@ -165,7 +169,17 @@ class RNMBXModule(private val mReactContext: ReactApplicationContext) : ReactCon
165
169
 
166
170
  @ReactMethod
167
171
  fun addCustomHeader(headerName: String, headerValue: String) {
168
- CustomHttpHeaders.addCustomHeader(headerName, headerValue)
172
+ addCustomHeaderWithOptions(headerName, headerValue)
173
+ }
174
+
175
+ @ReactMethod
176
+ fun addCustomHeaderWithOptions(headerName: String, headerValue: String, options: ReadableMap? = buildReadableMap { }) {
177
+ try {
178
+ val urlRegexp = options?.getString("urlRegexp")?.toRegex()
179
+ CustomHttpHeaders.addCustomHeader(headerName, headerValue, CustomHttpHeadersOptions(urlRegexp = urlRegexp))
180
+ } catch (e: PatternSyntaxException) {
181
+ Logger.e(CustomHttpHeaders.LOG_TAG, e.localizedMessage ?: "Error converting ${options?.getString("urlRegexp")} to regex")
182
+ }
169
183
  }
170
184
 
171
185
  @ReactMethod
@@ -0,0 +1,239 @@
1
+ package com.rnmapbox.rnmbx.utils
2
+
3
+ import android.graphics.PointF
4
+ import android.graphics.RectF
5
+ import android.util.Log
6
+ import com.facebook.react.bridge.Arguments
7
+ import com.facebook.react.bridge.NoSuchKeyException
8
+ import com.facebook.react.bridge.ReadableArray
9
+ import com.facebook.react.bridge.ReadableMap
10
+ import com.facebook.react.bridge.ReadableType
11
+ import com.facebook.react.bridge.WritableArray
12
+ import com.facebook.react.bridge.WritableMap
13
+ import com.google.gson.JsonArray
14
+ import com.google.gson.JsonElement
15
+ import com.google.gson.JsonObject
16
+ import com.google.gson.JsonPrimitive
17
+ import java.text.NumberFormat
18
+ import java.text.ParseException
19
+
20
+ object ConvertUtils {
21
+ const val LOG_TAG: String = "ConvertUtils"
22
+
23
+ fun toJsonObject(map: ReadableMap?): JsonObject? {
24
+ if (map == null) return null
25
+ val result = JsonObject()
26
+ val it = map.keySetIterator()
27
+
28
+ while (it.hasNextKey()) {
29
+ val key = it.nextKey()
30
+ when (map.getType(key)) {
31
+ ReadableType.Map -> result.add(key, toJsonObject(map.getMap(key)))
32
+ ReadableType.Array -> result.add(key, toJsonArray(map.getArray(key)))
33
+ ReadableType.Null -> result.add(key, null)
34
+ ReadableType.Number -> result.addProperty(key, map.getDouble(key))
35
+ ReadableType.String -> result.addProperty(key, map.getString(key))
36
+ ReadableType.Boolean -> result.addProperty(key, map.getBoolean(key))
37
+ }
38
+ }
39
+ return result
40
+ }
41
+
42
+ @JvmStatic
43
+ fun toJsonArray(array: ReadableArray?): JsonArray? {
44
+ if (array == null) return null
45
+ val result = JsonArray(array.size())
46
+ for (i in 0..<array.size()) {
47
+ when (array.getType(i)) {
48
+ ReadableType.Map -> result.add(toJsonObject(array.getMap(i)))
49
+ ReadableType.Array -> result.add(toJsonArray(array.getArray(i)))
50
+ ReadableType.Null -> result.add(null as JsonElement?)
51
+ ReadableType.Number -> result.add(array.getDouble(i))
52
+ ReadableType.String -> result.add(array.getString(i))
53
+ ReadableType.Boolean -> result.add(array.getBoolean(i))
54
+ }
55
+ }
56
+ return result
57
+ }
58
+
59
+ @JvmStatic
60
+ fun typedToJsonElement(map: ReadableMap?): JsonElement? {
61
+ if (map == null) return null
62
+
63
+ val type = map.getString("type")
64
+
65
+ if (type == ExpressionParser.TYPE_MAP) {
66
+ val result = JsonObject()
67
+
68
+ val keyValues = map.getArray("value")
69
+ for (i in 0..<keyValues!!.size()) {
70
+ val keyValue = keyValues.getArray(i)
71
+ val key = keyValue!!.getMap(0)!!.getString("value")
72
+
73
+ result.add(key, typedToJsonElement(keyValue.getMap(1)))
74
+ }
75
+ return result
76
+ } else if (type == ExpressionParser.TYPE_ARRAY) {
77
+ val arrayValue = map.getArray("value")
78
+ val result = JsonArray(arrayValue!!.size())
79
+ for (i in 0..<arrayValue.size()) {
80
+ result.add(typedToJsonElement(arrayValue.getMap(i)))
81
+ }
82
+ return result
83
+ } else if (type == ExpressionParser.TYPE_BOOL) {
84
+ return JsonPrimitive(map.getBoolean("value"))
85
+ } else if (type == ExpressionParser.TYPE_NUMBER) {
86
+ return JsonPrimitive(map.getDouble("value"))
87
+ } else if (type == ExpressionParser.TYPE_STRING) {
88
+ return JsonPrimitive(map.getString("value"))
89
+ } else {
90
+ throw RuntimeException(String.format("Unrecognized type {}", map.getString("type")))
91
+ }
92
+ }
93
+
94
+ fun toWritableArray(array: JsonArray): WritableArray {
95
+ val writableArray = Arguments.createArray()
96
+
97
+ for (i in 0..<array.size()) {
98
+ val element = array.get(i)
99
+
100
+ if (element.isJsonArray()) {
101
+ writableArray.pushArray(toWritableArray(element.getAsJsonArray()))
102
+ } else if (element.isJsonObject()) {
103
+ writableArray.pushMap(toWritableMap(element.getAsJsonObject()))
104
+ } else if (element.isJsonPrimitive()) {
105
+ val primitive = element.getAsJsonPrimitive()
106
+
107
+ if (primitive.isBoolean()) {
108
+ writableArray.pushBoolean(primitive.getAsBoolean())
109
+ } else if (primitive.isNumber()) {
110
+ writableArray.pushDouble(primitive.getAsDouble())
111
+ } else {
112
+ writableArray.pushString(primitive.getAsString())
113
+ }
114
+ }
115
+ }
116
+
117
+ return writableArray
118
+ }
119
+
120
+ fun toWritableMap(inObject: JsonObject): WritableMap {
121
+ val map = Arguments.createMap()
122
+
123
+ for (entry in inObject.entrySet()) {
124
+ val propName = entry.key
125
+ val jsonElement = entry.value
126
+
127
+ if (jsonElement.isJsonPrimitive()) {
128
+ val primitive = jsonElement.getAsJsonPrimitive()
129
+
130
+ if (primitive.isBoolean()) {
131
+ map.putBoolean(propName, primitive.getAsBoolean())
132
+ } else if (primitive.isNumber()) {
133
+ map.putDouble(propName, primitive.getAsDouble())
134
+ } else {
135
+ map.putString(propName, primitive.getAsString())
136
+ }
137
+ } else if (jsonElement.isJsonArray()) {
138
+ map.putArray(propName, toWritableArray(jsonElement.getAsJsonArray()))
139
+ } else if (jsonElement.isJsonObject()) {
140
+ map.putMap(propName, toWritableMap(jsonElement.getAsJsonObject()))
141
+ }
142
+ }
143
+
144
+ return map
145
+ }
146
+
147
+ fun getObjectFromString(str: String): Any? {
148
+ val numberFormat = NumberFormat.getNumberInstance()
149
+
150
+ try {
151
+ return numberFormat.parse(str)
152
+ } catch (e: ParseException) {
153
+ // ignore we're just figuring out what type this is
154
+ }
155
+
156
+ return str
157
+ }
158
+
159
+ fun toStringList(array: ReadableArray?): MutableList<String> {
160
+ val list: MutableList<String> = ArrayList<String>()
161
+
162
+ if (array == null) {
163
+ return list
164
+ }
165
+
166
+ for (i in 0..<array.size()) {
167
+ array.getString(i)?.let {
168
+ list.add(it)
169
+ }
170
+ }
171
+
172
+ return list
173
+ }
174
+
175
+ fun toPointF(array: ReadableArray?): PointF {
176
+ val pointF = PointF()
177
+
178
+ if (array == null) {
179
+ return pointF
180
+ }
181
+
182
+ pointF.set(array.getDouble(0).toFloat(), array.getDouble(1).toFloat())
183
+ return pointF
184
+ }
185
+
186
+ // returns null if array is null
187
+ fun toRectF(array: ReadableArray?): RectF? {
188
+ val rectF = RectF()
189
+
190
+ if (array == null || array.size() == 0) {
191
+ return null
192
+ }
193
+
194
+ rectF.set(
195
+ array.getDouble(3).toFloat(),
196
+ array.getDouble(0).toFloat(),
197
+ array.getDouble(1).toFloat(),
198
+ array.getDouble(2).toFloat()
199
+ )
200
+ return rectF
201
+ }
202
+
203
+ fun getDouble(key: String, map: ReadableMap, defaultValue: Double): Double {
204
+ var value = defaultValue
205
+
206
+ try {
207
+ value = map.getDouble(key)
208
+ } catch (e: NoSuchKeyException) {
209
+ // key not found use default value
210
+ Log.d(
211
+ LOG_TAG,
212
+ String.format("No key found for %s, using default value %f", key, defaultValue)
213
+ )
214
+ }
215
+
216
+ return value
217
+ }
218
+
219
+ fun getString(key: String, map: ReadableMap, defaultValue: String): String {
220
+ var value = defaultValue
221
+
222
+ try {
223
+ map.getString(key)?.let {
224
+ value = it
225
+ } ?: run {
226
+ Log.d(LOG_TAG, String.format("key %s is null, using default value %s", key, defaultValue))
227
+ // value is already defaultValue
228
+ }
229
+ } catch (e: NoSuchKeyException) {
230
+ // key not found use default value
231
+ Log.d(
232
+ LOG_TAG,
233
+ String.format("No key found for %s, using default value %s", key, defaultValue)
234
+ )
235
+ }
236
+
237
+ return value
238
+ }
239
+ }
@@ -30,8 +30,11 @@ object GeoJSONUtils {
30
30
  "GeoJSONUtils.fromFeature geometry was null for feature: ${feature.toJson()}"
31
31
  )
32
32
  }
33
- val properties = ConvertUtils.toWritableMap(feature.properties())
34
- map.putMap("properties", properties)
33
+
34
+ feature.properties()?.let {
35
+ val properties = ConvertUtils.toWritableMap(it)
36
+ map.putMap("properties", properties)
37
+ }
35
38
  return map
36
39
  }
37
40
 
@@ -733,3 +733,32 @@ class BackgroundPitchAlignment {
733
733
  companion object
734
734
  }
735
735
 
736
+ fun FillExtrusionLayer.fillExtrusionEdgeRadius(
737
+ expression: Expression
738
+ ) {
739
+ // V11 only
740
+ }
741
+
742
+ fun FillExtrusionLayer.fillExtrusionEdgeRadius(
743
+ value: Double
744
+ ) {
745
+ // V11 only
746
+ }
747
+
748
+ fun FillExtrusionLayer.fillExtrusionEmissiveStrength(
749
+ expression: Expression
750
+ ) {
751
+ // V11 only
752
+ }
753
+
754
+ fun FillExtrusionLayer.fillExtrusionEmissiveStrength(
755
+ value: Double
756
+ ) {
757
+ // V11 only
758
+ }
759
+
760
+ fun FillExtrusionLayer.fillExtrusionEmissiveStrengthTransition(
761
+ transition: StyleTransition
762
+ ) {
763
+ // V11 only
764
+ }
@@ -27,7 +27,7 @@ class RNMBXStyleValueTest {
27
27
  fun `getEnumName returns correct enum name`() {
28
28
  Mockito.`when`(mockPayload.getString("value")).thenReturn("test-value")
29
29
 
30
- val styleValue = RNMBXStyleValue(mockConfig)
30
+ val styleValue = RNMBXStyleValue('foo', mockConfig)
31
31
 
32
32
  assertEquals("TEST_VALUE", styleValue.getEnumName())
33
33
  }
@@ -36,7 +36,7 @@ class RNMBXStyleValueTest {
36
36
  fun `getEnumName handles Turkish locale correctly`() {
37
37
  Mockito.`when`(mockPayload.getString("value")).thenReturn("miter")
38
38
 
39
- val styleValue = RNMBXStyleValue(mockConfig)
39
+ val styleValue = RNMBXStyleValue('foo', mockConfig)
40
40
 
41
41
  Locale.setDefault(Locale("tr", "TR"))
42
42
 
@@ -1,5 +1,14 @@
1
1
  import MapboxMaps
2
2
 
3
+ struct CustomHttpHeadersOptions {
4
+ var urlRegexp: NSRegularExpression?
5
+ }
6
+
7
+ struct CustomHttpHeadersMapValue {
8
+ var headerValue: String
9
+ var options: CustomHttpHeadersOptions
10
+ }
11
+
3
12
  class CustomHttpHeaders : HttpServiceInterceptorInterface {
4
13
  #if RNMBX_11
5
14
  func onRequest(for request: HttpRequest, continuation: @escaping HttpServiceInterceptorRequestContinuation) {
@@ -18,7 +27,7 @@ class CustomHttpHeaders : HttpServiceInterceptorInterface {
18
27
  return headers
19
28
  }()
20
29
 
21
- var customHeaders : [String:String] = [:]
30
+ var customHeaders : [String:CustomHttpHeadersMapValue] = [:]
22
31
 
23
32
  func install() {
24
33
  #if RNMBX_11
@@ -38,19 +47,39 @@ class CustomHttpHeaders : HttpServiceInterceptorInterface {
38
47
  }
39
48
 
40
49
  // MARK: - HttpServiceInterceptorInterface
50
+
51
+ func getCustomRequestHeaders(for request: HttpRequest, with customHeaders: [String: CustomHttpHeadersMapValue]) -> [String: String] {
52
+ var headers: [String: String] = [:]
53
+ let urlString = request.url
41
54
 
42
- func onRequest(for request: HttpRequest) -> HttpRequest {
43
- customHeaders.forEach {(key, value) in
44
- request.headers[key] = value
55
+ for (key, entry) in customHeaders {
56
+ let options = entry.options
57
+
58
+ if let pattern = options.urlRegexp {
59
+ do {
60
+ let range = NSRange(location: 0, length: urlString.utf16.count)
61
+ if pattern.firstMatch(in: urlString, options: [], range: range) != nil {
62
+ headers[key] = entry.headerValue
63
+ }
64
+ }
65
+ } else {
66
+ headers[key] = entry.headerValue
67
+ }
45
68
  }
69
+ return headers
70
+ }
71
+
72
+
73
+ func onRequest(for request: HttpRequest) -> HttpRequest {
74
+ let customHeaders = getCustomRequestHeaders(for: request, with: customHeaders)
75
+ request.headers.merge(customHeaders) { (_, new) in new }
46
76
  return request
47
77
  }
48
78
 
49
79
  #if !RNMBX_11
50
80
  func onDownload(forDownload download: DownloadOptions) -> DownloadOptions {
51
- customHeaders.forEach {(key,value) in
52
- download.request.headers[key] = value
53
- }
81
+ let customHeaders = getCustomRequestHeaders(for: download.request, with: customHeaders)
82
+ download.request.headers.merge(customHeaders) { (_, new) in new }
54
83
  return download
55
84
  }
56
85
  #endif
@@ -36,7 +36,9 @@ public class RNMBXCustomLocationProvider: UIView, RNMBXMapComponent {
36
36
 
37
37
  @objc
38
38
  override public func didSetProps(_ props: [String]) {
39
- changes.apply(self)
39
+ if customLocationProvider != nil {
40
+ changes.apply(self)
41
+ }
40
42
  }
41
43
 
42
44
  var customLocationProvider: CustomLocationProvider? = nil
@@ -49,6 +51,7 @@ public class RNMBXCustomLocationProvider: UIView, RNMBXMapComponent {
49
51
  self.map = map
50
52
  if let mapView = map.mapView {
51
53
  installCustomeLocationProviderIfNeeded(mapView: mapView)
54
+ changes.apply(self)
52
55
  }
53
56
  }
54
57
 
@@ -12,6 +12,8 @@
12
12
  #import <react/renderer/components/rnmapbox_maps_specs/Props.h>
13
13
  #import <react/renderer/components/rnmapbox_maps_specs/RCTComponentViewHelpers.h>
14
14
 
15
+ #import "RNMBXFabricPropConvert.h"
16
+
15
17
  using namespace facebook::react;
16
18
 
17
19
  @interface RNMBXCustomLocationProviderComponentView () <RCTRNMBXCustomLocationProviderViewProtocol>
@@ -30,7 +32,7 @@ using namespace facebook::react;
30
32
  - (instancetype)initWithFrame:(CGRect)frame
31
33
  {
32
34
  if (self = [super initWithFrame:frame]) {
33
- static const auto defaultProps = std::make_shared<const RNMBXCircleLayerProps>();
35
+ static const auto defaultProps = std::make_shared<const RNMBXCustomLocationProviderProps>();
34
36
  _props = defaultProps;
35
37
  [self prepareView];
36
38
  }
@@ -49,12 +51,20 @@ using namespace facebook::react;
49
51
 
50
52
  + (ComponentDescriptorProvider)componentDescriptorProvider
51
53
  {
52
- return concreteComponentDescriptorProvider<RNMBXCircleLayerComponentDescriptor>();
54
+ return concreteComponentDescriptorProvider<RNMBXCustomLocationProviderComponentDescriptor>();
53
55
  }
54
56
 
55
57
  - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
56
58
  {
59
+ const auto &oldViewProps = static_cast<const RNMBXCustomLocationProviderProps &>(*oldProps);
60
+ const auto &newViewProps = static_cast<const RNMBXCustomLocationProviderProps &>(*props);
61
+
62
+ RNMBX_OPTIONAL_PROP_NumberArray(coordinate)
63
+ RNMBX_OPTIONAL_PROP_NSNumber(heading)
64
+
57
65
  [super updateProps:props oldProps:oldProps];
66
+
67
+ [_view didSetProps:@[]];
58
68
  }
59
69
 
60
70
  - (void)prepareForRecycle
@@ -13,6 +13,7 @@ NSNumber* RNMBXPropConvert_Optional_BOOL_NSNumber(const folly::dynamic &dyn, NSS
13
13
  BOOL RNMBXPropConvert_Optional_BOOL(const folly::dynamic &dyn, NSString* propertyName);
14
14
  NSString* RNMBXPropConvert_Optional_NSString(const folly::dynamic &dyn, NSString* propertyName);
15
15
  NSNumber* RNMBXPropConvert_Optional_NSNumber(const folly::dynamic &dyn, NSString* propertyName);
16
+ NSArray<NSNumber*>* RNMBXPropConvert_Optional_NumberArray(const folly::dynamic &dyn, NSString* propertyName);
16
17
  id RNMBXPropConvert_Optional_ExpressionDouble(const folly::dynamic &dyn, NSString* propertyName);
17
18
  BOOL RNMBXPropConvert_BOOL(const folly::dynamic &dyn, NSString* propertyName);
18
19
  NSDictionary* RNMBXPropConvert_Optional_NSDictionary(const folly::dynamic &dyn, NSString* propertyName);
@@ -27,6 +28,11 @@ NSDictionary* RNMBXPropConvert_Optional_NSDictionary(const folly::dynamic &dyn,
27
28
  _view.viewName = RNMBXPropConvert_Optional_BOOL(newViewProps.name, @#name); \
28
29
  }
29
30
 
31
+ #define RNMBX_REMAP_OPTIONAL_PROP_NSDictionary(name, viewName) \
32
+ if ((!oldProps.get() || oldViewProps.name != newViewProps.name)) { \
33
+ _view.viewName = RNMBXPropConvert_Optional_NSDictionary(newViewProps.name, @#name); \
34
+ }
35
+
30
36
  #define RNMBX_OPTIONAL_PROP_BOOL(name) RNMBX_REMAP_OPTIONAL_PROP_BOOL(name, name)
31
37
 
32
38
  #define RNMBX_OPTIONAL_PROP_NSString(name) \
@@ -34,6 +40,11 @@ NSDictionary* RNMBXPropConvert_Optional_NSDictionary(const folly::dynamic &dyn,
34
40
  _view.name = RNMBXPropConvert_Optional_NSString(newViewProps.name, @#name); \
35
41
  }
36
42
 
43
+ #define RNMBX_OPTIONAL_PROP_NumberArray(name) \
44
+ if ((!oldProps.get() || oldViewProps.name != newViewProps.name) && !newViewProps.name.isNull()) { \
45
+ _view.name = RNMBXPropConvert_Optional_NumberArray(newViewProps.name, @#name); \
46
+ }
47
+
37
48
  #define RNMBX_OPTIONAL_PROP_NSNumber(name) \
38
49
  if ((!oldProps.get() || oldViewProps.name != newViewProps.name) && !newViewProps.name.isNull()) { \
39
50
  _view.name = RNMBXPropConvert_Optional_NSNumber(newViewProps.name, @#name); \
@@ -49,7 +60,4 @@ NSDictionary* RNMBXPropConvert_Optional_NSDictionary(const folly::dynamic &dyn,
49
60
  _view.name = RNMBXPropConvert_BOOL(newViewProps.name, @#name); \
50
61
  }
51
62
 
52
- #define RNMBX_OPTIONAL_PROP_NSDictionary(name) \
53
- if ((!oldProps.get() || oldViewProps.name != newViewProps.name)) { \
54
- _view.name = RNMBXPropConvert_Optional_NSDictionary(newViewProps.name, @#name); \
55
- }
63
+ #define RNMBX_OPTIONAL_PROP_NSDictionary(name) RNMBX_REMAP_OPTIONAL_PROP_NSDictionary(name, name)
@@ -153,4 +153,8 @@ NSDictionary* RNMBXPropConvert_Optional_NSDictionary(const folly::dynamic &dyn,
153
153
  return RNMBXPropConvert_ID(dyn);
154
154
  }
155
155
 
156
+ NSArray<NSNumber*> * RNMBXPropConvert_Optional_NumberArray(const folly::dynamic &dyn, NSString* propertyName) {
157
+ return RNMBXPropConvert_ID(dyn);
158
+ }
159
+
156
160
  #endif