diff --git a/DrawerKit/DrawerKit/Internal API/PresentationController+Gestures.swift b/DrawerKit/DrawerKit/Internal API/PresentationController+Gestures.swift index 452db63..778b5ef 100644 --- a/DrawerKit/DrawerKit/Internal API/PresentationController+Gestures.swift +++ b/DrawerKit/DrawerKit/Internal API/PresentationController+Gestures.swift @@ -52,3 +52,15 @@ extension PresentationController { } } } + +extension PresentationController: UIGestureRecognizerDelegate { + func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { + if let view = gestureRecognizer.view, + view.isDescendant(of: presentedViewController.view), + let subview = view.hitTest(touch.location(in: view), with: nil) { + return !(subview is UIControl) + } else { + return true + } + } +} diff --git a/DrawerKit/DrawerKit/Internal API/PresentationController+Setup.swift b/DrawerKit/DrawerKit/Internal API/PresentationController+Setup.swift index 1babe42..befae3f 100644 --- a/DrawerKit/DrawerKit/Internal API/PresentationController+Setup.swift +++ b/DrawerKit/DrawerKit/Internal API/PresentationController+Setup.swift @@ -10,6 +10,10 @@ extension PresentationController { action: #selector(handleDrawerFullExpansionTap)) tapGesture.numberOfTouchesRequired = 1 tapGesture.numberOfTapsRequired = numTapsRequired + tapGesture.cancelsTouchesInView = false + tapGesture.delaysTouchesBegan = false + tapGesture.delaysTouchesEnded = false + tapGesture.delegate = self presentedView?.addGestureRecognizer(tapGesture) drawerFullExpansionTapGR = tapGesture } @@ -35,6 +39,10 @@ extension PresentationController { action: #selector(handleDrawerDismissalTap)) tapGesture.numberOfTouchesRequired = 1 tapGesture.numberOfTapsRequired = numTapsRequired + tapGesture.cancelsTouchesInView = false + tapGesture.delaysTouchesBegan = false + tapGesture.delaysTouchesEnded = false + tapGesture.delegate = self containerView?.addGestureRecognizer(tapGesture) drawerDismissalTapGR = tapGesture } diff --git a/DrawerKit/DrawerKit/Internal API/PresentationController.swift b/DrawerKit/DrawerKit/Internal API/PresentationController.swift index 1d841e8..d050a4d 100644 --- a/DrawerKit/DrawerKit/Internal API/PresentationController.swift +++ b/DrawerKit/DrawerKit/Internal API/PresentationController.swift @@ -14,7 +14,12 @@ final class PresentationController: UIPresentationController { /// The target state of the drawer. If no presentation animation is in /// progress, the value should be equivalent to `currentDrawerState`. - var targetDrawerState: DrawerState + var targetDrawerState: DrawerState { + didSet { + drawerDismissalTapGR?.isEnabled = targetDrawerState == .partiallyExpanded + drawerFullExpansionTapGR?.isEnabled = targetDrawerState == .partiallyExpanded + } + } var startingDrawerStateForDrag: DrawerState? @@ -29,9 +34,6 @@ final class PresentationController: UIPresentationController { self.handleView = (configuration.handleViewConfiguration != nil ? UIView() : nil) self.presentingDrawerAnimationActions = presentingDrawerAnimationActions self.presentedDrawerAnimationActions = presentedDrawerAnimationActions - - // NOTE: Set the current drawer state to the target state of the initial - // presentation animation. self.targetDrawerState = configuration.supportsPartialExpansion ? .partiallyExpanded : .fullyExpanded super.init(presentedViewController: presentedVC, presenting: presentingVC)