@rnmapbox/maps 10.1.42 → 10.1.43

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 (42) hide show
  1. package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt +40 -0
  2. package/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt +65 -0
  3. package/android/src/main/java/com/rnmapbox/rnmbx/utils/extensions/Map.kt +11 -0
  4. package/android/src/main/java/com/rnmapbox/rnmbx/utils/writeableMapArrayOf.kt +35 -0
  5. package/android/src/main/mapbox-v11-compat/v10/com/rnmapbox/rnmbx/v11compat/MapboxMap.kt +26 -1
  6. package/android/src/main/mapbox-v11-compat/v11/com/rnmapbox/rnmbx/v11compat/MapboxMap.kt +28 -1
  7. package/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeMapViewModuleSpec.java +13 -0
  8. package/ios/RNMBX/RNMBXCameraViewManager.m +3 -0
  9. package/ios/RNMBX/RNMBXCameraViewManager.swift +10 -8
  10. package/ios/RNMBX/RNMBXCircleLayerComponentView.mm +1 -1
  11. package/ios/RNMBX/RNMBXCircleLayerViewManager.m +2 -0
  12. package/ios/RNMBX/RNMBXCircleLayerViewManager.swift +2 -0
  13. package/ios/RNMBX/RNMBXMapViewManager.m +2 -0
  14. package/ios/RNMBX/RNMBXMapViewManager.swift +321 -178
  15. package/ios/RNMBX/RNMBXMapViewModule.h +3 -2
  16. package/ios/RNMBX/RNMBXMapViewModule.mm +28 -19
  17. package/ios/RNMBX/RNMBXShapeSourceViewManager.m +2 -0
  18. package/ios/RNMBX/RNMBXShapeSourceViewManager.swift +52 -47
  19. package/ios/RNMBX/ShapeAnimators/RNMBXMovePointShapeAnimatorModule.mm +2 -2
  20. package/ios/RNMBX/ShapeAnimators/RNMBXMovePointShapeAnimatorModule.swift +1 -1
  21. package/ios/RNMBX/Utils/RNMBXViewResolver.h +45 -0
  22. package/ios/RNMBX/Utils/RNMBXViewResolver.mm +134 -0
  23. package/lib/commonjs/components/Images.js +1 -1
  24. package/lib/commonjs/components/Images.js.map +1 -1
  25. package/lib/commonjs/components/MapView.js +60 -3
  26. package/lib/commonjs/components/MapView.js.map +1 -1
  27. package/lib/commonjs/specs/NativeMapViewModule.js.map +1 -1
  28. package/lib/module/components/Images.js +1 -1
  29. package/lib/module/components/Images.js.map +1 -1
  30. package/lib/module/components/MapView.js +59 -2
  31. package/lib/module/components/MapView.js.map +1 -1
  32. package/lib/module/specs/NativeMapViewModule.js.map +1 -1
  33. package/lib/typescript/src/components/MapView.d.ts +35 -0
  34. package/lib/typescript/src/components/MapView.d.ts.map +1 -1
  35. package/lib/typescript/src/specs/NativeMapViewModule.d.ts +3 -0
  36. package/lib/typescript/src/specs/NativeMapViewModule.d.ts.map +1 -1
  37. package/package.json +133 -2
  38. package/rnmapbox-maps.podspec +2 -1
  39. package/setup-jest.js +3 -0
  40. package/src/components/Images.tsx +1 -1
  41. package/src/components/MapView.tsx +92 -2
  42. package/src/specs/NativeMapViewModule.ts +20 -0
@@ -3,6 +3,7 @@ package com.rnmapbox.rnmbx.components.mapview
3
3
  import com.facebook.react.bridge.Promise
4
4
  import com.facebook.react.bridge.ReactApplicationContext
5
5
  import com.facebook.react.bridge.ReadableArray
6
+ import com.facebook.react.bridge.ReadableMap
6
7
  import com.facebook.react.bridge.WritableMap
7
8
  import com.facebook.react.bridge.WritableNativeMap
8
9
  import com.rnmapbox.rnmbx.NativeMapViewModuleSpec
@@ -12,6 +13,7 @@ import com.rnmapbox.rnmbx.utils.ViewRefTag
12
13
  import com.rnmapbox.rnmbx.utils.ViewTagResolver
13
14
  import com.rnmapbox.rnmbx.utils.extensions.toCoordinate
14
15
  import com.rnmapbox.rnmbx.utils.extensions.toScreenCoordinate
16
+ import com.rnmapbox.rnmbx.utils.extensions.toValueHashMap
15
17
 
