Skip to content

Commit

Permalink
Fixed an issue of content taps being cancelled by the drawer tap reco…
Browse files Browse the repository at this point in the history
…gnisers.
  • Loading branch information
andersio committed Apr 6, 2018
1 parent 6856c2e commit bda2f00
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ extension PresentationController {
self.currentDrawerCornerRadius = 0
}

self.lastDrawerState = endingState

AnimationSupport.clientCleanupViews(presentingDrawerAnimationActions: presentingAnimationActions,
presentedDrawerAnimationActions: presentedAnimationActions,
endingPosition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
11 changes: 8 additions & 3 deletions DrawerKit/DrawerKit/Internal API/PresentationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
}
Expand All @@ -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)
Expand Down
16 changes: 4 additions & 12 deletions DrawerKitDemo/DrawerKitDemoUITests/DrawerKitDemoUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bda2f00

Please sign in to comment.