@rnmapbox/maps 10.0.0-beta.45 → 10.0.0-beta.46

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.
@@ -0,0 +1,38 @@
1
+ package com.mapbox.rctmgl.modules
2
+
3
+ import com.mapbox.common.*
4
+
5
+ object CustomHttpHeaders : HttpServiceInterceptorInterface {
6
+ init {}
7
+
8
+ val map = mutableMapOf<String, String>()
9
+
10
+ fun addCustomHeader(headerName: String, headerValue: String) {
11
+ HttpServiceFactory.getInstance().setInterceptor(
12
+ this
13
+ )
14
+ }
15
+
16
+ fun removeCustomHeader(headerName: String) {
17
+ map.remove(headerName)
18
+ }
19
+
20
+ override fun onRequest(request: HttpRequest): HttpRequest {
21
+ for (entry in map.entries.iterator()) {
22
+ request.headers[entry.key] = entry.value
23
+ }
24
+ return request
25
+ }
26
+
27
+ override fun onDownload(download: DownloadOptions): DownloadOptions {
28
+ for (entry in map.entries.iterator()) {
29
+ download.request.headers[entry.key] = entry.value
30
+ }
31
+ return download
32
+ }
33
+
34
+ override fun onResponse(response: HttpResponse): HttpResponse {
35
+ return response
36
+ }
37
+ }
38
+
@@ -12,6 +12,7 @@ import com.mapbox.rctmgl.modules.RCTMGLOfflineModule
12
12
  import com.mapbox.rctmgl.modules.RCTMGLLocationModule
13
13
  import com.facebook.react.bridge.ReactMethod
14
14
  import com.facebook.react.common.MapBuilder
15
+ import com.mapbox.common.*
15
16
  import com.mapbox.maps.Style
16
17
  import com.mapbox.rctmgl.components.camera.constants.CameraMode
17
18
  import java.util.HashMap
@@ -124,6 +125,16 @@ class RCTMGLModule(private val mReactContext: ReactApplicationContext) : ReactCo
124
125
  // NO-OP
125
126
  }
126
127
 
128
+ @ReactMethod
129
+ fun addCustomHeader(headerName: String, headerValue: String) {
130
+ CustomHttpHeaders.addCustomHeader(headerName, headerValue)
131
+ }
132
+
133
+ @ReactMethod
134
+ fun removeCustomHeader(headerName: String) {
135
+ CustomHttpHeaders.removeCustomHeader(headerName)
136
+ }
137
+
127
138
  companion object {
128
139
  const val REACT_CLASS = "RCTMGLModule"
129
140
  private val customHeaderInterceptorAdded = false
@@ -132,4 +143,4 @@ class RCTMGLModule(private val mReactContext: ReactApplicationContext) : ReactCo
132
143
  return getDefault((reactContext)!!, null).resourceOptions.accessToken
133
144
  }
134
145
  }
135
- }
146
+ }
@@ -4,6 +4,8 @@ import MapKit
4
4
 
5
5
  @objc(RCTMGLMapView)
