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. (#57)

* Fixed an issue of content taps being cancelled by the drawer tap recognisers.

* Address a PR comment.
  • Loading branch information
andersio authored and diegopetrucci committed Apr 6, 2018
1 parent d80f25a commit b3f0f95
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
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
10 changes: 6 additions & 4 deletions DrawerKit/DrawerKit/Internal API/PresentationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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)
Expand Down

0 comments on commit b3f0f95

Please sign in to comment.