16
18
  class NativeMapViewModule(context: ReactApplicationContext, val viewTagResolver: ViewTagResolver) : NativeMapViewModuleSpec(context) {
17
19
  private fun withMapViewOnUIThread(
@@ -158,6 +160,44 @@ class NativeMapViewModule(context: ReactApplicationContext, val viewTagResolver:
158
160
  }
159
161
  }
160
162
 
163
+ override fun setFeatureState(
164
+ viewRef: ViewRefTag?,
165
+ featureId: String,
166
+ state: ReadableMap,
167
+ sourceId: String,
168
+ sourceLayerId: String?,
169
+ promise: Promise
170
+ ) {
171
+ withMapViewOnUIThread(viewRef, promise) {
172
+ it.setFeatureState(featureId, state.toValueHashMap(), sourceId, sourceLayerId, createCommandResponse(promise))
173
+ }
174
+ }
175
+
176
+ override fun getFeatureState(
177
+ viewRef: ViewRefTag?,
178
+ featureId: String,
179
+ sourceId: String,
180
+ sourceLayerId: String?,
181
+ promise: Promise
182
+ ) {
183
+ withMapViewOnUIThread(viewRef, promise) {
184
+ it.getFeatureState(featureId, sourceId, sourceLayerId, createCommandResponse(promise))
185
+ }
186
+ }
187
+
188
+ override fun removeFeatureState(
189
+ viewRef: ViewRefTag?,
190
+ featureId: String,
191
+ stateKey: String?,
192
+ sourceId: String,
193
+ sourceLayerId: String?,
194
+ promise: Promise
195
+ ) {
196
+ withMapViewOnUIThread(viewRef, promise) {
197
+ it.removeFeatureState(featureId, stateKey, sourceId, sourceLayerId, createCommandResponse(promise))
198
+ }
199
+ }
200
+
161
201
  override fun querySourceFeatures(
162
202
  viewRef: ViewRefTag?,
163
203
  sourceId: String,
@@ -65,6 +65,7 @@ import java.util.*
65
65
 
66
66
  import com.rnmapbox.rnmbx.components.annotation.RNMBXPointAnnotationCoordinator
67
67
  import com.rnmapbox.rnmbx.components.images.ImageManager
68
+ import com.rnmapbox.rnmbx.utils.extensions.toStringKeyPairs
68
69
 
69
70
  import com.rnmapbox.rnmbx.v11compat.event.*
70
71
  import com.rnmapbox.rnmbx.v11compat.feature.*
@@ -1027,6 +1028,70 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie
1027
1028
  }
1028
1029
  }
1029
1030
 
