URLBar shouldn't show cancel button on iPad, visual tweaks

This commit is contained in:
James Magahern
2020-07-31 14:23:00 -07:00
parent ad85c3dc23
commit 2eec003a84
4 changed files with 18 additions and 10 deletions

View File

@@ -67,7 +67,6 @@ class BrowserView: UIView
override func layoutSubviews() {
super.layoutSubviews()
webView?.frame = bounds
var webViewContentInset = UIEdgeInsets()
@@ -101,9 +100,9 @@ class BrowserView: UIView
}
// Fix web view content insets
webView?.scrollView.automaticallyAdjustsScrollIndicatorInsets = false
webView?.scrollView.contentInset = webViewContentInset.subtracting(safeAreaInsets)
webView?.scrollView.scrollIndicatorInsets = webViewContentInset
if let webView = webView {
webView.scrollView.layer.masksToBounds = false // allow content to draw under titlebar/toolbar
webView.frame = bounds.inset(by: webViewContentInset)
}
}
}

View File

@@ -22,6 +22,8 @@ class TitlebarView: UIView
titleLabelView.layer.shadowRadius = 0.0
titleLabelView.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
titleLabelView.font = UIFont.boldSystemFont(ofSize: 12.0)
backgroundImageView.alpha = 0.98
}
private func backgroundImageForSize(_ size: CGSize) -> UIImage? {

View File

@@ -98,9 +98,10 @@ class ToolbarView: UIView
// Cancel button
let urlBarPadding: CGFloat = 8.0
let cancelButtonSize = cancelButton.sizeThatFits(containerView.bounds.size)
var cancelButtonSize = cancelButton.sizeThatFits(containerView.bounds.size)
cancelButtonSize.width += (urlBarPadding * 2)
cancelButton.frame = CGRect(origin: CGPoint(x: (containerView.bounds.maxX - cancelButtonSize.width), y: 0),
size: CGSize(width: cancelButtonSize.width, height: containerView.bounds.height))
size: CGSize(width: cancelButtonSize.width + urlBarPadding, height: containerView.bounds.height))
// Leading toolbar buttons
if leadingButtonsView.numberOfButtonViews > 0 {
@@ -189,10 +190,12 @@ class ToolbarViewController: UIViewController
forwardButton.setImage(UIImage(systemName: "chevron.right"), for: .normal)
let toolbarAnimationDuration: TimeInterval = 0.3
urlBar.textField.addAction(.init(handler: { [toolbarView, urlBar] _ in
urlBar.textField.addAction(.init(handler: { [traitCollection, toolbarView, urlBar] _ in
if traitCollection.horizontalSizeClass == .compact {
UIView.animate(withDuration: toolbarAnimationDuration) {
toolbarView.cancelButtonVisible = urlBar.textField.isFirstResponder
}
}
}), for: [ .editingDidBegin, .editingDidEnd ])
toolbarView.cancelButton.addAction(.init(handler: { [urlBar] action in

View File

@@ -52,6 +52,10 @@ class URLBar: UIView
textField.font = .systemFont(ofSize: 14.0)
textField.clearingBehavior = .clearOnInsertionAndShowSelectionTint
textField.clearButtonMode = .whileEditing
textField.addAction(UIAction(handler: { [unowned self] _ in
// Mask view visibility is affected by editing state.
self.layoutSubviews()
}), for: [ .editingDidBegin, .editingDidEnd ])
addSubview(textField)
textField.addAction(.init(handler: { [textField, refreshButton] _ in