Adds back/forward buttons to page menu
This commit is contained in:
@@ -203,6 +203,7 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
let label = documentControls.fontSizeAdjustView.labelView
|
||||
label.text = numberFormatter.string(for: tab.webView._viewScale)
|
||||
|
||||
// Font size adjust
|
||||
documentControls.fontSizeAdjustView.decreaseSizeButton.addAction(UIAction(handler: { [unowned self] sender in
|
||||
self.decreaseSize(sender)
|
||||
label.text = numberFormatter.string(for: tab.webView._viewScale)
|
||||
@@ -213,11 +214,31 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
label.text = numberFormatter.string(for: tab.webView._viewScale)
|
||||
}), for: .touchUpInside)
|
||||
|
||||
// Find on page
|
||||
documentControls.findOnPageControlView.addAction(UIAction(handler: { [unowned self] _ in
|
||||
documentControls.dismiss(animated: true, completion: nil)
|
||||
browserView.setFindOnPageVisible(true, animated: true)
|
||||
}), for: .touchUpInside)
|
||||
|
||||
// Navigation controls
|
||||
documentControls.navigationControlView.backButton.isEnabled = webView.canGoBack
|
||||
documentControls.navigationControlView.backButton.addAction(UIAction() { [unowned self] _ in
|
||||
webView.goBack()
|
||||
}, for: .touchUpInside)
|
||||
|
||||
documentControls.observations.append(webView.observe(\.canGoBack, changeHandler: { (_, _) in
|
||||
documentControls.navigationControlView.backButton.isEnabled = webView.canGoBack
|
||||
}))
|
||||
|
||||
documentControls.navigationControlView.forwardButton.isEnabled = webView.canGoForward
|
||||
documentControls.navigationControlView.forwardButton.addAction(UIAction() { [unowned self] _ in
|
||||
webView.goForward()
|
||||
}, for: .touchUpInside)
|
||||
|
||||
documentControls.observations.append(webView.observe(\.canGoForward, changeHandler: { (_, _) in
|
||||
documentControls.navigationControlView.forwardButton.isEnabled = webView.canGoForward
|
||||
}))
|
||||
|
||||
present(documentControls, animated: true, completion: nil)
|
||||
}), for: .touchUpInside)
|
||||
|
||||
|
||||
@@ -7,26 +7,33 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
class StackView: UIView
|
||||
class StackView<T: UIView>: UIView
|
||||
{
|
||||
var arrangedSubviews: [UIView] = []
|
||||
public enum LayoutType {
|
||||
case intrinsicSize
|
||||
case equalSize
|
||||
}
|
||||
|
||||
var arrangedSubviews: [T] = []
|
||||
{ didSet { setNeedsLayout() } }
|
||||
|
||||
var layoutDimension: UIAxis = .vertical
|
||||
var layoutType: LayoutType = .intrinsicSize
|
||||
|
||||
convenience init(dimension: UIAxis) {
|
||||
convenience init(dimension: UIAxis = .vertical, layoutType: LayoutType = .intrinsicSize) {
|
||||
self.init(frame: .zero)
|
||||
self.layoutDimension = dimension
|
||||
self.layoutType = layoutType
|
||||
}
|
||||
|
||||
// Convenience
|
||||
public func addArrangedSubview(_ view: UIView) {
|
||||
public func addArrangedSubview(_ view: T) {
|
||||
addSubview(view)
|
||||
arrangedSubviews.append(view)
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
public func removeArrangedSubview(_ view: UIView) {
|
||||
public func removeArrangedSubview(_ view: T) {
|
||||
if view.superview == self {
|
||||
view.removeFromSuperview()
|
||||
}
|
||||
@@ -68,6 +75,16 @@ class StackView: UIView
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
if layoutType == .intrinsicSize {
|
||||
layoutWithIntrinsicSize()
|
||||
} else if layoutType == .equalSize {
|
||||
layoutWithEqualSize()
|
||||
} else {
|
||||
fatalError("StackView: I don't know how to lay out this type")
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func layoutWithIntrinsicSize() {
|
||||
var origin: CGPoint = CGPoint(x: safeAreaInsets.left, y: safeAreaInsets.top)
|
||||
var spaceRemaining = bounds.size
|
||||
for view in arrangedSubviews {
|
||||
@@ -88,5 +105,35 @@ class StackView: UIView
|
||||
origin.x += offset.x
|
||||
origin.y += offset.y
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fileprivate func layoutWithEqualSize() {
|
||||
let numberOfItems = arrangedSubviews.count
|
||||
|
||||
let structureDimension: CGFloat = (
|
||||
(layoutDimension == .horizontal) ? bounds.height : bounds.width
|
||||
)
|
||||
|
||||
let itemDimension: CGFloat = (
|
||||
(layoutDimension == .horizontal) ? (bounds.width / CGFloat(numberOfItems)) : (bounds.height / CGFloat(numberOfItems))
|
||||
)
|
||||
|
||||
var origin: CGPoint = CGPoint(x: safeAreaInsets.left, y: safeAreaInsets.top)
|
||||
for view in arrangedSubviews {
|
||||
let size: CGSize = (
|
||||
(layoutDimension == .horizontal)
|
||||
? CGSize(width: itemDimension, height: structureDimension)
|
||||
: CGSize(width: structureDimension, height: itemDimension)
|
||||
)
|
||||
|
||||
view.frame = CGRect(origin: origin, size: size)
|
||||
|
||||
origin = (
|
||||
(layoutDimension == .horizontal)
|
||||
? CGPoint(x: origin.x + size.width, y: origin.y)
|
||||
: CGPoint(x: origin.x, y: origin.y + size.height)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,8 @@ class DocumentControlView: UIControl
|
||||
|
||||
tintColor = .label
|
||||
|
||||
label.font = UIFont.preferredFont(forTextStyle: .subheadline)
|
||||
label.textAlignment = .center
|
||||
label.font = UIFont.preferredFont(forTextStyle: .body)
|
||||
label.textAlignment = .left
|
||||
|
||||
imageView.contentMode = .center
|
||||
|
||||
|
||||
@@ -9,9 +9,12 @@ import UIKit
|
||||
|
||||
class DocumentControlViewController: UIViewController
|
||||
{
|
||||
let documentControlView = StackView(dimension: .vertical)
|
||||
let documentControlView = StackView<DocumentControlView>(dimension: .vertical)
|
||||
let fontSizeAdjustView = FontSizeAdjustView()
|
||||
let findOnPageControlView = DocumentControlView()
|
||||
let navigationControlView = NavigationControlsView()
|
||||
|
||||
var observations: [NSKeyValueObservation] = []
|
||||
|
||||
static public let preferredWidth = CGFloat(200.0)
|
||||
|
||||
@@ -21,10 +24,13 @@ class DocumentControlViewController: UIViewController
|
||||
findOnPageControlView.label.text = "Find On Page"
|
||||
findOnPageControlView.imageView.image = UIImage(systemName: "magnifyingglass")
|
||||
|
||||
fontSizeAdjustView.drawsBottomSeparator = true
|
||||
|
||||
documentControlView.addArrangedSubview(navigationControlView)
|
||||
documentControlView.addArrangedSubview(fontSizeAdjustView)
|
||||
documentControlView.addArrangedSubview(findOnPageControlView)
|
||||
|
||||
for (i, view) in documentControlView.arrangedSubviews.enumerated() {
|
||||
view.drawsBottomSeparator = (i < documentControlView.arrangedSubviews.count - 1)
|
||||
}
|
||||
}
|
||||
|
||||
override func loadView() {
|
||||
|
||||
37
App/Document Controls UI/NavigationControlsView.swift
Normal file
37
App/Document Controls UI/NavigationControlsView.swift
Normal file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// NavigationControlsView.swift
|
||||
// App
|
||||
//
|
||||
// Created by James Magahern on 2/11/21.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class NavigationControlsView: DocumentControlView
|
||||
{
|
||||
let backButton = UIButton(frame: .zero)
|
||||
let forwardButton = UIButton(frame: .zero)
|
||||
|
||||
let stack = StackView(dimension: .horizontal, layoutType: .equalSize)
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
backButton.setImage(UIImage(systemName: "chevron.left"), for: .normal)
|
||||
stack.addArrangedSubview(backButton)
|
||||
|
||||
forwardButton.setImage(UIImage(systemName: "chevron.right"), for: .normal)
|
||||
stack.addArrangedSubview(forwardButton)
|
||||
|
||||
addSubview(stack)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
stack.frame = bounds
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class URLBar: ReliefButton
|
||||
private let progressIndicatorView = ProgressIndicatorView()
|
||||
private var progressIndicatorAnimating = false
|
||||
|
||||
private let documentImage = UIImage(systemName: "doc.plaintext")
|
||||
private let documentImage = UIImage(systemName: "filemenu.and.selection")
|
||||
private let refreshImage = UIImage(systemName: "arrow.clockwise")
|
||||
private let stopImage = UIImage(systemName: "xmark")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user