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 5, 2018
1 parent 6856c2e commit f276167
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 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 @@ -2,19 +2,13 @@ import UIKit

extension PresentationController {
@objc func handleDrawerFullExpansionTap() {
guard let tapGesture = drawerFullExpansionTapGR else { return }
let tapY = tapGesture.location(in: presentedView).y
guard tapY < drawerPartialHeight else { return }
NotificationCenter.default.post(notification: DrawerNotification.drawerInteriorTapped)
animateTransition(to: .fullyExpanded)
}

@objc func handleDrawerDismissalTap() {
guard let tapGesture = drawerDismissalTapGR else { return }
let tapY = tapGesture.location(in: containerView).y
guard tapY < currentDrawerY else { return }
NotificationCenter.default.post(notification: DrawerNotification.drawerExteriorTapped)
tapGesture.isEnabled = false
drawerDismissalTapGR?.isEnabled = false
presentedViewController.dismiss(animated: true)
}

Expand Down Expand Up @@ -56,3 +50,19 @@ extension PresentationController {
}
}
}

extension PresentationController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
guard lastDrawerState == .partiallyExpanded else { return false }

if gestureRecognizer === drawerDismissalTapGR {
let tapY = gestureRecognizer.location(in: containerView).y
return tapY < currentDrawerY
} else if gestureRecognizer === drawerFullExpansionTapGR {
let tapY = gestureRecognizer.location(in: presentedView).y
return tapY < drawerPartialHeight
} else {
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extension PresentationController {
action: #selector(handleDrawerFullExpansionTap))
tapGesture.numberOfTouchesRequired = 1
tapGesture.numberOfTapsRequired = numTapsRequired
tapGesture.delegate = self
presentedView?.addGestureRecognizer(tapGesture)
drawerFullExpansionTapGR = tapGesture
}
Expand All @@ -35,6 +36,7 @@ extension PresentationController {
action: #selector(handleDrawerDismissalTap))
tapGesture.numberOfTouchesRequired = 1
tapGesture.numberOfTapsRequired = numTapsRequired
tapGesture.delegate = self
containerView?.addGestureRecognizer(tapGesture)
drawerDismissalTapGR = tapGesture
}
Expand Down
4 changes: 2 additions & 2 deletions DrawerKit/DrawerKit/Internal API/PresentationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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 +34,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

0 comments on commit f276167

Please sign in to comment.