Pointer effects

This commit is contained in:
James Magahern
2021-04-19 17:55:24 -07:00
parent 6eb462aeb7
commit 428232bfa8
5 changed files with 28 additions and 1 deletions

View File

@@ -70,6 +70,11 @@ class ReliefButton: UIButton
addSubview(backgroundView)
traitCollectionDidChange(nil)
pointerStyleProvider = { (button, pointerEffect, pointerShape) -> UIPointerStyle? in
let preview = UITargetedPreview(view: button)
return UIPointerStyle(effect: .lift(preview), shape: pointerShape)
}
}
required init?(coder: NSCoder) {

View File

@@ -14,6 +14,11 @@ class SegmentedReliefButton: ReliefButton
didSet { children.forEach { addSubview($0) }; setNeedsLayout() }
}
override var isPointerInteractionEnabled: Bool {
set { children.forEach { $0.isPointerInteractionEnabled = newValue } }
get { children.first?.isPointerInteractionEnabled ?? false }
}
private let backgroundsContainerView = UIView(frame: .zero)
private var childrenHighlighObservations: [NSKeyValueObservation] = []
@@ -30,7 +35,8 @@ class SegmentedReliefButton: ReliefButton
}
override var isHighlighted: Bool {
didSet {}
// Does not highlight. Only children do.
set {} get { false }
}
required init?(coder: NSCoder) {

View File

@@ -29,6 +29,7 @@ class TabView: UIControl
addSubview(closeButton)
closeButton.setImage(UIImage(systemName: "xmark.square.fill"), for: .normal)
closeButton.isPointerInteractionEnabled = true
closeButton.imageView?.contentMode = .center
closeButton.tintColor = .label

View File

@@ -14,6 +14,10 @@ class ToolbarButtonContainerView: UIView
public var numberOfButtonViews: Int { buttonViews.count }
func addButtonView(_ button: UIView) {
if let asButton = button as? UIButton {
asButton.isPointerInteractionEnabled = true
}
buttonViews.append(button)
addSubview(button)
setNeedsLayout()

View File

@@ -40,6 +40,10 @@ class URLBar: ReliefButton
didSet { updateProgressIndicator() }
}
override var isPointerInteractionEnabled: Bool {
get { false } set {}
}
private let fadeMaskView = UIImageView(frame: .zero)
private let progressIndicatorView = ProgressIndicatorView()
@@ -84,6 +88,7 @@ class URLBar: ReliefButton
refreshButton.tintColor = .secondaryLabel
refreshButton.setImage(refreshImage, for: .normal)
refreshButton.isPointerInteractionEnabled = true
addSubview(refreshButton)
errorButton.backgroundColor = .systemRed
@@ -92,10 +97,12 @@ class URLBar: ReliefButton
errorButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 11.0)
errorButton.setTitleColor(.white, for: .normal)
errorButton.setTitle("ERR", for: .normal)
errorButton.isPointerInteractionEnabled = true
addSubview(errorButton)
documentButton.tintColor = .secondaryLabel
documentButton.setImage(documentImage, for: .normal)
documentButton.isPointerInteractionEnabled = true
addSubview(documentButton)
documentSeparatorView.backgroundColor = .secondarySystemFill
@@ -155,6 +162,10 @@ class URLBar: ReliefButton
self.setNeedsLayout()
}
override func setBackgroundInverted(_ inverted: Bool) {
// no-op
}
override var intrinsicContentSize: CGSize {
let preferredHeight = CGFloat(34)
return CGSize(width: 1000.0, height: preferredHeight)