Add pointer interaction for timeline header button. Issue #1943
This commit is contained in:
parent
1ddfb7b927
commit
bd75df7294
|
@ -13,5 +13,44 @@ class MasterTimelineTitleView: UIView {
|
|||
@IBOutlet weak var iconView: IconView!
|
||||
@IBOutlet weak var label: UILabel!
|
||||
@IBOutlet weak var unreadCountView: MasterTimelineUnreadCountView!
|
||||
|
||||
@available(iOS 13.4, *)
|
||||
private lazy var pointerInteraction: UIPointerInteraction = {
|
||||
UIPointerInteraction(delegate: self)
|
||||
}()
|
||||
|
||||
func buttonize() {
|
||||
heightAnchor.constraint(equalToConstant: 40.0).isActive = true
|
||||
accessibilityTraits = .button
|
||||
if #available(iOS 13.4, *) {
|
||||
addInteraction(pointerInteraction)
|
||||
}
|
||||
}
|
||||
|
||||
func debuttonize() {
|
||||
accessibilityTraits.remove(.button)
|
||||
if #available(iOS 13.4, *) {
|
||||
removeInteraction(pointerInteraction)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension MasterTimelineTitleView: UIPointerInteractionDelegate {
|
||||
|
||||
@available(iOS 13.4, *)
|
||||
func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
|
||||
|
||||
let params = UIPreviewParameters()
|
||||
var rect = self.bounds
|
||||
rect.origin.x = rect.origin.x - 10
|
||||
rect.size.width = rect.width + 20
|
||||
let path = UIBezierPath(roundedRect: rect, cornerRadius: 10.0)
|
||||
params.visiblePath = path
|
||||
|
||||
let preview = UITargetedPreview(view: self, parameters: params)
|
||||
|
||||
return UIPointerStyle(effect: .automatic(preview), shape: .path(path))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -564,12 +564,11 @@ private extension MasterTimelineViewController {
|
|||
updateTitleUnreadCount()
|
||||
|
||||
if coordinator.timelineFeed is WebFeed {
|
||||
titleView.heightAnchor.constraint(equalToConstant: 44.0).isActive = true
|
||||
titleView.buttonize()
|
||||
titleView.addGestureRecognizer(feedTapGestureRecognizer)
|
||||
titleView.accessibilityTraits = .button
|
||||
} else {
|
||||
titleView.debuttonize()
|
||||
titleView.removeGestureRecognizer(feedTapGestureRecognizer)
|
||||
titleView.accessibilityTraits.remove(.button)
|
||||
}
|
||||
|
||||
navigationItem.titleView = titleView
|
||||
|
|
Loading…
Reference in New Issue