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