Skip to content

Commit

Permalink
Fix case when the map is dragged inside scroll view (#2024)
Browse files Browse the repository at this point in the history
* Fix case when the map is dragged inside scroll view

* Add Example

* Fix grammar

Co-authored-by: Patrick Leonard <[email protected]>

---------

Co-authored-by: Patrick Leonard <[email protected]>
  • Loading branch information
aleksproger and pjleonard37 committed Feb 15, 2024
1 parent c00860c commit 4367c15
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Foundation
import SwiftUI
@_spi(Experimental) import MapboxMaps

@available(iOS 14.0, *)
struct MapScrollExample: View {
var body: some View {
List {
Section {
Text("Test Map behaviour inside scroll.")
.font(.title)
.bold()
}
Section {
Map(initialViewport: .followPuck(zoom: 18, bearing: .heading, pitch: 60)) {
Puck2D(bearing: .heading)
}.aspectRatio(1.0, contentMode: .fill)
}
}
}
}

@available(iOS 14.0, *)
struct MapScrollExample_Previews: PreviewProvider {
static var previews: some View {
MapScrollExample()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ extension PanGestureHandler: UIGestureRecognizerDelegate {
shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer
) -> Bool {
guard gestureRecognizer === self.gestureRecognizer else { return false }
guard gestureRecognizer.attachedToSameView(as: otherGestureRecognizer) else { return true }
/// The map can be used inside a scroll view which has it's own `PanGestureRecognizer` and they should be mutually exclusive.
/// This will introduce problems for client who are going to implement custom `DragGesture` in SwiftUI, but it's considered as rare case.
/// That's said`gestureRecognizer.attachedToSameView` check is skipped here.

switch otherGestureRecognizer {
case is UIRotationGestureRecognizer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,4 @@ final class PanGestureHandlerTests: XCTestCase {

panGestureHandler.assertNotRecognizedSimultaneously(gestureRecognizer, with: interruptingRecognizers)
}

func testPinchShouldRecognizeSimultaneouslyWithAnyRecognizerAttachedToDifferentView() {
panGestureHandler.assertRecognizedSimultaneously(gestureRecognizer, with: interruptingRecognizers)
}
}

0 comments on commit 4367c15

Please sign in to comment.