6
6
  open class RCTMGLMapView : MapView {
7
+ var tapDelegate: IgnoreRCTMGLMakerViewGestureDelegate? = nil
8
+
7
9
  var compassEnabled: Bool = false
8
10
  var compassFadeWhenNorth: Bool = false
9
11
  var reactOnPress : RCTBubblingEventBlock?
@@ -420,12 +422,70 @@ extension RCTMGLMapView {
420
422
 
421
423
  // MARK: - gestures
422
424
 
425
+ class IgnoreRCTMGLMakerViewGestureDelegate : NSObject, UIGestureRecognizerDelegate {
426
+ var originalDelegate: UIGestureRecognizerDelegate?
427
+
428
+ init(originalDelegate: UIGestureRecognizerDelegate?) {
429
+ self.originalDelegate = originalDelegate
430
+ }
431
+
432
+ func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
433
+ return originalDelegate?.gestureRecognizerShouldBegin?(gestureRecognizer) ?? true
434
+ }
435
+
436
+ func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
437
+ return originalDelegate?.gestureRecognizer?(gestureRecognizer,shouldRecognizeSimultaneouslyWith: otherGestureRecognizer) ?? false
438
+ }
439
+
440
+ func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool {
441
+ return originalDelegate?.gestureRecognizer?(gestureRecognizer,shouldRequireFailureOf: otherGestureRecognizer) ?? false
442
+ }
443
+
444
+ func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {
445
+ return originalDelegate?.gestureRecognizer?(gestureRecognizer,shouldBeRequiredToFailBy: otherGestureRecognizer) ?? false
446
+ }
447
+
448
+ private func isMarkerViewSubview(_ view: UIView) -> Bool {
449
+ var current : UIView? = view
450
+ while let act = current {
451
+ if (act is RCTMGLMarkerView) {
452
+ return true
453
+ }
454
+ current = act.superview
455
+ }
456
+ return false
457
+ }
458
+
459
+ func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
460
+ if let view = touch.view, isMarkerViewSubview(view) {
461
+ return false
462
+ }
463
+ return originalDelegate?.gestureRecognizer?(gestureRecognizer,shouldReceive: touch) ?? true
464
+ }
465
+
466
+ func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive press: UIPress) -> Bool {
467
+ return originalDelegate?.gestureRecognizer?(gestureRecognizer,shouldReceive: press) ?? true
468
+ }
469
+
470
+
471
+ @available(iOS 13.4, *)
472
+ func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive event: UIEvent) -> Bool {
473
+ return originalDelegate?.gestureRecognizer?(gestureRecognizer,shouldReceive: event) ?? true
474
+ }
475
+ }
476
+
423
477
  extension RCTMGLMapView {
478
+
424
479
  @objc func setReactOnPress(_ value: @escaping RCTBubblingEventBlock) {
425
480
  self.reactOnPress = value
426
-
427
- self.mapView.gestures.singleTapGestureRecognizer.removeTarget( pointAnnotationManager.manager, action: nil)
428
- self.mapView.gestures.singleTapGestureRecognizer.addTarget(self, action: #selector(doHandleTap(_:)))
481
+
482
+ let singleTapGestureRecognizer = self.mapView.gestures.singleTapGestureRecognizer
483
+
484
+ singleTapGestureRecognizer.removeTarget(pointAnnotationManager.manager, action: nil)
485
+ singleTapGestureRecognizer.addTarget(self, action: #selector(doHandleTap(_:)))
486
+
487
+ self.tapDelegate = IgnoreRCTMGLMakerViewGestureDelegate(originalDelegate: singleTapGestureRecognizer.delegate)
488
+ singleTapGestureRecognizer.delegate = tapDelegate
429
489
  }
430
490
 
431
491
  @objc func setReactOnLongPress(_ value: @escaping RCTBubblingEventBlock) {
@@ -673,6 +733,11 @@ class PointAnnotationManager : AnnotationInteractionDelegate {
673
733
  private var draggedAnnotation: PointAnnotation?
674
734
 
675
735
  func annotationManager(_ manager: AnnotationManager, didDetectTappedAnnotations annotations: [Annotation]) {
736
+ // We handle taps ourselfs
737
+ // onTap(annotations: annotations)
738
+ }
739
+
740
+ func onTap(annotations: [Annotation]) {
676
741
  guard annotations.count > 0 else {
677
742
  fatalError("didDetectTappedAnnotations: No annotations found")
678
743
  }
@@ -724,7 +789,7 @@ class PointAnnotationManager : AnnotationInteractionDelegate {
724
789
  }
725
790
  let options = RenderedQueryOptions(layerIds: [layerId], filter: nil)
726
791
  mapFeatureQueryable.queryRenderedFeatures(
727
- at: tap.location(in: tap.view),
792
+ with: tap.location(in: tap.view),
728
793
  options: options) { [weak self] (result) in
729
794
 
730
795
  guard let self = self else { return }
@@ -746,10 +811,7 @@ class PointAnnotationManager : AnnotationInteractionDelegate {
746
811
 
747
812
  // If `tappedAnnotations` is not empty, call delegate
748
813
  if !tappedAnnotations.isEmpty {
749
- self.annotationManager(
750
- self.manager,
751
- didDetectTappedAnnotations: tappedAnnotations)
752
-
814
+ self.onTap(annotations: tappedAnnotations)
753
815
  } else {
754
816
  noAnnotationFound(tap)
755
817
  }
@@ -757,7 +819,6 @@ class PointAnnotationManager : AnnotationInteractionDelegate {
757
819
  case .failure(let error):
758
820
  noAnnotationFound(tap)
759
821
  Logger.log(level:.warn, message:"Failed to query map for annotations due to error: \(error)")
760
-
761
822
  }
762
823
  }
763
824
  }
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.0.0-beta.45",
4
+ "version": "10.0.0-beta.46",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },