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 + } +}