1031
+ fun setFeatureState(
1032
+ featureId: String,
1033
+ state: HashMap<String, Value>,
1034
+ sourceId: String,
1035
+ sourceLayerId: String?,
1036
+ response: CommandResponse
1037
+ ) {
1038
+ mapView.getMapboxMap().setFeatureStateCompat(
1039
+ sourceId,
1040
+ sourceLayerId,
1041
+ featureId,
1042
+ Value.valueOf(state)
1043
+ ) { expected ->
1044
+ if (expected.isError()) {
1045
+ response.error(expected.error!!.toString())
1046
+ } else {
1047
+ response.success { }
1048
+ }
1049
+ }
1050
+ }
1051
+
1052
+ fun getFeatureState(
1053
+ featureId: String,
1054
+ sourceId: String,
1055
+ sourceLayerId: String?,
1056
+ response: CommandResponse
1057
+ ) {
1058
+ mapView.getMapboxMap().getFeatureState(sourceId, sourceLayerId, featureId) { expected ->
1059
+ if (expected.isValue) {
1060
+ response.success {
1061
+ val state = expected.value?.contents;
1062
+ if (state is Map<*,*>) {
1063
+ it.putMap("featureState", writableMapOf(*state.toStringKeyPairs()))
1064
+ } else {
1065
+ it.putMap("featureState", Arguments.createMap())
1066
+ }
1067
+ }
1068
+ } else {
1069
+ response.error(expected.error ?: "Unknown error")
1070
+ }
1071
+ }
1072
+ }
1073
+
1074
+ fun removeFeatureState(
1075
+ featureId: String,
1076
+ stateKey: String?,
1077
+ sourceId: String,
1078
+ sourceLayerId: String?,
1079
+ response: CommandResponse
1080
+ ) {
1081
+ mapView.getMapboxMap().removeFeatureStateCompat(
1082
+ sourceId,
1083
+ sourceLayerId,
1084
+ featureId,
1085
+ stateKey
1086
+ ) { expected ->
1087
+ if (expected.isError()) {
1088
+ response.error(expected.error?.toString() ?: "Unknown error")
1089
+ } else {
1090
+ response.success { }
1091
+ }
1092
+ }
1093
+ }
1094
+
1030
1095
  fun match(layer: Layer, sourceId:String, sourceLayerId: String?) : Boolean {
1031
1096
  fun match(actSourceId: String, actSourceLayerId: String?) : Boolean {
1032
1097
  return (actSourceId == sourceId && ((sourceLayerId == null) || (sourceLayerId == actSourceLayerId)))
@@ -0,0 +1,11 @@
1
+ package com.rnmapbox.rnmbx.utils.extensions
2
+
3
+ fun Map<*, *>.toStringKeyPairs(): Array<Pair<String, *>> {
4
+ return this.entries.fold(mutableListOf<Pair<String, *>>()) { acc, (key, value) ->
5
+ acc.apply {
6
+ if (key is String) {
7
+ add(key to value)
8
+ }
9
+ }
10
+ }.toTypedArray()
11
+ }
@@ -3,6 +3,9 @@ package com.rnmapbox.rnmbx.utils
3
3
  import com.facebook.react.bridge.Arguments
4
4
  import com.facebook.react.bridge.WritableArray
5
5
  import com.facebook.react.bridge.WritableMap
6
+ import com.mapbox.bindgen.Value
7
+ import com.rnmapbox.rnmbx.utils.extensions.toStringKeyPairs
8
+
6
9
 
7
10
  fun writableMapOf(vararg values: Pair<String, *>): WritableMap {
8
11
  val map = Arguments.createMap()
@@ -14,8 +17,23 @@ fun writableMapOf(vararg values: Pair<String, *>): WritableMap {
14
17
  is Int -> map.putInt(key, value)
15
18
  is Long -> map.putInt(key, value.toInt())
16
19
  is String -> map.putString(key, value)
20
+ is Map<*,*> -> map.putMap(key, writableMapOf(*value.toStringKeyPairs()))
21
+ is Array<*> -> map.putArray(key, writableArrayOf(*value.map{ it as Any }.toTypedArray()))
17
22
  is WritableMap -> map.putMap(key, value)
18
23
  is WritableArray -> map.putArray(key, value)
24
+ is Value -> {
25
+ val contents = value.contents
26
+ when (contents) {
27
+ null -> map.putNull(key)
28
+ is Boolean -> map.putBoolean(key, contents)
29
+ is Double -> map.putDouble(key, contents)
30
+ is Int -> map.putInt(key, contents)
31
+ is Long -> map.putInt(key, contents.toInt())
32
+ is String -> map.putString(key, contents)
33
+ is WritableMap -> map.putMap(key, contents)
34
+ is WritableArray -> map.putArray(key, contents)
35
+ }
36
+ }
19
37
  else -> throw IllegalArgumentException("Unsupported value type ${value::class.java.name} for key [$key]")
20
38
  }
21
39
  }
@@ -32,8 +50,25 @@ fun writableArrayOf(vararg values: Any): WritableArray {
32
50
  is Int -> array.pushInt(value)
33
51
  is Long -> array.pushInt(value.toInt())
34
52
  is String -> array.pushString(value)
53
+ is Map<*,*> -> array.pushMap(writableMapOf(*value.toStringKeyPairs()))
54
+ is Array<*> -> array.pushArray(writableArrayOf(*value.map{ it as Any }.toTypedArray()))
35
55
  is WritableMap -> array.pushMap(value)
36
56
  is WritableArray -> array.pushArray(value)
57
+ is Value -> {
58
+ val contents = value.contents
59
+ when (contents) {
60
+ null -> array.pushNull()
61
+ is Boolean -> array.pushBoolean(contents)
62
+ is Double -> array.pushDouble(contents)
63
+ is Int -> array.pushInt(contents)
64
+ is Long -> array.pushInt(contents.toInt())
65
+ is String -> array.pushString(contents)
66
+ is Map<*,*> -> array.pushMap(writableMapOf(*contents.toStringKeyPairs()))
67
+ is Array<*> -> array.pushArray(writableArrayOf(*contents.map{ it as Any }.toTypedArray()))
68
+ is WritableMap -> array.pushMap(contents)
69
+ is WritableArray -> array.pushArray(contents)
70
+ }
71
+ }
37
72
  else -> throw IllegalArgumentException("Unsupported value type ${value::class.java.name}")
38
73
  }
39
74
  }
@@ -1,4 +1,5 @@
1
- package com.rnmapbox.rnmbx.v11compat.mapboxmap;
1
+
2
+ package com.rnmapbox.rnmbx.v11compat.mapboxmap
2
3
 
3
4
  import android.animation.Animator
4
5
  import android.app.Activity
@@ -6,7 +7,9 @@ import android.content.Context
6
7
  import android.content.ContextWrapper
7
8
  import androidx.activity.result.contract.ActivityResultContracts
8
9
  import com.mapbox.bindgen.Expected
10
+ import com.mapbox.bindgen.ExpectedFactory
9
11
  import com.mapbox.bindgen.None
12
+ import com.mapbox.bindgen.Value
10
13
  import com.mapbox.maps.CameraOptions
11
14
  import com.mapbox.maps.MapView
12
15
  import com.mapbox.maps.MapboxMap
@@ -14,6 +17,28 @@ import com.mapbox.maps.plugin.animation.MapAnimationOptions
14
17
  import com.mapbox.maps.plugin.animation.easeTo
15
18
  import com.mapbox.maps.plugin.animation.flyTo
16
19
 
20
+ fun MapboxMap.setFeatureStateCompat(
21
+ sourceId: String,
22
+ sourceLayerId: String?,
23
+ featureId: String,
24
+ state: Value,
25
+ callback: (Expected<String, None>) -> Unit
26
+ ) {
27
+ this.setFeatureState(sourceId, sourceLayerId, featureId, state)
28
+ callback(ExpectedFactory.createNone<String>())
29
+ }
30
+
31
+ fun MapboxMap.removeFeatureStateCompat(
32
+ sourceId: String,
33
+ sourceLayerId: String?,
34
+ featureId: String,
35
+ stateKey: String?,
36
+ callback: (Expected<String, None>) -> Unit
37
+ ) {
38
+ this.removeFeatureState(sourceId, sourceLayerId, featureId, stateKey)
39
+ callback(ExpectedFactory.createNone<String>())
40
+ }
41
+
17
42
  fun MapboxMap.flyToV11(
18
43
  cameraOptions: CameraOptions,
19
44
  animationOptions: MapAnimationOptions.Builder,
@@ -2,6 +2,9 @@ package com.rnmapbox.rnmbx.v11compat.mapboxmap
2
2
 
3
3
  import android.animation.Animator
4
4
  import android.content.Context
5
+ import com.mapbox.bindgen.Value
6
+ import com.mapbox.bindgen.Expected
7
+ import com.mapbox.bindgen.None
5
8
  import com.mapbox.maps.AsyncOperationResultCallback
6
9
  import com.mapbox.maps.CameraOptions
7
10
  import com.mapbox.maps.MapboxMap
@@ -9,6 +12,30 @@ import com.mapbox.maps.plugin.animation.MapAnimationOptions
9
12
  import com.mapbox.maps.plugin.animation.easeTo
10
13
  import com.mapbox.maps.plugin.animation.flyTo
11
14
 
15
+ fun MapboxMap.setFeatureStateCompat(
16
+ sourceId: String,
17
+ sourceLayerId: String?,
18
+ featureId: String,
19
+ state: Value,
20
+ callback: (Expected<String, None>) -> Unit
21
+ ) {
22
+ this.setFeatureState(sourceId, sourceLayerId, featureId, state) { _ ->
23
+ callback(com.mapbox.bindgen.ExpectedFactory.createNone<String>())
24
+ }
25
+ }
26
+
27
+ fun MapboxMap.removeFeatureStateCompat(
28
+ sourceId: String,
29
+ sourceLayerId: String?,
30
+ featureId: String,
31
+ stateKey: String?,
32
+ callback: (Expected<String, None>) -> Unit
33
+ ) {
34
+ this.removeFeatureState(sourceId, sourceLayerId, featureId, stateKey) { _ ->
35
+ callback(com.mapbox.bindgen.ExpectedFactory.createNone<String>())
36
+ }
37
+ }
38
+
12
39
  fun MapboxMap.flyToV11(
13
40
  cameraOptions: CameraOptions,
14
41
  animationOptions: MapAnimationOptions.Builder,
@@ -39,4 +66,4 @@ fun MapboxMap.clearData(callback: AsyncOperationResultCallback) {
39
66
 
40
67
  fun MapboxMap.Companion.clearData(context: Context, callback: AsyncOperationResultCallback) {
41
68
  this.clearData(callback)
42
- }
69
+ }
@@ -19,6 +19,7 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
19
19
  import com.facebook.react.bridge.ReactMethod;
20
20
  import com.facebook.react.bridge.ReactModuleWithSpec;
21
21
  import com.facebook.react.bridge.ReadableArray;
22
+ import com.facebook.react.bridge.ReadableMap;
22
23
  import com.facebook.react.turbomodule.core.interfaces.TurboModule;
23
24
  import javax.annotation.Nonnull;
24
25
  import javax.annotation.Nullable;
@@ -86,4 +87,16 @@ public abstract class NativeMapViewModuleSpec extends ReactContextBaseJavaModule
86
87
  @ReactMethod
87
88
  @DoNotStrip
88
89
  public abstract void querySourceFeatures(@Nullable Double viewRef, String sourceId, ReadableArray withFilter, ReadableArray withSourceLayerIDs, Promise promise);
90
+
91
+ @ReactMethod
92
+ @DoNotStrip
93
+ public abstract void setFeatureState(@Nullable Double viewRef, String featureId, ReadableMap state, String sourceId, @Nullable String sourceLayerId, Promise promise);
94
+
95
+ @ReactMethod
96
+ @DoNotStrip
97
+ public abstract void getFeatureState(@Nullable Double viewRef, String featureId, String sourceId, @Nullable String sourceLayerId, Promise promise);
98
+
99
+ @ReactMethod
100
+ @DoNotStrip
101
+ public abstract void removeFeatureState(@Nullable Double viewRef, String featureId, @Nullable String stateKey, String sourceId, @Nullable String sourceLayerId, Promise promise);
89
102
  }
@@ -1,3 +1,5 @@
1
+ #if !RCT_NEW_ARCH_ENABLED
2
+
1
3
  #import "React/RCTBridgeModule.h"
2
4
  #import <React/RCTViewManager.h>
3
5
  #import <Foundation/Foundation.h>
@@ -22,3 +24,4 @@ RCT_EXPORT_VIEW_PROPERTY(onUserTrackingModeChange, RCTBubblingEventBlock)
22
24
  RCT_EXPORT_VIEW_PROPERTY(stop, NSDictionary)
23
25
 
24
26
  @end
27
+ #endif
@@ -1,14 +1,16 @@
1
- import Foundation
2
- import MapboxMaps
1
+ #if !RCT_NEW_ARCH_ENABLED
2
+ import Foundation
3
+ import MapboxMaps
3
4
 
4
- @objc(RNMBXCameraViewManager)
5
- class RNMBXCameraViewManager : RCTViewManager {
5
+ @objc(RNMBXCameraViewManager)
6
+ class RNMBXCameraViewManager: RCTViewManager {
6
7
  @objc
7
8
  override static func requiresMainQueueSetup() -> Bool {
8
- return false
9
+ return false
9
10
  }
10
-
11
+
11
12
  override func view() -> UIView! {
12
- return RNMBXCamera()
13
+ return RNMBXCamera()
13
14
  }
14
- }
15
+ }
16
+ #endif
@@ -32,7 +32,7 @@ using namespace facebook::react;
32
32
  if (self = [super initWithFrame:frame]) {
33
33
  static const auto defaultProps = std::make_shared<const RNMBXCircleLayerProps>();
34
34
  _props = defaultProps;
35
- [self prepareView];
35
+ [self prepareView];
36
36
  }
37
37
 
38
38
  return self;
@@ -1,3 +1,4 @@
1
+ #if !RCT_NEW_ARCH_ENABLED
1
2
  #import <React/RCTBridgeModule.h>
2
3
  #import <React/RCTViewManager.h>
3
4
 
@@ -10,3 +11,4 @@ RCT_EXPORT_VIEW_PROPERTY(sourceLayerID, NSString)
10
11
  #include "CommonLayerProperties.H"
11
12
 
12
13
  @end
14
+ #endif
@@ -1,3 +1,4 @@
1
+ #if !RCT_NEW_ARCH_ENABLED
1
2
  @objc(RNMBXCircleLayerViewManager)
2
3
  class RNMBXCircleLayerViewManager: RCTViewManager {
3
4
  @objc
@@ -11,3 +12,4 @@ class RNMBXCircleLayerViewManager: RCTViewManager {
11
12
  return layer
12
13
  }
13
14
  }
15
+ #endif
@@ -1,3 +1,4 @@
1
+ #if !RCT_NEW_ARCH_ENABLED
1
2
  #import <React/RCTBridgeModule.h>
2
3
  #import <React/RCTViewManager.h>
3
4
 
@@ -41,3 +42,4 @@ RCT_REMAP_VIEW_PROPERTY(onMapChange, reactOnMapChange, RCTBubblingEventBlock)
41
42
  RCT_EXPORT_VIEW_PROPERTY(mapViewImpl, NSString)
42
43
 
43
44
  @end
45
+ #endif