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

View File

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

View File

@@ -98,9 +98,10 @@ class ToolbarView: UIView
// Cancel button // Cancel button
let urlBarPadding: CGFloat = 8.0 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), 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 // Leading toolbar buttons
if leadingButtonsView.numberOfButtonViews > 0 { if leadingButtonsView.numberOfButtonViews > 0 {
@@ -189,9 +190,11 @@ class ToolbarViewController: UIViewController
forwardButton.setImage(UIImage(systemName: "chevron.right"), for: .normal) forwardButton.setImage(UIImage(systemName: "chevron.right"), for: .normal)
let toolbarAnimationDuration: TimeInterval = 0.3 let toolbarAnimationDuration: TimeInterval = 0.3
urlBar.textField.addAction(.init(handler: { [toolbarView, urlBar] _ in urlBar.textField.addAction(.init(handler: { [traitCollection, toolbarView, urlBar] _ in
UIView.animate(withDuration: toolbarAnimationDuration) { if traitCollection.horizontalSizeClass == .compact {
toolbarView.cancelButtonVisible = urlBar.textField.isFirstResponder UIView.animate(withDuration: toolbarAnimationDuration) {
toolbarView.cancelButtonVisible = urlBar.textField.isFirstResponder
}
} }
}), for: [ .editingDidBegin, .editingDidEnd ]) }), for: [ .editingDidBegin, .editingDidEnd ])

View File

@@ -52,6 +52,10 @@ class URLBar: UIView
textField.font = .systemFont(ofSize: 14.0) textField.font = .systemFont(ofSize: 14.0)
textField.clearingBehavior = .clearOnInsertionAndShowSelectionTint textField.clearingBehavior = .clearOnInsertionAndShowSelectionTint
textField.clearButtonMode = .whileEditing 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) addSubview(textField)
textField.addAction(.init(handler: { [textField, refreshButton] _ in textField.addAction(.init(handler: { [textField, refreshButton] _ in