Add pointer interaction to ToastView

This commit is contained in:
Shadowfacts 2023-01-01 12:35:40 -05:00
parent 4dca231a06
commit 91b7ce3008
1 changed files with 20 additions and 0 deletions

View File

@ -53,6 +53,8 @@ class ToastView: UIView {
layer.shadowOpacity = 0.5 layer.shadowOpacity = 0.5
layer.masksToBounds = false layer.masksToBounds = false
addInteraction(UIPointerInteraction(delegate: self))
let stack = UIStackView() let stack = UIStackView()
stack.translatesAutoresizingMaskIntoConstraints = false stack.translatesAutoresizingMaskIntoConstraints = false
stack.axis = .horizontal stack.axis = .horizontal
@ -282,3 +284,21 @@ extension ToastView: UIGestureRecognizerDelegate {
return true 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
}
}