Another attempt to fix empty URL bar
This commit is contained in:
@@ -9,9 +9,18 @@ import UIKit
|
||||
|
||||
class ToolbarView: UIView
|
||||
{
|
||||
var urlBar: URLBar? { didSet { containerView.addSubview(urlBar!) } }
|
||||
var urlBar: URLBar? {
|
||||
didSet {
|
||||
guard let urlBar else { return }
|
||||
containerView.addSubview(urlBar)
|
||||
|
||||
urlBar.textField.addAction(.init(handler: { [unowned self] _ in
|
||||
layoutLatch.activate()
|
||||
}), for: [ .editingDidBegin, .editingDidEnd ])
|
||||
}
|
||||
}
|
||||
|
||||
var cancelButtonVisible: Bool = false { didSet { layoutSubviews() } }
|
||||
var cancelButtonVisible: Bool = false { didSet { setNeedsLayout() } }
|
||||
|
||||
let containerView = UIView(frame: .zero)
|
||||
let backgroundView = GradientView(direction: .vertical, colors: [
|
||||
@@ -23,6 +32,9 @@ class ToolbarView: UIView
|
||||
let leadingButtonsView = ToolbarButtonContainerView(frame: .zero)
|
||||
let trailingButtonsView = ToolbarButtonContainerView(frame: .zero)
|
||||
|
||||
// Something I'm sure I'll regret: to ensure animation with the keyboard, latch layout until we get the right signal.
|
||||
lazy var layoutLatch = LayoutLatch(self)
|
||||
|
||||
convenience init()
|
||||
{
|
||||
self.init(frame: .zero)
|
||||
@@ -54,6 +66,7 @@ class ToolbarView: UIView
|
||||
|
||||
override func layoutSubviews()
|
||||
{
|
||||
guard !layoutLatch.latched else { return }
|
||||
super.layoutSubviews()
|
||||
|
||||
let shadowPath = UIBezierPath(rect: bounds)
|
||||
|
||||
@@ -153,20 +153,12 @@ class URLBar: ReliefButton
|
||||
textField.font = .systemFont(ofSize: 13.0)
|
||||
textField.clearButtonMode = .never
|
||||
textField.placeholder = "URL or search term"
|
||||
textField.addAction(UIAction(handler: { [unowned self] _ in
|
||||
// Mask view visibility is affected by editing state.
|
||||
self.layoutSubviews()
|
||||
}), for: [ .editingDidBegin, .editingDidEnd ])
|
||||
textField.keyCommands = [
|
||||
UIKeyCommand(action: #selector(Self.downKeyPressed), input: UIKeyCommand.inputDownArrow)
|
||||
.prioritizeOverSystem()
|
||||
]
|
||||
addSubview(textField)
|
||||
|
||||
textField.addAction(.init(handler: { [textField, refreshButton ] _ in
|
||||
refreshButton.isHidden = textField.isFirstResponder
|
||||
}), for: [ .editingDidBegin, .editingDidEnd ])
|
||||
|
||||
refreshButton.tintColor = .secondaryLabel
|
||||
refreshButton.setImage(refreshImage, for: .normal)
|
||||
refreshButton.isPointerInteractionEnabled = true
|
||||
@@ -189,6 +181,7 @@ class URLBar: ReliefButton
|
||||
documentSeparatorView.backgroundColor = .secondarySystemFill
|
||||
addSubview(documentSeparatorView)
|
||||
|
||||
controlsView.autoresizingMask = []
|
||||
controlsView.clearButton.addAction(.init(handler: { [textField] _ in
|
||||
textField.clearText()
|
||||
}), for: .primaryActionTriggered)
|
||||
@@ -346,7 +339,7 @@ class URLBar: ReliefButton
|
||||
documentSeparatorView.frame = documentSeparatorView.frame.insetBy(dx: 0.0, dy: 3.0)
|
||||
|
||||
// Text field controls
|
||||
controlsView.frame = CGRect(origin: .zero, size: controlsView.sizeThatFits(bounds.size))
|
||||
controlsView.frame = CGRect(origin: controlsView.frame.origin, size: controlsView.sizeThatFits(bounds.size))
|
||||
|
||||
// Text field
|
||||
let textFieldPadding: CGFloat = 6.0
|
||||
@@ -365,8 +358,18 @@ class URLBar: ReliefButton
|
||||
let refreshButtonSize = CGSize(width: textField.frame.height, height: textField.frame.height)
|
||||
refreshButton.frame = CGRect(origin: CGPoint(x: bounds.width - refreshButtonSize.width, y: 0), size: refreshButtonSize)
|
||||
|
||||
// Refresh vs. controls view visibility
|
||||
let isFocused = textField.isFirstResponder
|
||||
if isFocused {
|
||||
controlsView.alpha = 1.0
|
||||
refreshButton.alpha = 0.0
|
||||
} else {
|
||||
controlsView.alpha = 0.0
|
||||
refreshButton.alpha = 1.0
|
||||
}
|
||||
|
||||
// Error button
|
||||
if case .error(error: _) = loadProgress, !textField.isFirstResponder {
|
||||
if case .error(error: _) = loadProgress, !isFocused {
|
||||
errorButton.isHidden = false
|
||||
errorButton.sizeToFit()
|
||||
errorButton.frame = CGRect(
|
||||
@@ -384,7 +387,7 @@ class URLBar: ReliefButton
|
||||
// Fade mask
|
||||
fadeMaskView.frame = textField.bounds
|
||||
fadeMaskView.image = fadeBackgroundImageForSize(fadeMaskView.frame.size, cutoffLocation: fadeCutoffLocation)
|
||||
if !textField.isFirstResponder {
|
||||
if !isFocused {
|
||||
textField.mask = fadeMaskView
|
||||
} else {
|
||||
textField.mask = nil
|
||||
|
||||
Reference in New Issue
Block a user