Skip to content

Commit c4c2a5c

Browse files
committed
Fix issue where drawer pan would interfere with horizontal gestures
1 parent 06dfa8f commit c4c2a5c

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

DrawerView/DrawerView.swift

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import UIKit
1010
import Dispatch
1111

12-
let LOGGING = false
12+
let LOGGING = true
1313

1414
let dateFormat = "yyyy-MM-dd hh:mm:ss.SSS"
1515
let dateFormatter: DateFormatter = {
@@ -1400,9 +1400,34 @@ private struct ChildScrollViewInfo {
14001400
extension DrawerView: UIGestureRecognizerDelegate {
14011401

14021402
override public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
1403-
if gestureRecognizer === panGestureRecognizer || gestureRecognizer === overlayTapRecognizer {
1403+
if gestureRecognizer === panGestureRecognizer {
1404+
guard enabled else { return false }
1405+
1406+
// Check if the pan gesture is primarily horizontal (like swipe-to-delete)
1407+
// If so, don't begin to allow those gestures to work
1408+
let translation = panGestureRecognizer.translation(in: self)
1409+
let velocity = panGestureRecognizer.velocity(in: self)
1410+
1411+
// If there's meaningful translation/velocity, check direction
1412+
if abs(translation.x) > 0 || abs(translation.y) > 0 {
1413+
let isHorizontal = abs(translation.x) > abs(translation.y)
1414+
if isHorizontal {
1415+
return false
1416+
}
1417+
} else if abs(velocity.x) > 0 || abs(velocity.y) > 0 {
1418+
let isHorizontal = abs(velocity.x) > abs(velocity.y)
1419+
if isHorizontal {
1420+
return false
1421+
}
1422+
}
1423+
1424+
return true
1425+
}
1426+
1427+
if gestureRecognizer === overlayTapRecognizer {
14041428
return enabled
14051429
}
1430+
14061431
return true
14071432
}
14081433

0 commit comments

Comments
 (0)