From 4e105e0fbc1f475530c23135fb112cfd8cbd8985 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 26 Apr 2022 13:29:22 -0400 Subject: [PATCH] Fix table view cell gesture blocking toast long-press Fixes #149 --- Tusker/Views/Toast/ToastView.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Tusker/Views/Toast/ToastView.swift b/Tusker/Views/Toast/ToastView.swift index c38cd1fb..86834be4 100644 --- a/Tusker/Views/Toast/ToastView.swift +++ b/Tusker/Views/Toast/ToastView.swift @@ -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 + } +}