forked from shadowfacts/Tusker
Improve pointer interaction on new status cell action buttons
Closes #195
This commit is contained in:
parent
b6d8232951
commit
d95ba82e5b
|
@ -194,21 +194,25 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
|
|||
private(set) lazy var replyButton = UIButton().configure {
|
||||
$0.setImage(UIImage(systemName: "arrowshape.turn.up.left.fill"), for: .normal)
|
||||
$0.addTarget(self, action: #selector(replyPressed), for: .touchUpInside)
|
||||
$0.addInteraction(UIPointerInteraction(delegate: self))
|
||||
}
|
||||
|
||||
private(set) lazy var favoriteButton = UIButton().configure {
|
||||
$0.setImage(UIImage(systemName: "star.fill"), for: .normal)
|
||||
$0.addTarget(self, action: #selector(favoritePressed), for: .touchUpInside)
|
||||
$0.addInteraction(UIPointerInteraction(delegate: self))
|
||||
}
|
||||
|
||||
private(set) lazy var reblogButton = UIButton().configure {
|
||||
$0.setImage(UIImage(systemName: "repeat"), for: .normal)
|
||||
$0.addTarget(self, action: #selector(reblogPressed), for: .touchUpInside)
|
||||
$0.addInteraction(UIPointerInteraction(delegate: self))
|
||||
}
|
||||
|
||||
let moreButton = UIButton().configure {
|
||||
private(set) lazy var moreButton = UIButton().configure {
|
||||
$0.setImage(UIImage(systemName: "ellipsis"), for: .normal)
|
||||
$0.showsMenuAsPrimaryAction = true
|
||||
$0.addInteraction(UIPointerInteraction(delegate: self))
|
||||
}
|
||||
|
||||
// MARK: Cell state
|
||||
|
@ -612,3 +616,24 @@ extension TimelineStatusCollectionViewCell: UIDragInteractionDelegate {
|
|||
return dragItemsForAccount()
|
||||
}
|
||||
}
|
||||
|
||||
extension TimelineStatusCollectionViewCell: UIPointerInteractionDelegate {
|
||||
func pointerInteraction(_ interaction: UIPointerInteraction, regionFor request: UIPointerRegionRequest, defaultRegion: UIPointerRegion) -> UIPointerRegion? {
|
||||
guard let button = interaction.view as? UIButton else {
|
||||
return nil
|
||||
}
|
||||
var rect = button.convert(button.imageView!.bounds, from: button.imageView!)
|
||||
rect = rect.insetBy(dx: -24, dy: -24)
|
||||
return UIPointerRegion(rect: rect)
|
||||
}
|
||||
|
||||
func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
|
||||
guard let button = interaction.view as? UIButton else {
|
||||
return nil
|
||||
}
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue