Skip to content

Commit

Permalink
Prevent an UIScrollViewDelayedTouchesBeganGestureRecognizer failed
Browse files Browse the repository at this point in the history
It causes tableView(_:didSelectRowAt:) not being called on first tap
after an nimation. The change hasn't fixed the problem completely, but
it works better.
  • Loading branch information
scenee committed Apr 18, 2019
1 parent 7a51219 commit 9076ba8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Framework/Sources/FloatingPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ class FloatingPanel: NSObject, UIGestureRecognizerDelegate, UIScrollViewDelegate
let panGestureRecognizer: FloatingPanelPanGestureRecognizer
var isRemovalInteractionEnabled: Bool = false

fileprivate var animator: UIViewPropertyAnimator?
fileprivate var animator: UIViewPropertyAnimator? {
didSet {
// This prevents an unexpected UIScrollViewDelayedTouchesBeganGestureRecognizer
// failed as possible because it cauese tableView(_:didSelectRowAt:)
// not being called on first tap after an animation.
scrollView?.isUserInteractionEnabled = (animator == nil)
}
}

private var initialFrame: CGRect = .zero
private var initialTranslationY: CGFloat = 0
Expand Down Expand Up @@ -302,7 +309,7 @@ class FloatingPanel: NSObject, UIGestureRecognizerDelegate, UIScrollViewDelegate
// Prevent aborting the touch events when the animator is
// released almost at a target position. Because user expect to
// enable tap gestures at that position.
if fabs(surfaceView.frame.minY - layoutAdapter.topY) > 20.0 {
if fabs(surfaceView.frame.minY - layoutAdapter.topY) > 40.0 {
if animator.isInterruptible {
animator.stopAnimation(false)
animator.finishAnimation(at: .current)
Expand Down Expand Up @@ -640,6 +647,7 @@ class FloatingPanel: NSObject, UIGestureRecognizerDelegate, UIScrollViewDelegate

private func finishAnimation(at targetPosition: FloatingPanelPosition) {
log.debug("finishAnimation to \(targetPosition)")

self.isDecelerating = false
self.animator = nil

Expand Down

0 comments on commit 9076ba8

Please sign in to comment.