Skip to content

Commit 2c5e7bb

Browse files
authored
[iOS] Fix onScroll being triggered only once at the end of pan gesture (#410)
* [iOS] Fix onScroll being triggered only once at the end of pan gesture * Add changelog entry
1 parent 177b7c6 commit 2c5e7bb

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Add `LogConfiguration` allowing to intercept logs produced by the plugin. Pass your custom `LogWriterBackend` to `LogConfiguration.registerLogWriterBackend()` to redirect logs produced by the mapping engine to your desired destination.
44
* Add `MapWidget.onResourceRequestListener` that can be used to subscribe to resource requests made by the map.
5+
* [iOS] Re-wire `MapWidget`'s `onScroll` event to be triggered whenever map is being panned instead of triggering it only after pan ends.
56

67
### 1.0.0-beta.3
78

ios/Classes/GesturesController.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,25 @@ class GesturesController: NSObject, FLT_SETTINGSGesturesSettingsInterface, UIGes
99
func gestureManager(_ gestureManager: MapboxMaps.GestureManager, didBegin gestureType: MapboxMaps.GestureType) {}
1010

1111
func gestureManager(_ gestureManager: MapboxMaps.GestureManager, didEnd gestureType: MapboxMaps.GestureType, willAnimate: Bool) {
12-
switch gestureType {
13-
case .pan:
14-
let point = Point(mapView.mapboxMap.coordinate(for: gestureManager.panGestureRecognizer.location(in: mapView)))
15-
self.onGestureListener?.onScroll(FLT_GESTURESScreenCoordinate.makeWith(x: point.coordinates.latitude, y: point.coordinates.longitude), completion: {_ in })
16-
case .singleTap:
17-
let point = Point(mapView.mapboxMap.coordinate(for: gestureManager.singleTapGestureRecognizer.location(in: mapView)))
18-
self.onGestureListener?.onTap(FLT_GESTURESScreenCoordinate.makeWith(x: point.coordinates.latitude, y: point.coordinates.longitude), completion: {_ in })
19-
default: break
12+
guard gestureType == .singleTap else {
13+
return
2014
}
15+
16+
let point = Point(mapView.mapboxMap.coordinate(for: gestureManager.singleTapGestureRecognizer.location(in: mapView)))
17+
self.onGestureListener?.onTap(FLT_GESTURESScreenCoordinate.makeWith(x: point.coordinates.latitude, y: point.coordinates.longitude), completion: {_ in })
2118
}
2219

2320
func gestureManager(_ gestureManager: MapboxMaps.GestureManager, didEndAnimatingFor gestureType: MapboxMaps.GestureType) {}
2421

22+
@objc private func onMapPan(_ sender: UIPanGestureRecognizer) {
23+
guard sender.state == .began || sender.state == .changed || sender.state == .ended else {
24+
return
25+
}
26+
27+
let point = Point(mapView.mapboxMap.coordinate(for: sender.location(in: mapView)))
28+
self.onGestureListener?.onScroll(FLT_GESTURESScreenCoordinate.makeWith(x: point.coordinates.latitude, y: point.coordinates.longitude), completion: {_ in })
29+
}
30+
2531
@objc private func onMapLongTap(_ sender: UITapGestureRecognizer) {
2632
guard sender.state == .ended else { return }
2733
let point = Point(mapView.mapboxMap.coordinate(for: sender.location(in: mapView)))
@@ -113,6 +119,7 @@ class GesturesController: NSObject, FLT_SETTINGSGesturesSettingsInterface, UIGes
113119
gestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(onMapLongTap))
114120
mapView.addGestureRecognizer(gestureRecognizer!)
115121
mapView.gestures.delegate = self
122+
mapView.gestures.panGestureRecognizer.addTarget(self, action: #selector(onMapPan))
116123
onGestureListener = FLT_GESTURESGestureListener(binaryMessenger: messenger)
117124
}
118125

@@ -124,7 +131,6 @@ class GesturesController: NSObject, FLT_SETTINGSGesturesSettingsInterface, UIGes
124131

125132
private var mapView: MapView
126133
private var gestureRecognizer: UIGestureRecognizer?
127-
private var cancelable: Cancelable?
128134

129135
init(withMapView mapView: MapView) {
130136
self.mapView = mapView

0 commit comments

Comments
 (0)