From bda2f00eec3cde69c40b89054fb0431bffc1acc1 Mon Sep 17 00:00:00 2001 From: Anders Ha Date: Thu, 5 Apr 2018 20:02:59 +0100 Subject: [PATCH] Fixed an issue of content taps being cancelled by the drawer tap recognisers. --- .../PresentationController+Animation.swift | 2 ++ .../PresentationController+Gestures.swift | 13 +++++++++++++ .../PresentationController+Setup.swift | 8 ++++++++ .../Internal API/PresentationController.swift | 11 ++++++++--- .../DrawerKitDemoUITests.swift | 16 ++++------------ 5 files changed, 35 insertions(+), 15 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..684d7bc 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) diff --git a/DrawerKitDemo/DrawerKitDemoUITests/DrawerKitDemoUITests.swift b/DrawerKitDemo/DrawerKitDemoUITests/DrawerKitDemoUITests.swift index bac09fc..3583430 100644 --- a/DrawerKitDemo/DrawerKitDemoUITests/DrawerKitDemoUITests.swift +++ b/DrawerKitDemo/DrawerKitDemoUITests/DrawerKitDemoUITests.swift @@ -81,21 +81,13 @@ class DrawerKitDemoUITests: XCTestCase { } private func isDrawerOpen() -> Bool { - let drawer = app.staticTexts[Identifiers.drawerTitle] - if tryWaitFor(element: drawer, withState: .exists) { - return drawer.isHittable - } else { - return false - } + let drawerTitle = app.staticTexts[Identifiers.drawerTitle] + return !tryWaitFor(element: drawerTitle, withState: .notexists, waiting: 1.0) } private func isDrawerFullyOpen() -> Bool { - let image = app.images[Identifiers.drawerImage] - if tryWaitFor(element: image, withState: .exists) { - return app.images[Identifiers.drawerImage].frame.origin.y < drawerY - } else { - return false - } + let drawerImage = app.images[Identifiers.drawerImage] + return !tryWaitFor(element: drawerImage, withState: .notexists, waiting: 1.0) } @discardableResult