From 27d6f4572d664b7af2bdfe859fc3fc61c49e754b Mon Sep 17 00:00:00 2001 From: Joe Fabisevich Date: Mon, 4 Mar 2024 16:17:56 -0500 Subject: [PATCH] Exposing UIColor variants of preferred color methods to fix dark/light mode colors from asset catalogs not being respected --- .../SafariView/SafariView.swift | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/Sources/BetterSafariView/SafariView/SafariView.swift b/Sources/BetterSafariView/SafariView/SafariView.swift index 10f9052..b04f9b5 100644 --- a/Sources/BetterSafariView/SafariView/SafariView.swift +++ b/Sources/BetterSafariView/SafariView/SafariView.swift @@ -72,15 +72,29 @@ public struct SafariView { /// @available(iOS 14.0, *) public func preferredBarAccentColor(_ color: Color?) -> Self { + guard let color else { return self } + + return self.preferredControlAccentColor(UIColor(color)) + } + + /// Sets the accent color for the background of the navigation bar and the toolbar. + /// + /// This color preference is ignored if the view controller is in Private Browsing mode or displaying an antiphishing warning. + /// After the view controller is presented, changes made are not reflected. + /// + /// - Parameters: + /// - color: The color to use as a bar accent color. If `nil`, the accent color continues to be inherited. + /// + public func preferredBarAccentColor(_ color: UIColor?) -> Self { var modified = self if let color = color { - modified.preferredBarTintColor = UIColor(color) + modified.preferredBarTintColor = color } else { modified.preferredBarTintColor = nil } return modified } - + /// Sets the accent color for the control buttons on the navigation bar and the toolbar. /// /// This color preference is ignored if the view controller is in Private Browsing mode or displaying an antiphishing warning. @@ -91,9 +105,24 @@ public struct SafariView { /// @available(iOS 14.0, *) public func preferredControlAccentColor(_ color: Color?) -> Self { + guard let color else { return self } + + return self.preferredControlAccentColor(UIColor(color)) + } + + /// Sets the accent color for the control buttons on the navigation bar and the toolbar. + /// + /// This color preference is ignored if the view controller is in Private Browsing mode or displaying an antiphishing warning. + /// After the view controller is presented, changes made are not reflected. + /// + /// - Parameters: + /// - color: The color to use as a control accent color. If `nil`, the accent color continues to be inherited. + /// + @available(iOS 14.0, *) + public func preferredControlAccentColor(_ color: UIColor?) -> Self { var modified = self if let color = color { - modified.preferredControlTintColor = UIColor(color) + modified.preferredControlTintColor = color } else { modified.preferredControlTintColor = nil }