From 45b67129dc6b3cd7b64ac20ddef6b57f67d41210 Mon Sep 17 00:00:00 2001 From: Anders Ha Date: Thu, 5 Apr 2018 20:02:59 +0100 Subject: [PATCH 1/2] Fixed an issue of content taps being cancelled by the drawer tap recognisers. --- .../PresentationController+Animation.swift | 2 ++ .../PresentationController+Gestures.swift | 13 +++++++++++++ .../Internal API/PresentationController+Setup.swift | 8 ++++++++ .../Internal API/PresentationController.swift | 11 ++++++++--- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/DrawerKit/DrawerKit/Internal API/PresentationController+Animation.swift b/DrawerKit/DrawerKit/Internal API/PresentationController+Animation.swift index b6d2a9b..8a3e55d 100644 --- a/DrawerKit/DrawerKit/Internal API/PresentationController+Animation.swift +++ b/DrawerKit/DrawerKit/Internal API/PresentationController+Animation.swift @@ -85,6 +85,8 @@ extension PresentationController { self.currentDrawerCornerRadius = 0 } + self.lastDrawerState = endingState + AnimationSupport.clientCleanupViews(presentingDrawerAnimationActions: presentingAnimationActions, presentedDrawerAnimationActions: presentedAnimationActions, endingPosition, diff --git a/DrawerKit/DrawerKit/Internal API/PresentationController+Gestures.swift b/DrawerKit/DrawerKit/Internal API/PresentationController+Gestures.swift index 5d5dfb9..65e1a9c 100644 --- a/DrawerKit/DrawerKit/Internal API/PresentationController+Gestures.swift +++ b/DrawerKit/DrawerKit/Internal API/PresentationController+Gestures.swift @@ -56,3 +56,16 @@ 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), + subview is UIControl { + return false + } 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 47cf651..1f8eafd 100644 --- a/DrawerKit/DrawerKit/Internal API/PresentationController.swift +++ b/DrawerKit/DrawerKit/Internal API/PresentationController.swift @@ -11,7 +11,12 @@ final class PresentationController: UIPresentationController { var drawerFullExpansionTapGR: UITapGestureRecognizer? var drawerDismissalTapGR: UITapGestureRecognizer? var drawerDragGR: UIPanGestureRecognizer? - var lastDrawerState: DrawerState = .collapsed + var lastDrawerState: DrawerState { + didSet { + drawerDismissalTapGR?.isEnabled = lastDrawerState == .partiallyExpanded + drawerFullExpansionTapGR?.isEnabled = lastDrawerState == .partiallyExpanded + } + } init(presentingVC: UIViewController?, presentingDrawerAnimationActions: DrawerAnimationActions, @@ -24,6 +29,7 @@ final class PresentationController: UIPresentationController { self.handleView = (configuration.handleViewConfiguration != nil ? UIView() : nil) self.presentingDrawerAnimationActions = presentingDrawerAnimationActions self.presentedDrawerAnimationActions = presentedDrawerAnimationActions + self.lastDrawerState = configuration.supportsPartialExpansion ? .partiallyExpanded : .fullyExpanded super.init(presentedViewController: presentedVC, presenting: presentingVC) } } @@ -33,9 +39,8 @@ extension PresentationController { var frame: CGRect = .zero frame.size = size(forChildContentContainer: presentedViewController, withParentContainerSize: containerViewSize) - let state: DrawerState = (supportsPartialExpansion ? .partiallyExpanded : .fullyExpanded) let drawerFullY = configuration.fullExpansionBehaviour.drawerFullY - frame.origin.y = GeometryEvaluator.drawerPositionY(for: state, + frame.origin.y = GeometryEvaluator.drawerPositionY(for: lastDrawerState, drawerPartialHeight: drawerPartialHeight, containerViewHeight: containerViewHeight, drawerFullY: drawerFullY) From 9abfb76e46a3b9b29d315cf544ef42ab0c714f30 Mon Sep 17 00:00:00 2001 From: Anders Ha Date: Fri, 6 Apr 2018 15:03:46 +0100 Subject: [PATCH 2/2] Address a PR comment. --- .../Internal API/PresentationController+Gestures.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/DrawerKit/DrawerKit/Internal API/PresentationController+Gestures.swift b/DrawerKit/DrawerKit/Internal API/PresentationController+Gestures.swift index ab1e246..778b5ef 100644 --- a/DrawerKit/DrawerKit/Internal API/PresentationController+Gestures.swift +++ b/DrawerKit/DrawerKit/Internal API/PresentationController+Gestures.swift @@ -57,9 +57,8 @@ 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), - subview is UIControl { - return false + let subview = view.hitTest(touch.location(in: view), with: nil) { + return !(subview is UIControl) } else { return true }