Fix table view cell gesture blocking toast long-press

Fixes #149
This commit is contained in:
Shadowfacts 2022-04-26 13:29:22 -04:00
parent d2f1d78aa2
commit 4e105e0fbc
1 changed files with 12 additions and 2 deletions

View File

@ -12,6 +12,7 @@ class ToastView: UIView {
let configuration: ToastConfiguration
private var panRecognizer: UIPanGestureRecognizer!
private var shrinkAnimator: UIViewPropertyAnimator?
private var recognizedGesture = false
private var handledLongPress = false
@ -101,9 +102,10 @@ class ToastView: UIView {
stack.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -4),
])
let pan = UIPanGestureRecognizer(target: self, action: #selector(panRecognized))
addGestureRecognizer(pan)
panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(panRecognized))
addGestureRecognizer(panRecognizer)
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(longPressRecognized))
longPress.delegate = self
addGestureRecognizer(longPress)
}
@ -266,3 +268,11 @@ class ToastView: UIView {
}
}
extension ToastView: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {
// if another recognizer can recognize simulatenously (e.g., table view cell drag initiation) it should require the toast one to fail
// otherwise long-pressing on a toast results in the drag beginning instead
return true
}
}