forked from shadowfacts/Tusker
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!)
|
var rect = button.convert(button.imageView!.bounds, from: button.imageView!)
|
||||||
rect = rect.insetBy(dx: -24, dy: -24)
|
rect = rect.insetBy(dx: -24, dy: -24)
|
||||||
return UIPointerRegion(rect: rect)
|
return UIPointerRegion(rect: rect)
|
||||||
}
|
}
|
||||||
|
|
||||||
func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
|
|
||||||
guard let button = interaction.view as? UIButton else {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
|
||||||
|
if interaction.view === avatarImageView {
|
||||||
|
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!)
|
let preview = UITargetedPreview(view: button.imageView!)
|
||||||
var rect = button.convert(button.imageView!.bounds, from: button.imageView!)
|
var rect = button.convert(button.imageView!.bounds, from: button.imageView!)
|
||||||
rect = rect.insetBy(dx: -8, dy: -8)
|
rect = rect.insetBy(dx: -8, dy: -8)
|
||||||
return UIPointerStyle(effect: .highlight(preview), shape: .roundedRect(rect))
|
return UIPointerStyle(effect: .highlight(preview), shape: .roundedRect(rect))
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue