Add pointer interaction to avatar in timeline status cell
This commit is contained in:
parent
d95ba82e5b
commit
43aee0ec67
|
@ -54,6 +54,7 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
|
||||||
$0.isUserInteractionEnabled = true
|
$0.isUserInteractionEnabled = true
|
||||||
$0.addInteraction(UIContextMenuInteraction(delegate: self))
|
$0.addInteraction(UIContextMenuInteraction(delegate: self))
|
||||||
$0.addInteraction(UIDragInteraction(delegate: self))
|
$0.addInteraction(UIDragInteraction(delegate: self))
|
||||||
|
$0.addInteraction(UIPointerInteraction(delegate: self))
|
||||||
$0.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed)))
|
$0.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,6 +216,10 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
|
||||||
$0.addInteraction(UIPointerInteraction(delegate: self))
|
$0.addInteraction(UIPointerInteraction(delegate: self))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var actionButtons: [UIButton] {
|
||||||
|
[replyButton, favoriteButton, reblogButton, moreButton]
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Cell state
|
// MARK: Cell state
|
||||||
|
|
||||||
private var mainContainerTopToReblogLabelConstraint: NSLayoutConstraint!
|
private var mainContainerTopToReblogLabelConstraint: NSLayoutConstraint!
|
||||||
|
@ -619,21 +624,28 @@ extension TimelineStatusCollectionViewCell: UIDragInteractionDelegate {
|
||||||
|
|
||||||
extension TimelineStatusCollectionViewCell: UIPointerInteractionDelegate {
|
extension TimelineStatusCollectionViewCell: UIPointerInteractionDelegate {
|
||||||
func pointerInteraction(_ interaction: UIPointerInteraction, regionFor request: UIPointerRegionRequest, defaultRegion: UIPointerRegion) -> UIPointerRegion? {
|
func pointerInteraction(_ interaction: UIPointerInteraction, regionFor request: UIPointerRegionRequest, defaultRegion: UIPointerRegion) -> UIPointerRegion? {
|
||||||
guard let button = interaction.view as? UIButton else {
|
if interaction.view === avatarImageView {
|
||||||
return nil
|
return defaultRegion
|
||||||
|
} else if let button = interaction.view as? UIButton,
|
||||||
|
actionButtons.contains(button) {
|
||||||
|
var rect = button.convert(button.imageView!.bounds, from: button.imageView!)
|
||||||
|
rect = rect.insetBy(dx: -24, dy: -24)
|
||||||
|
return UIPointerRegion(rect: rect)
|
||||||
}
|
}
|
||||||
var rect = button.convert(button.imageView!.bounds, from: button.imageView!)
|
return nil
|
||||||
rect = rect.insetBy(dx: -24, dy: -24)
|
|
||||||
return UIPointerRegion(rect: rect)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
|
func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
|
||||||
guard let button = interaction.view as? UIButton else {
|
if interaction.view === avatarImageView {
|
||||||
return nil
|
let preview = UITargetedPreview(view: avatarImageView)
|
||||||
|
return UIPointerStyle(effect: .lift(preview))
|
||||||
|
} else if let button = interaction.view as? UIButton,
|
||||||
|
actionButtons.contains(button) {
|
||||||
|
let preview = UITargetedPreview(view: button.imageView!)
|
||||||
|
var rect = button.convert(button.imageView!.bounds, from: button.imageView!)
|
||||||
|
rect = rect.insetBy(dx: -8, dy: -8)
|
||||||
|
return UIPointerStyle(effect: .highlight(preview), shape: .roundedRect(rect))
|
||||||
}
|
}
|
||||||
let preview = UITargetedPreview(view: button.imageView!)
|
return nil
|
||||||
var rect = button.convert(button.imageView!.bounds, from: button.imageView!)
|
|
||||||
rect = rect.insetBy(dx: -8, dy: -8)
|
|
||||||
return UIPointerStyle(effect: .highlight(preview), shape: .roundedRect(rect))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue