iPad support

This commit is contained in:
James Magahern
2020-07-29 18:34:46 -07:00
parent 220fc6f070
commit 663dfcd2bb
3 changed files with 32 additions and 21 deletions

View File

@@ -67,9 +67,20 @@ class BrowserView: UIView
super.layoutSubviews() super.layoutSubviews()
webView?.frame = bounds webView?.frame = bounds
var webViewContentInset = UIEdgeInsets()
bringSubviewToFront(titlebarView)
var titlebarHeight: CGFloat = 24.0
titlebarHeight += safeAreaInsets.top
titlebarView.frame = CGRect(origin: .zero, size: CGSize(width: bounds.width, height: titlebarHeight))
webViewContentInset.top += titlebarView.frame.height
if let toolbarView = toolbarView { if let toolbarView = toolbarView {
var toolbarSize = toolbarView.sizeThatFits(bounds.size) var toolbarSize = toolbarView.sizeThatFits(bounds.size)
// Compact: toolbar is at the bottom
if traitCollection.horizontalSizeClass == .compact {
var bottomOffset: CGFloat = 0.0 var bottomOffset: CGFloat = 0.0
if keyboardLayoutOffset == 0 { if keyboardLayoutOffset == 0 {
toolbarSize.height += safeAreaInsets.bottom toolbarSize.height += safeAreaInsets.bottom
@@ -79,21 +90,18 @@ class BrowserView: UIView
toolbarView.bounds = CGRect(origin: .zero, size: toolbarSize) toolbarView.bounds = CGRect(origin: .zero, size: toolbarSize)
toolbarView.center = CGPoint(x: bounds.center.x, y: bounds.maxY - (toolbarView.bounds.height / 2) - bottomOffset) toolbarView.center = CGPoint(x: bounds.center.x, y: bounds.maxY - (toolbarView.bounds.height / 2) - bottomOffset)
webViewContentInset.bottom += toolbarView.frame.height
} else {
// Regular: toolbar is at the top
toolbarView.bounds = CGRect(origin: .zero, size: toolbarSize)
toolbarView.center = CGPoint(x: bounds.center.x, y: titlebarView.center.y + titlebarView.frame.height)
webViewContentInset.top += toolbarView.frame.height
}
} }
bringSubviewToFront(titlebarView)
var titlebarHeight: CGFloat = 24.0
titlebarHeight += safeAreaInsets.top
titlebarView.frame = CGRect(origin: .zero, size: CGSize(width: bounds.width, height: titlebarHeight))
// Fix web view content insets // Fix web view content insets
webView?.scrollView.automaticallyAdjustsScrollIndicatorInsets = false webView?.scrollView.automaticallyAdjustsScrollIndicatorInsets = false
var webViewContentInset = UIEdgeInsets()
webViewContentInset.top = titlebarView.frame.height
webViewContentInset.bottom = toolbarView?.frame.height ?? 0
webView?.scrollView.contentInset = webViewContentInset.subtracting(safeAreaInsets) webView?.scrollView.contentInset = webViewContentInset.subtracting(safeAreaInsets)
webView?.scrollView.scrollIndicatorInsets = webViewContentInset webView?.scrollView.scrollIndicatorInsets = webViewContentInset
} }

View File

@@ -62,6 +62,9 @@ class BrowserViewController: UIViewController,
scriptViewController.allowScriptsForTab = self.javaScriptEnabledForTab scriptViewController.allowScriptsForTab = self.javaScriptEnabledForTab
let navController = UINavigationController(rootViewController: scriptViewController) let navController = UINavigationController(rootViewController: scriptViewController)
navController.modalPresentationStyle = .popover
navController.popoverPresentationController?.sourceView = self.toolbarController.scriptControllerIconView
self.present(navController, animated: true, completion: nil) self.present(navController, animated: true, completion: nil)
}), for: .touchUpInside) }), for: .touchUpInside)

View File

@@ -82,12 +82,12 @@ class ToolbarView: UIView
// Cancel button // Cancel button
let urlBarPadding: CGFloat = 8.0 let urlBarPadding: CGFloat = 8.0
let cancelButtonSize = cancelButton.sizeThatFits(containerView.bounds.size) let cancelButtonSize = cancelButton.sizeThatFits(containerView.bounds.size)
cancelButton.frame = CGRect(origin: CGPoint(x: (urlBar?.frame.maxX ?? 0) + urlBarPadding, 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, height: containerView.bounds.height))
// Toolbar buttons // Toolbar buttons
let toolbarSize = buttonsView.sizeThatFits(containerView.bounds.size) let buttonContainerSize = buttonsView.sizeThatFits(containerView.bounds.size)
buttonsView.frame = CGRect(origin: CGPoint(x: (urlBar?.frame.maxX ?? 0) + urlBarPadding, y: 0), size: toolbarSize) buttonsView.frame = CGRect(origin: CGPoint(x: (containerView.bounds.maxX - buttonContainerSize.width) + urlBarPadding, y: 0), size: buttonContainerSize)
var avoidingSize: CGSize = .zero var avoidingSize: CGSize = .zero
if cancelButtonVisible { if cancelButtonVisible {
@@ -99,7 +99,7 @@ class ToolbarView: UIView
cancelButton.alpha = 0.0 cancelButton.alpha = 0.0
buttonsView.alpha = 1.0 buttonsView.alpha = 1.0
avoidingSize = toolbarSize avoidingSize = buttonContainerSize
} }
if let urlBar = urlBar { if let urlBar = urlBar {