TabView: Favicons in tab bar
This commit is contained in:
@@ -35,6 +35,7 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
private var backButtonObservation: NSKeyValueObservation?
|
||||
private var forwardButtonObservation: NSKeyValueObservation?
|
||||
private var activeTabObservation: AnyCancellable?
|
||||
private var faviconObservation: AnyCancellable?
|
||||
|
||||
private var loadError: Error?
|
||||
|
||||
@@ -276,12 +277,14 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
}
|
||||
|
||||
private func updateTitleAndURL(forWebView webView: WKWebView) {
|
||||
browserView.titlebarView.setTitle(webView.title ?? "")
|
||||
if webView == browserView.webView {
|
||||
browserView.titlebarView.setTitle(webView.title ?? "")
|
||||
|
||||
if let urlString = webView.url?.absoluteString {
|
||||
toolbarController.urlBar.textField.text = urlString
|
||||
} else {
|
||||
toolbarController.urlBar.textField.text = ""
|
||||
if let urlString = webView.url?.absoluteString {
|
||||
toolbarController.urlBar.textField.text = urlString
|
||||
} else {
|
||||
toolbarController.urlBar.textField.text = ""
|
||||
}
|
||||
}
|
||||
|
||||
// Figure out which tab this corresponds to
|
||||
@@ -336,6 +339,12 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
toolbarController.forwardButton.isEnabled = webView.canGoForward
|
||||
})
|
||||
|
||||
// Favicon observation
|
||||
faviconObservation = tab.$favicon.receive(on: DispatchQueue.main)
|
||||
.sink { [unowned self] _ in
|
||||
updateTitleAndURL(forWebView: webView)
|
||||
}
|
||||
|
||||
// Script blocker button
|
||||
updateScriptBlockerButton()
|
||||
|
||||
|
||||
@@ -60,8 +60,8 @@ class Tab: NSObject, SBRProcessBundleBridgeDelegate
|
||||
}()
|
||||
|
||||
public var identifier = UUID()
|
||||
@Published public var favicon: UIImage?
|
||||
|
||||
public var favicon: UIImage?
|
||||
private var faviconHost: String?
|
||||
private var faviconRequest: AnyCancellable?
|
||||
|
||||
|
||||
@@ -37,6 +37,9 @@ class TabView: UIControl
|
||||
leftSeparator.backgroundColor = .secondarySystemFill
|
||||
rightSeparator.backgroundColor = .secondarySystemFill
|
||||
|
||||
imageView.contentMode = .scaleAspectFit
|
||||
addSubview(imageView)
|
||||
|
||||
// Try just one for now
|
||||
leftSeparator.isHidden = true
|
||||
}
|
||||
@@ -53,9 +56,16 @@ class TabView: UIControl
|
||||
width: closeButtonSize.width, height: closeButtonSize.height
|
||||
)
|
||||
|
||||
var xOffset = insetBounds.minX
|
||||
imageView.frame = CGRect(
|
||||
x: xOffset, y: insetBounds.minY,
|
||||
width: insetBounds.height, height: insetBounds.height
|
||||
)
|
||||
xOffset += imageView.frame.width
|
||||
|
||||
label.frame = CGRect(
|
||||
x: insetBounds.minX, y: insetBounds.minY,
|
||||
width: closeButton.frame.minX - closeButtonPadding, height: insetBounds.height
|
||||
x: xOffset + 12.0, y: insetBounds.minY,
|
||||
width: closeButton.frame.minX - closeButtonPadding - xOffset, height: insetBounds.height
|
||||
)
|
||||
|
||||
let separatorWidth = CGFloat(1.0)
|
||||
@@ -127,6 +137,8 @@ class TabBarView: UIView
|
||||
|
||||
private let bottomSeparatorView = UIView(frame: .zero)
|
||||
|
||||
private let placeholderTabImage = UIImage(systemName: "network")
|
||||
|
||||
override func sizeThatFits(_ size: CGSize) -> CGSize {
|
||||
CGSize(width: size.width, height: Self.preferredHeight)
|
||||
}
|
||||
@@ -201,8 +213,8 @@ class TabBarView: UIView
|
||||
|
||||
if let tabView = visibleTab(atIndex: index) {
|
||||
tabView.label.text = title
|
||||
tabView.imageView.image = image
|
||||
tabView.identifier = identifier
|
||||
tabView.imageView.image = image ?? placeholderTabImage
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1200"
|
||||
version = "2.0">
|
||||
version = "1.7">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
@@ -40,8 +40,7 @@
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES"
|
||||
internalIOSLaunchStyle = "2"
|
||||
viewDebuggingEnabled = "No">
|
||||
internalIOSLaunchStyle = "2">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
|
||||
Reference in New Issue
Block a user