From 91b7ce3008ead2f32573f92c83cbe0ce995811ad Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 1 Jan 2023 12:35:40 -0500 Subject: [PATCH] Add pointer interaction to ToastView --- Tusker/Views/Toast/ToastView.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Tusker/Views/Toast/ToastView.swift b/Tusker/Views/Toast/ToastView.swift index a0aae067..4410ecbf 100644 --- a/Tusker/Views/Toast/ToastView.swift +++ b/Tusker/Views/Toast/ToastView.swift @@ -53,6 +53,8 @@ class ToastView: UIView { layer.shadowOpacity = 0.5 layer.masksToBounds = false + addInteraction(UIPointerInteraction(delegate: self)) + let stack = UIStackView() stack.translatesAutoresizingMaskIntoConstraints = false stack.axis = .horizontal @@ -282,3 +284,21 @@ extension ToastView: UIGestureRecognizerDelegate { return true } } + +extension ToastView: UIPointerInteractionDelegate { + func pointerInteraction(_ interaction: UIPointerInteraction, regionFor request: UIPointerRegionRequest, defaultRegion: UIPointerRegion) -> UIPointerRegion? { + return defaultRegion + } + + func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? { + return UIPointerStyle(effect: .highlight(UITargetedPreview(view: self))) + } + + func pointerInteraction(_ interaction: UIPointerInteraction, willEnter region: UIPointerRegion, animator: UIPointerInteractionAnimating) { + shouldDismissAutomatically = false + } + + func pointerInteraction(_ interaction: UIPointerInteraction, willExit region: UIPointerRegion, animator: UIPointerInteractionAnimating) { + shouldDismissAutomatically = true + } +}