From 09c10aba9c08afae5e51b1b8d4db9274a708823d Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Thu, 18 Jul 2019 18:30:14 -0400 Subject: [PATCH 01/73] Added new theming mechanism built off of JSON files. --- Client.xcodeproj/project.pbxproj | 22 +- .../Browser/BrowserViewController.swift | 6 +- Client/Frontend/Browser/Tab.swift | 2 + .../TabsBar/TabsBarViewController.swift | 6 +- .../BottomToolbar/BottomToolbarView.swift | 6 +- .../Toolbars/UrlBar/TabLocationView.swift | 6 +- .../Toolbars/UrlBar/TopToolbarView.swift | 6 +- .../Toolbars/UrlBar/UrlBarTextField.swift | 6 +- Client/Frontend/Widgets/Theme.swift | 57 --- Client/Frontend/Widgets/Themes/Theme.swift | 340 ++++++++++++++++++ Client/Frontend/Widgets/Themes/darkTheme.json | 38 ++ .../Frontend/Widgets/Themes/lightTheme.json | 38 ++ .../Frontend/Widgets/Themes/privateTheme.json | 38 ++ 13 files changed, 501 insertions(+), 70 deletions(-) delete mode 100644 Client/Frontend/Widgets/Theme.swift create mode 100644 Client/Frontend/Widgets/Themes/Theme.swift create mode 100644 Client/Frontend/Widgets/Themes/darkTheme.json create mode 100644 Client/Frontend/Widgets/Themes/lightTheme.json create mode 100644 Client/Frontend/Widgets/Themes/privateTheme.json diff --git a/Client.xcodeproj/project.pbxproj b/Client.xcodeproj/project.pbxproj index 53671ca1ebb..ff176f88de2 100644 --- a/Client.xcodeproj/project.pbxproj +++ b/Client.xcodeproj/project.pbxproj @@ -485,6 +485,9 @@ 5D24AF8221BA459000F9506A /* BlocklistName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D24AF8121BA459000F9506A /* BlocklistName.swift */; }; 5D24AF8421BA489A00F9506A /* ContentBlocker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D24AF8321BA489A00F9506A /* ContentBlocker.swift */; }; 5D24AF9021BA4D7700F9506A /* ContentBlockerRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D24AF8F21BA4D7700F9506A /* ContentBlockerRegion.swift */; }; + 5D26E8A522E117750015D7E9 /* privateTheme.json in Resources */ = {isa = PBXBuildFile; fileRef = 5D26E8A422E117750015D7E9 /* privateTheme.json */; }; + 5D26E8A722E1177B0015D7E9 /* darkTheme.json in Resources */ = {isa = PBXBuildFile; fileRef = 5D26E8A622E1177A0015D7E9 /* darkTheme.json */; }; + 5D26E8A922E117800015D7E9 /* lightTheme.json in Resources */ = {isa = PBXBuildFile; fileRef = 5D26E8A822E1177F0015D7E9 /* lightTheme.json */; }; 5D6DDEF3214003A6001FF0AE /* DAU.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D6DDEE6214003A6001FF0AE /* DAU.swift */; }; 5D6DDEFE2141B6A1001FF0AE /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D6DDEF62141B6A0001FF0AE /* Preferences.swift */; }; 5D6DDF0021428CF0001FF0AE /* DAUTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D6DDEFF21428CF0001FF0AE /* DAUTests.swift */; }; @@ -1846,6 +1849,9 @@ 5D24AF8121BA459000F9506A /* BlocklistName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlocklistName.swift; sourceTree = ""; }; 5D24AF8321BA489A00F9506A /* ContentBlocker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentBlocker.swift; sourceTree = ""; }; 5D24AF8F21BA4D7700F9506A /* ContentBlockerRegion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentBlockerRegion.swift; sourceTree = ""; }; + 5D26E8A422E117750015D7E9 /* privateTheme.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = privateTheme.json; sourceTree = ""; }; + 5D26E8A622E1177A0015D7E9 /* darkTheme.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = darkTheme.json; sourceTree = ""; }; + 5D26E8A822E1177F0015D7E9 /* lightTheme.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = lightTheme.json; sourceTree = ""; }; 5D6DDEE6214003A6001FF0AE /* DAU.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DAU.swift; sourceTree = ""; }; 5D6DDEF62141B6A0001FF0AE /* Preferences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = ""; }; 5D6DDEFF21428CF0001FF0AE /* DAUTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DAUTests.swift; sourceTree = ""; }; @@ -3355,6 +3361,17 @@ path = sync; sourceTree = ""; }; + 5D26E89C22E117660015D7E9 /* Themes */ = { + isa = PBXGroup; + children = ( + 7B3631E91C244FEE00D12AF9 /* Theme.swift */, + 5D26E8A422E117750015D7E9 /* privateTheme.json */, + 5D26E8A822E1177F0015D7E9 /* lightTheme.json */, + 5D26E8A622E1177A0015D7E9 /* darkTheme.json */, + ); + path = Themes; + sourceTree = ""; + }; 5D6DDEDF214003A6001FF0AE /* Analytics */ = { isa = PBXGroup; children = ( @@ -3660,7 +3677,7 @@ E65607601C08B4E200534B02 /* SearchInputView.swift */, E63ED7D71BFCD9990097D08E /* LoginTableViewCell.swift */, C4E3984B1D21F2FD004E89BA /* TabTrayButtonExtensions.swift */, - 7B3631E91C244FEE00D12AF9 /* Theme.swift */, + 5D26E89C22E117660015D7E9 /* Themes */, 59A68B1F857A8638598A63A0 /* TwoLineCell.swift */, D863C8E31F68BFC20058D95F /* GradientProgressBar.swift */, 27D87C2D2152B50200FB55C6 /* GradientView.swift */, @@ -5139,12 +5156,14 @@ 3BC659591E5BA505006D560F /* top_sites.json in Resources */, E4B7B7631A793CF20022C5E0 /* CharisSILI.ttf in Resources */, E4CD9F541A71506400318571 /* Reader.html in Resources */, + 5D26E8A722E1177B0015D7E9 /* darkTheme.json in Resources */, C6345ECB2113B3A000CFB983 /* SearchPlugins in Resources */, F930CDAC227000F200A23FE1 /* U2F.js in Resources */, 5D7001C222249F7B00E576FB /* ShortNameToFileMapping.json in Resources */, 4422D55921BFFB7F00BF1855 /* unicode.py in Resources */, 7B2142FE1E5E055000CDD3FC /* InfoPlist.strings in Resources */, E69922171B94E3EF007C480D /* Licenses.html in Resources */, + 5D26E8A522E117750015D7E9 /* privateTheme.json in Resources */, E4CD9F5B1A71506C00318571 /* Reader.css in Resources */, D0FCF8061FE4772D004A7995 /* AllFramesAtDocumentEnd.js in Resources */, 27658273217130D900754B2F /* DigiCertHighAssurance.cer in Resources */, @@ -5169,6 +5188,7 @@ 4422D4AD21BFFB7600BF1855 /* LICENSE in Resources */, E4B7B7641A793CF20022C5E0 /* CharisSILR.ttf in Resources */, 4422D56D21BFFB7F00BF1855 /* make_unicode_groups.py in Resources */, + 5D26E8A922E117800015D7E9 /* lightTheme.json in Resources */, E4B7B7681A793CF20022C5E0 /* FiraSans-Bold.ttf in Resources */, E4B7B7781A793CF20022C5E0 /* FiraSans-Italic.ttf in Resources */, 0BA1E00E1B03FB0B007675AF /* NetError.html in Resources */, diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index 33c8095810f..6c85d08298e 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -209,9 +209,11 @@ class BrowserViewController: UIViewController { override var preferredStatusBarStyle: UIStatusBarStyle { switch Theme.of(tabManager.selectedTab) { - case .regular: + case Theme.regular: return .default - case .private: + case Theme.private: + return .lightContent + default: return .lightContent } } diff --git a/Client/Frontend/Browser/Tab.swift b/Client/Frontend/Browser/Tab.swift index 0eae8b1a3df..d9f8b069b9c 100644 --- a/Client/Frontend/Browser/Tab.swift +++ b/Client/Frontend/Browser/Tab.swift @@ -55,6 +55,8 @@ class Tab: NSObject { return type.isPrivate } + var theme: Theme = Theme.regular + var contentIsSecure = false var tabState: TabState { diff --git a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift index 9d14eebf1e3..2edac664379 100644 --- a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift +++ b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift @@ -334,14 +334,16 @@ extension TabsBarViewController: TabManagerDelegate { extension TabsBarViewController: Themeable { func applyTheme(_ theme: Theme) { switch theme { - case .regular: + case Theme.regular: view.backgroundColor = BraveUX.GreyB plusButton.tintColor = BraveUX.GreyI bottomLine.backgroundColor = UIColor(white: 0.0, alpha: 0.2) - case .private: + case Theme.private: view.backgroundColor = BraveUX.Black plusButton.tintColor = UIColor.white bottomLine.backgroundColor = UIColor(white: 1.0, alpha: 0.2) + default: + break } collectionView.backgroundColor = view.backgroundColor diff --git a/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift b/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift index 253a71e32b1..dfd8586021d 100644 --- a/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift +++ b/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift @@ -106,9 +106,11 @@ class BottomToolbarView: UIView, ToolbarProtocol { extension BottomToolbarView: Themeable { func applyTheme(_ theme: Theme) { switch theme { - case .regular: + case Theme.regular: backgroundColor = BraveUX.ToolbarsBackgroundSolidColor - case .private: + case Theme.private: + backgroundColor = BraveUX.DarkToolbarsBackgroundSolidColor + default: backgroundColor = BraveUX.DarkToolbarsBackgroundSolidColor } diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift b/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift index 90e6ce927d5..48132c8bc8b 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift @@ -382,9 +382,11 @@ extension TabLocationView: AccessibilityActionsSource { extension TabLocationView: Themeable { func applyTheme(_ theme: Theme) { switch theme { - case .regular: + case Theme.regular: backgroundColor = BraveUX.LocationBarBackgroundColor - case .private: + case Theme.private: + backgroundColor = BraveUX.LocationBarBackgroundColor_PrivateMode + default: backgroundColor = BraveUX.LocationBarBackgroundColor_PrivateMode } diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift index 6b47b40ec29..1cd67affe8d 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift @@ -568,9 +568,11 @@ extension TopToolbarView: Themeable { currentTheme = theme cancelButton.setTitleColor(UIColor.Browser.Tint.colorFor(theme), for: .normal) switch theme { - case .regular: + case Theme.regular: backgroundColor = BraveUX.ToolbarsBackgroundSolidColor - case .private: + case Theme.private: + backgroundColor = BraveUX.DarkToolbarsBackgroundSolidColor + default: backgroundColor = BraveUX.DarkToolbarsBackgroundSolidColor } line.backgroundColor = UIColor.Browser.URLBarDivider.colorFor(theme) diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift b/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift index bf45074bf6a..bb332a5fb22 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift @@ -72,9 +72,11 @@ extension UrlBarTextField: Themeable { func applyTheme(_ theme: Theme) { switch theme { - case .regular: + case Theme.regular: backgroundColor = BraveUX.LocationBarBackgroundColor - case .private: + case Theme.private: + backgroundColor = BraveUX.LocationBarBackgroundColor_PrivateMode + default: backgroundColor = BraveUX.LocationBarBackgroundColor_PrivateMode } diff --git a/Client/Frontend/Widgets/Theme.swift b/Client/Frontend/Widgets/Theme.swift deleted file mode 100644 index 3bc06f7b8a4..00000000000 --- a/Client/Frontend/Widgets/Theme.swift +++ /dev/null @@ -1,57 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -import Foundation - -protocol Themeable { - - func applyTheme(_ theme: Theme) - -} - -enum Theme: String { - - /// Regular browsing. - case regular - - /// Private browsing. - case `private` - - /// Textual representation suitable for debugging. - var debugDescription: String { - switch self { - case .regular: - return "Regular theme" - case .private: - return "Private theme" - } - } - - /// Returns whether the theme is private or not. - var isPrivate: Bool { - switch self { - case .regular: - return false - case .private: - return true - } - } - - /// Returns the theme of the given Tab, if the tab is nil returns a regular theme. - /// - /// - parameter tab: An object representing a Tab. - /// - returns: A Tab theme. - static func of(_ tab: Tab?) -> Theme { - if let tab = tab { - switch TabType.of(tab) { - case .regular: - return .regular - case .private: - return .private - } - } - return PrivateBrowsingManager.shared.isPrivateBrowsing ? .private : .regular - } - -} diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift new file mode 100644 index 00000000000..595b802afa9 --- /dev/null +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -0,0 +1,340 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import Foundation + +protocol Themeable { + + var themeableChildren: [Themeable]? { get } + func applyTheme(_ theme: Theme) + +} + +extension Themeable { + // Should be explicity done on each Themeable view, but doing this to avoid tons of compile errors + var themeableChildren: [Themeable]? { return nil } + + func applyTheme(_ theme: Theme) { + self.themeableChildren?.forEach { $0.applyTheme(theme) } + } +} + +class Theme: Equatable, Decodable { + + + required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: ThemeCodingKeys.self) + uuid = try container.decode(String.self, forKey: .uuid) + title = try container.decode(String.self, forKey: .title) + url = try container.decode(URL.self, forKey: .url) + description = try container.decode(String.self, forKey: .description) + thumbnail = try container.decode(URL.self, forKey: .thumbnail) + isDark = try container.decode(Bool.self, forKey: .isDark) + enabled = try container.decode(Bool.self, forKey: .enabled) + + colors = try container.decode(Color.self, forKey: .colors) + images = try container.decode(Image.self, forKey: .images) + } + + let uuid: String + let title: String + let url: URL + let description: String + let thumbnail: URL + let isDark: Bool + let enabled: Bool + + let colors: Color + struct Color: Decodable { + + init(from decoder: Decoder) throws { + + let container = try decoder.container(keyedBy: ThemeCodingKeys.ColorCodingKeys.self) + let headerStr = try container.decode(String.self, forKey: .header) + let footerStr = try container.decode(String.self, forKey: .footer) + let homeStr = try container.decode(String.self, forKey: .home) + let addressBarStr = try container.decode(String.self, forKey: .addressBar) + let borderStr = try container.decode(String.self, forKey: .border) + + header = UIColor(colorString: headerStr) + footer = UIColor(colorString: footerStr) + home = UIColor(colorString: homeStr) + addressBar = UIColor(colorString: addressBarStr) + border = UIColor(colorString: borderStr) + + stats = try container.decode(Stat.self, forKey: .stats) + tints = try container.decode(Tint.self, forKey: .tints) + } + + let header: UIColor + let footer: UIColor + let home: UIColor + let addressBar: UIColor + let border: UIColor + + let stats: Stat + struct Stat: Decodable { + init(from decoder: Decoder) throws { + + let container = try decoder.container(keyedBy: ThemeCodingKeys.ColorCodingKeys.StatCodingKeys.self) + let adsStr = try container.decode(String.self, forKey: .ads) + let trackersStr = try container.decode(String.self, forKey: .trackers) + let httpseStr = try container.decode(String.self, forKey: .httpse) + let timeSavedStr = try container.decode(String.self, forKey: .timeSaved) + + ads = UIColor(colorString: adsStr) + trackers = UIColor(colorString: trackersStr) + httpse = UIColor(colorString: httpseStr) + timeSaved = UIColor(colorString: timeSavedStr) + } + + let ads: UIColor + let trackers: UIColor + let httpse: UIColor + let timeSaved: UIColor + } + + let tints: Tint + struct Tint: Decodable { + init(from decoder: Decoder) throws { + + let container = try decoder.container(keyedBy: ThemeCodingKeys.ColorCodingKeys.TintCodingKeys.self) + let homeStr = try container.decode(String.self, forKey: .home) + let headerStr = try container.decode(String.self, forKey: .header) + let footerStr = try container.decode(String.self, forKey: .footer) + let addressBarStr = try container.decode(String.self, forKey: .addressBar) + + home = UIColor(colorString: homeStr) + header = UIColor(colorString: headerStr) + footer = UIColor(colorString: footerStr) + addressBar = UIColor(colorString: addressBarStr) + } + + let home: UIColor + let header: UIColor + let footer: UIColor + let addressBar: UIColor + } + } + + let images: Image + struct Image: Decodable { + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: ThemeCodingKeys.ImageCodingKeys.self) + header = try container.decode(URL.self, forKey: .header) + footer = try container.decode(URL.self, forKey: .footer) + home = try container.decode(URL.self, forKey: .home) + } + + let header: URL + let footer: URL + let home: URL + } + + lazy var available: [Theme] = { + return [Theme.regular, Theme.private] + }() + + /// Textual representation suitable for debugging. + var debugDescription: String { + return description + } + + /// Returns whether the theme is private or not. + var isPrivate: Bool { + switch self { + case Theme.regular: + return false + case Theme.private: + return true + default: + return true + } + } + + /// Returns the theme of the given Tab, if the tab is nil returns a regular theme. + /// + /// - parameter tab: An object representing a Tab. + /// - returns: A Tab theme. + static func of(_ tab: Tab?) -> Theme { + if let tab = tab { + switch TabType.of(tab) { + case .regular: + return .regular + case .private: + return .private + + } + } + return PrivateBrowsingManager.shared.isPrivateBrowsing ? .private : .regular + } + + // Maybe wrap in a `mode` struct, however, most UI will only care about theme.data + /// Regular browsing. + static let regular: Theme = { + let themeData = normalTheme().data(using: String.Encoding.utf8)! + return try! JSONDecoder().decode(Theme.self, from: themeData) + }() + + /// Private browsing. + static let `private`: Theme = { + let themeData = privateTheme().data(using: String.Encoding.utf8)! + return try! JSONDecoder().decode(Theme.self, from: themeData) + }() + + static func == (lhs: Theme, rhs: Theme) -> Bool { + return lhs.uuid == rhs.uuid + } +} + +private extension Theme { + + static func normalTheme() -> String { + return """ + + { + "uuid": "FAIDSFJELWEF", + "title": "Default light", + "url": "www.brave.com", + "description": "The standard default light theme", + "thumbnail": "https://www.google.com", + "isDark": false, + "enabled": true, + + "colors": { + "header": "0xffffff", + "footer": "0xffffff", + "home": "0xffffff", + "addressBar": "0xD7D7E0", + "border": "0x000000", + "tints": { + "home": "0x434351", + "header": "0x434351", + "footer": "0x434351", + "addressBar": "0x434351" + }, + "transparencies": { + "addressBarAlpha": 1.0, + "borderAlpha": 0.2, + }, + "stats": { + "ads": "0xFA4214", + "trackers": "0xFA4214", + "httpse": "0x9339D4", + "timeSaved": "0x222326" + } + }, + "images": { + "header": "https://www.google.com", + "footer": "https://www.google.com", + "home": "https://www.google.com", + } + } + + + + """ + } + + static func privateTheme() -> String { + return """ + + { + "uniqueKey": "382", + "description": "Default private theme" + } + + """ + } +} + +fileprivate enum ThemeCodingKeys: String, CodingKey { + case uuid + case title + case url + case description + case thumbnail + case isDark + case enabled + + case colors + enum ColorCodingKeys: String, CodingKey { + case header + case footer + case home + case addressBar + case border + + case tints + enum TintCodingKeys: String, CodingKey { + case home + case header + case footer + case addressBar + } + + case transparencies + enum TransparencyCodingKeys: String, CodingKey { + case addressBarAlpha + case borderAlpha + } + + case stats + enum StatCodingKeys: String, CodingKey { + case ads + case trackers + case httpse + case timeSaved + } + } + + case images + enum ImageCodingKeys: String, CodingKey { + case header + case footer + case home + } +} + +/** + + { + "title": "Rust", + "url": "", // Creator url + "description": "", // Any details or information about theme -user facing + "thumb": "Rust", // Theme manager thumb, can be url/uri + "isDark": false, // Simple flag for dark or light type themes + "enabled": true, // Displays in theme manager + + "colors": { + "header": "0xffffff", + "footer": "0xffffff", + "home": "0xffffff", + "addressBar": "0xE2591F", // address bar bg + "border": "0xE2591F", // header and footer border color + "tints": { + "home": "0xE2591F", + "header": "0xE2591F", // Icon tint + "footer": "0xE2591F", // Icon tint + "addressBar": "0xE2591F" // Inner url bar icon tint and font color + }, + "transparencies": { + "addressBarAlpha": 0.2, // address bar bg alpha (allows blending to background) + "borderAlpha": 0.2, // header and footer border alpha (allows blending) + }, + "stats": { + "ads": "0xE2591F", // color for ads label on home screen + "trackers": "0xE2591F", // color for trackers label on home screen + "httpse": "0xE2591F", // color for httpse upgrades on home screen + "timeSaved": "0xE2591F" // color for time saved label on home screen + } + }, + "images": { + "header": "", + "footer": "", + "home": "", // Background image can be url/uri + } + } + + */ diff --git a/Client/Frontend/Widgets/Themes/darkTheme.json b/Client/Frontend/Widgets/Themes/darkTheme.json new file mode 100644 index 00000000000..5544a63e07c --- /dev/null +++ b/Client/Frontend/Widgets/Themes/darkTheme.json @@ -0,0 +1,38 @@ +{ + "uuid": "FAIDSFJELWEF2" + "title": "Default dark", + "url": "www.brave.com", + "description": "The standard default dark theme", + "thumb": "", + "isDark": true, + "enabled": true, + + "colors": { + "header": "0x000000", + "footer": "0x000000", + "home": "0x0A0A0A", + "addressBar": "0x262626", + "border": "0xffffff", + "tints": { + "home": "0xE7E6E9", + "header": "0xE7E6E9", + "footer": "0xE7E6E9", + "addressBar": "0xE7E6E9" + }, + "transparencies": { + "addressBarAlpha": 1.0, + "borderAlpha": 0.2, + }, + "stats": { + "ads": "0xFA4214", + "trackers": "", + "httpse": "0x9339D4", + "timeSaved": "0xffffff" + } + }, + "images": { + "header": "", + "footer": "", + "home": "", + } +} diff --git a/Client/Frontend/Widgets/Themes/lightTheme.json b/Client/Frontend/Widgets/Themes/lightTheme.json new file mode 100644 index 00000000000..a701904c480 --- /dev/null +++ b/Client/Frontend/Widgets/Themes/lightTheme.json @@ -0,0 +1,38 @@ +{ + "uuid": "FAIDSFJELWEF" + "title": "Default light", + "url": "www.brave.com", + "description": "The standard default light theme", + "thumb": "", + "isDark": false, + "enabled": true, + + "colors": { + "header": "0xffffff", + "footer": "0xffffff", + "home": "0xffffff", + "addressBar": "0xD7D7E0", + "border": "0x000000", + "tints": { + "home": "0x434351", + "header": "0x434351", + "footer": "0x434351", + "addressBar": "0x434351" + }, + "transparencies": { + "addressBarAlpha": 1.0, + "borderAlpha": 0.2, + }, + "stats": { + "ads": "0xFA4214", + "trackers": "", + "httpse": "0x9339D4", + "timeSaved": "0x222326" + } + }, + "images": { + "header": "", + "footer": "", + "home": "", + } +} diff --git a/Client/Frontend/Widgets/Themes/privateTheme.json b/Client/Frontend/Widgets/Themes/privateTheme.json new file mode 100644 index 00000000000..39b5d4225cb --- /dev/null +++ b/Client/Frontend/Widgets/Themes/privateTheme.json @@ -0,0 +1,38 @@ +{ + "uuid": "FAIDSFJELWEF3" + "title": "Default private", + "url": "www.brave.com", + "description": "The standard default private theme", + "thumb": "", + "isDark": true, + "enabled": true, + + "colors": { + "header": "0x1B0C32", + "footer": "0x1B0C32", + "home": "0x210950", + "addressBar": "0x3D2742", + "border": "0xffffff", + "tints": { + "home": "0xE7E6E9", + "header": "0xE7E6E9", + "footer": "0xE7E6E9", + "addressBar": "0xE7E6E9" + }, + "transparencies": { + "addressBarAlpha": 1.0, + "borderAlpha": 0.2, + }, + "stats": { + "ads": "0xFA4214", + "trackers": "", + "httpse": "0x9339D4", + "timeSaved": "0xffffff" + } + }, + "images": { + "header": "", + "footer": "", + "home": "", + } +} From c5fe2ccd376598a4f5b54f7fb1529f189b1648ac Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 2 Aug 2019 08:21:34 -0400 Subject: [PATCH 02/73] Added Transparencies to theme file. --- Client/Frontend/Widgets/Themes/Theme.swift | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index 595b802afa9..dccf4e90666 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -22,7 +22,6 @@ extension Themeable { class Theme: Equatable, Decodable { - required init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: ThemeCodingKeys.self) uuid = try container.decode(String.self, forKey: .uuid) @@ -65,6 +64,7 @@ class Theme: Equatable, Decodable { stats = try container.decode(Stat.self, forKey: .stats) tints = try container.decode(Tint.self, forKey: .tints) + transparencies = try container.decode(Transparency.self, forKey: .transparencies) } let header: UIColor @@ -116,6 +116,12 @@ class Theme: Equatable, Decodable { let footer: UIColor let addressBar: UIColor } + + let transparencies: Transparency + struct Transparency: Decodable { + let addressBarAlpha: CGFloat + let borderAlpha: CGFloat + } } let images: Image @@ -143,14 +149,7 @@ class Theme: Equatable, Decodable { /// Returns whether the theme is private or not. var isPrivate: Bool { - switch self { - case Theme.regular: - return false - case Theme.private: - return true - default: - return true - } + return self.isDark } /// Returns the theme of the given Tab, if the tab is nil returns a regular theme. From da616c3f5fa90ee643d2dabd0de9652550d2b6ec Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 2 Aug 2019 08:21:56 -0400 Subject: [PATCH 03/73] Added private theme. --- Client/Frontend/Widgets/Themes/Theme.swift | 81 ++++++++++------------ 1 file changed, 36 insertions(+), 45 deletions(-) diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index dccf4e90666..30bf6760141 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -238,10 +238,43 @@ private extension Theme { static func privateTheme() -> String { return """ - { - "uniqueKey": "382", - "description": "Default private theme" + "uuid": "FAIDSFJELWEF3", + "title": "Default private", + "url": "www.brave.com", + "description": "The standard default private theme", + "thumbnail": "https://www.google.com", + "isDark": true, + "enabled": true, + + "colors": { + "header": "0x1B0C32", + "footer": "0x1B0C32", + "home": "0x210950", + "addressBar": "0x3D2742", + "border": "0xffffff", + "tints": { + "home": "0xE7E6E9", + "header": "0xE7E6E9", + "footer": "0xE7E6E9", + "addressBar": "0xE7E6E9" + }, + "transparencies": { + "addressBarAlpha": 1.0, + "borderAlpha": 0.2, + }, + "stats": { + "ads": "0xFA4214", + "trackers": "0xFA4214", + "httpse": "0x9339D4", + "timeSaved": "0xffffff" + } + }, + "images": { + "header": "https://www.google.com", + "footer": "https://www.google.com", + "home": "https://www.google.com", + } } """ @@ -295,45 +328,3 @@ fileprivate enum ThemeCodingKeys: String, CodingKey { case home } } - -/** - - { - "title": "Rust", - "url": "", // Creator url - "description": "", // Any details or information about theme -user facing - "thumb": "Rust", // Theme manager thumb, can be url/uri - "isDark": false, // Simple flag for dark or light type themes - "enabled": true, // Displays in theme manager - - "colors": { - "header": "0xffffff", - "footer": "0xffffff", - "home": "0xffffff", - "addressBar": "0xE2591F", // address bar bg - "border": "0xE2591F", // header and footer border color - "tints": { - "home": "0xE2591F", - "header": "0xE2591F", // Icon tint - "footer": "0xE2591F", // Icon tint - "addressBar": "0xE2591F" // Inner url bar icon tint and font color - }, - "transparencies": { - "addressBarAlpha": 0.2, // address bar bg alpha (allows blending to background) - "borderAlpha": 0.2, // header and footer border alpha (allows blending) - }, - "stats": { - "ads": "0xE2591F", // color for ads label on home screen - "trackers": "0xE2591F", // color for trackers label on home screen - "httpse": "0xE2591F", // color for httpse upgrades on home screen - "timeSaved": "0xE2591F" // color for time saved label on home screen - } - }, - "images": { - "header": "", - "footer": "", - "home": "", // Background image can be url/uri - } - } - - */ From 08d688d2205023c10eb529513d27ae610aecf44c Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 2 Aug 2019 08:24:59 -0400 Subject: [PATCH 04/73] Added `styleChildren` call to all `Themeable` children. A few smaller views had elements styled. --- .../Browser/BrowserViewController.swift | 11 ++++++-- .../HomePanel/BraveShieldStatsView.swift | 11 +++++--- .../HomePanel/FavoritesViewController.swift | 12 ++++---- .../Frontend/Browser/ReaderModeBarView.swift | 2 ++ .../Browser/TabTrayButtonExtensions.swift | 2 ++ .../Frontend/Browser/TabTrayController.swift | 15 ++++++++-- .../TabsBar/TabsBarViewController.swift | 19 ++++--------- .../BottomToolbar/BottomToolbarView.swift | 16 ++++------- .../Browser/Toolbars/ToolbarButton.swift | 2 ++ .../Toolbars/UrlBar/TabLocationView.swift | 28 +++++++++---------- .../Toolbars/UrlBar/TopToolbarView.swift | 23 ++++++--------- .../Toolbars/UrlBar/UrlBarTextField.swift | 14 +++------- Client/Frontend/Widgets/TabsButton.swift | 2 ++ Client/Frontend/Widgets/Themes/Theme.swift | 12 +++++--- 14 files changed, 88 insertions(+), 81 deletions(-) diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index 6c85d08298e..35cf2ce84ef 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -2876,10 +2876,15 @@ extension BrowserViewController: TabTrayDelegate { // MARK: Browser Chrome Theming extension BrowserViewController: Themeable { - + + var themeableChildren: [Themeable?]? { + return [topToolbar, toolbar, readerModeBar, tabsBar, favoritesViewController] + } + func applyTheme(_ theme: Theme) { - let ui: [Themeable?] = [topToolbar, toolbar, readerModeBar, tabsBar, favoritesViewController] - ui.forEach { $0?.applyTheme(theme) } + styleChildren(theme: theme) + + // Maybe just set to clear color? statusBarOverlay.backgroundColor = topToolbar.backgroundColor setNeedsStatusBarAppearanceUpdate() } diff --git a/Client/Frontend/Browser/HomePanel/BraveShieldStatsView.swift b/Client/Frontend/Browser/HomePanel/BraveShieldStatsView.swift index 1ac7879a14e..293ce7ec2df 100644 --- a/Client/Frontend/Browser/HomePanel/BraveShieldStatsView.swift +++ b/Client/Frontend/Browser/HomePanel/BraveShieldStatsView.swift @@ -8,7 +8,13 @@ import BraveShared class BraveShieldStatsView: UIView, Themeable { func applyTheme(_ theme: Theme) { - // BRAVE TODO: + styleChildren(theme: theme) + + let colors = theme.colors.stats + adsStatView.color = colors.ads + httpsStatView.color = colors.httpse + timeStatView.color = colors.timeSaved + } fileprivate let millisecondsPerItem: Int = 50 @@ -16,21 +22,18 @@ class BraveShieldStatsView: UIView, Themeable { lazy var adsStatView: StatView = { let statView = StatView(frame: CGRect.zero) statView.title = Strings.ShieldsAdAndTrackerStats - statView.color = UX.BraveOrange return statView }() lazy var httpsStatView: StatView = { let statView = StatView(frame: CGRect.zero) statView.title = Strings.ShieldsHttpsStats - statView.color = UX.Green return statView }() lazy var timeStatView: StatView = { let statView = StatView(frame: CGRect.zero) statView.title = Strings.ShieldsTimeStats - statView.color = PrivateBrowsingManager.shared.isPrivateBrowsing ? UX.GreyA : UX.GreyJ return statView }() diff --git a/Client/Frontend/Browser/HomePanel/FavoritesViewController.swift b/Client/Frontend/Browser/HomePanel/FavoritesViewController.swift index 75bde2301ce..eb897ed4ba6 100644 --- a/Client/Frontend/Browser/HomePanel/FavoritesViewController.swift +++ b/Client/Frontend/Browser/HomePanel/FavoritesViewController.swift @@ -105,8 +105,6 @@ class FavoritesViewController: UIViewController, Themeable { override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = PrivateBrowsingManager.shared.isPrivateBrowsing ? UX.HomePanel.BackgroundColorPBM : UX.HomePanel.BackgroundColor - let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongGesture(gesture:))) collection.addGestureRecognizer(longPressGesture) @@ -202,10 +200,14 @@ class FavoritesViewController: UIViewController, Themeable { updateDuckDuckGoVisibility() } + var themeableChildren: [Themeable?]? { + return [braveShieldStatsView] + } + func applyTheme(_ theme: Theme) { - let isPrivate = theme == .private - view.backgroundColor = isPrivate ? UX.HomePanel.BackgroundColorPBM : UX.HomePanel.BackgroundColor - braveShieldStatsView.timeStatView.color = isPrivate ? UX.GreyA : UX.GreyJ + styleChildren(theme: theme) + + view.backgroundColor = theme.colors.home } override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { diff --git a/Client/Frontend/Browser/ReaderModeBarView.swift b/Client/Frontend/Browser/ReaderModeBarView.swift index e23b73e96bf..0cda81a027c 100644 --- a/Client/Frontend/Browser/ReaderModeBarView.swift +++ b/Client/Frontend/Browser/ReaderModeBarView.swift @@ -89,6 +89,8 @@ class ReaderModeBarView: UIView { extension ReaderModeBarView: Themeable { func applyTheme(_ theme: Theme) { + styleChildren(theme: theme) + backgroundColor = UIColor.Browser.Background.colorFor(theme) buttonTintColor = UIColor.Browser.Tint.colorFor(theme) } diff --git a/Client/Frontend/Browser/TabTrayButtonExtensions.swift b/Client/Frontend/Browser/TabTrayButtonExtensions.swift index 879efd3f415..9f8eb3eb95f 100644 --- a/Client/Frontend/Browser/TabTrayButtonExtensions.swift +++ b/Client/Frontend/Browser/TabTrayButtonExtensions.swift @@ -28,6 +28,8 @@ class PrivateModeButton: InsetButton, Themeable { } func applyTheme(_ theme: Theme) { + styleChildren(theme: theme) + setTitleColor(UIColor.TabTray.ToolbarButtonTint.colorFor(theme), for: .normal) imageView?.tintColor = tintColor isSelected = theme.isPrivate diff --git a/Client/Frontend/Browser/TabTrayController.swift b/Client/Frontend/Browser/TabTrayController.swift index 6a8a7b19acd..42df8503b04 100644 --- a/Client/Frontend/Browser/TabTrayController.swift +++ b/Client/Frontend/Browser/TabTrayController.swift @@ -194,6 +194,8 @@ class TabCell: UICollectionViewCell, Themeable { } func applyTheme(_ theme: Theme) { + styleChildren(theme: theme) + backgroundHolder.backgroundColor = theme == .private ? UX.HomePanel.BackgroundColorPBM : UX.HomePanel.BackgroundColor screenshotView.backgroundColor = backgroundHolder.backgroundColor if theme == .private { @@ -394,6 +396,8 @@ class TabTrayController: UIViewController, Themeable { } func applyTheme(_ theme: Theme) { + styleChildren(theme: theme) + collectionView?.backgroundColor = TabTrayControllerUX.BackgroundColor.colorFor(theme) collectionView?.visibleCells.compactMap({ $0 as? TabCell }).forEach { $0.applyTheme(theme) } toolbar.applyTheme(theme) @@ -1105,7 +1109,7 @@ extension TabTrayController: UIAdaptivePresentationControllerDelegate, UIPopover } // MARK: - Toolbar -class TrayToolbar: UIView { +class TrayToolbar: UIView, Themeable { fileprivate let toolbarButtonSize = CGSize(width: 44, height: 44) let addTabButton = UIButton(type: .system).then { @@ -1160,12 +1164,17 @@ class TrayToolbar: UIView { required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } + + var themeableChildren: [Themeable?]? { + return [privateModeButton] + } - fileprivate func applyTheme(_ theme: Theme) { + func applyTheme(_ theme: Theme) { + styleChildren(theme: theme) + UIApplication.shared.windows.first?.backgroundColor = TabTrayControllerUX.BackgroundColor.colorFor(theme) addTabButton.tintColor = UIColor.TabTray.ToolbarButtonTint.colorFor(theme) // Needs to be changed doneButton.tintColor = UIColor.TabTray.ToolbarButtonTint.colorFor(theme) backgroundColor = TabTrayControllerUX.BackgroundColor.colorFor(theme) - privateModeButton.applyTheme(theme) } } diff --git a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift index 2edac664379..ef7369fbcc4 100644 --- a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift +++ b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift @@ -274,7 +274,6 @@ extension TabsBarViewController: UICollectionViewDataSource { cell.tabManager = tabManager cell.tab = tab - cell.titleLabel.text = tab.displayTitle cell.currentIndex = indexPath.row cell.separatorLineRight.isHidden = (indexPath.row != tabList.count() - 1) @@ -333,19 +332,11 @@ extension TabsBarViewController: TabManagerDelegate { extension TabsBarViewController: Themeable { func applyTheme(_ theme: Theme) { - switch theme { - case Theme.regular: - view.backgroundColor = BraveUX.GreyB - plusButton.tintColor = BraveUX.GreyI - bottomLine.backgroundColor = UIColor(white: 0.0, alpha: 0.2) - case Theme.private: - view.backgroundColor = BraveUX.Black - plusButton.tintColor = UIColor.white - bottomLine.backgroundColor = UIColor(white: 1.0, alpha: 0.2) - default: - break - } - + styleChildren(theme: theme) + + view.backgroundColor = theme.colors.header + plusButton.tintColor = theme.colors.tints.header + bottomLine.backgroundColor = theme.colors.border.withAlphaComponent(theme.colors.transparencies.borderAlpha) collectionView.backgroundColor = view.backgroundColor } } diff --git a/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift b/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift index dfd8586021d..7bf2282eec2 100644 --- a/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift +++ b/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift @@ -104,16 +104,12 @@ class BottomToolbarView: UIView, ToolbarProtocol { // MARK: - Themeable extension BottomToolbarView: Themeable { + var themeableChildren: [Themeable?]? { + return actionButtons + } + func applyTheme(_ theme: Theme) { - switch theme { - case Theme.regular: - backgroundColor = BraveUX.ToolbarsBackgroundSolidColor - case Theme.private: - backgroundColor = BraveUX.DarkToolbarsBackgroundSolidColor - default: - backgroundColor = BraveUX.DarkToolbarsBackgroundSolidColor - } - - helper?.setTheme(theme: theme, forButtons: actionButtons) + styleChildren(theme: theme) + backgroundColor = theme.colors.footer } } diff --git a/Client/Frontend/Browser/Toolbars/ToolbarButton.swift b/Client/Frontend/Browser/Toolbars/ToolbarButton.swift index 9378ec9349b..87b0f6c77b1 100644 --- a/Client/Frontend/Browser/Toolbars/ToolbarButton.swift +++ b/Client/Frontend/Browser/Toolbars/ToolbarButton.swift @@ -44,6 +44,8 @@ class ToolbarButton: UIButton { extension ToolbarButton: Themeable { func applyTheme(_ theme: Theme) { + styleChildren(theme: theme) + selectedTintColor = UIColor.ToolbarButton.SelectedTint.colorFor(theme) disabledTintColor = UIColor.ToolbarButton.DisabledTint.colorFor(theme) unselectedTintColor = UIColor.Browser.Tint.colorFor(theme) diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift b/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift index 48132c8bc8b..3d0e292ca37 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift @@ -380,22 +380,22 @@ extension TabLocationView: AccessibilityActionsSource { // MARK: - Themeable extension TabLocationView: Themeable { + var themeableChildren: [Themeable?]? { + return [reloadButton] + } + func applyTheme(_ theme: Theme) { - switch theme { - case Theme.regular: - backgroundColor = BraveUX.LocationBarBackgroundColor - case Theme.private: - backgroundColor = BraveUX.LocationBarBackgroundColor_PrivateMode - default: - backgroundColor = BraveUX.LocationBarBackgroundColor_PrivateMode - } - - urlTextField.textColor = UIColor.Browser.Tint.colorFor(theme) - readerModeButton.selectedTintColor = UIColor.TextField.ReaderModeButtonSelected.colorFor(theme) - readerModeButton.unselectedTintColor = UIColor.TextField.ReaderModeButtonUnselected.colorFor(theme) + styleChildren(theme: theme) - reloadButton.applyTheme(theme) - separatorLine.backgroundColor = UIColor.TextField.Separator.colorFor(theme) + backgroundColor = theme.colors.addressBar.withAlphaComponent(theme.colors.transparencies.addressBarAlpha) + + urlTextField.textColor = theme.colors.tints.addressBar + + readerModeButton.unselectedTintColor = theme.colors.tints.header + // TODO: Should probably be dealt with better + readerModeButton.selectedTintColor = theme.colors.tints.header.withAlphaComponent(0.2) + + separatorLine.backgroundColor = theme.colors.border.withAlphaComponent(theme.colors.transparencies.borderAlpha) } } diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift index 1cd67affe8d..a550dda25a2 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift @@ -557,25 +557,20 @@ extension TopToolbarView: AutocompleteTextFieldDelegate { // MARK: - Themeable extension TopToolbarView: Themeable { + var themeableChildren: [Themeable?]? { + return [locationView, locationTextField] + actionButtons + } func applyTheme(_ theme: Theme) { - locationView.applyTheme(theme) - locationTextField?.applyTheme(theme) - actionButtons.forEach { $0.applyTheme(theme) } - tabsButton.applyTheme(theme) + styleChildren(theme: theme) progressBar.setGradientColors(startColor: UIColor.LoadingBar.Start.colorFor(theme), endColor: UIColor.LoadingBar.End.colorFor(theme)) currentTheme = theme - cancelButton.setTitleColor(UIColor.Browser.Tint.colorFor(theme), for: .normal) - switch theme { - case Theme.regular: - backgroundColor = BraveUX.ToolbarsBackgroundSolidColor - case Theme.private: - backgroundColor = BraveUX.DarkToolbarsBackgroundSolidColor - default: - backgroundColor = BraveUX.DarkToolbarsBackgroundSolidColor - } - line.backgroundColor = UIColor.Browser.URLBarDivider.colorFor(theme) + cancelButton.setTitleColor(theme.colors.tints.header, for: .normal) + + backgroundColor = theme.colors.header + line.backgroundColor = theme.colors.border + line.alpha = theme.colors.transparencies.borderAlpha } } diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift b/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift index bb332a5fb22..6d250f0ef0f 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift @@ -71,17 +71,11 @@ class UrlBarTextField: AutocompleteTextField { extension UrlBarTextField: Themeable { func applyTheme(_ theme: Theme) { - switch theme { - case Theme.regular: - backgroundColor = BraveUX.LocationBarBackgroundColor - case Theme.private: - backgroundColor = BraveUX.LocationBarBackgroundColor_PrivateMode - default: - backgroundColor = BraveUX.LocationBarBackgroundColor_PrivateMode - } + styleChildren(theme: theme) - textColor = UIColor.TextField.TextAndTint.colorFor(theme) + backgroundColor = .yellow + textColor = theme.colors.tints.header clearButtonTintColor = textColor - highlightColor = UIColor.TextField.Highlight.colorFor(theme) +// highlightColor = .green } } diff --git a/Client/Frontend/Widgets/TabsButton.swift b/Client/Frontend/Widgets/TabsButton.swift index ba7bc5e62ad..1d693062845 100644 --- a/Client/Frontend/Widgets/TabsButton.swift +++ b/Client/Frontend/Widgets/TabsButton.swift @@ -122,6 +122,8 @@ class TabsButton: UIButton { extension TabsButton: Themeable { func applyTheme(_ theme: Theme) { + styleChildren(theme: theme) + titleBackgroundColor = UIColor.Browser.Background.colorFor(theme) textColor = UIColor.Browser.Tint.colorFor(theme) countLabel.textColor = UIColor.Browser.Tint.colorFor(theme) diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index 30bf6760141..e11f443c2e1 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -6,17 +6,21 @@ import Foundation protocol Themeable { - var themeableChildren: [Themeable]? { get } + var themeableChildren: [Themeable?]? { get } func applyTheme(_ theme: Theme) } extension Themeable { - // Should be explicity done on each Themeable view, but doing this to avoid tons of compile errors - var themeableChildren: [Themeable]? { return nil } + // TODO: Remove, should be explicity done on each Themeable view, but doing this to avoid tons of compile errors + var themeableChildren: [Themeable?]? { return nil } func applyTheme(_ theme: Theme) { - self.themeableChildren?.forEach { $0.applyTheme(theme) } + styleChildren(theme: theme) + } + + func styleChildren(theme: Theme) { + self.themeableChildren?.forEach { $0?.applyTheme(theme) } } } From 6760afbe5f5af7182ed2bdc79cb1a9b4b493fcfb Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 2 Aug 2019 08:25:31 -0400 Subject: [PATCH 05/73] Added some clarifying comments. --- Client/Frontend/Browser/BrowserViewController.swift | 2 +- Client/Frontend/Browser/Toolbars/ToolbarHelper.swift | 1 + Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift | 2 ++ Client/Frontend/UIConstants.swift | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index 35cf2ce84ef..ad549ef28c6 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -2497,7 +2497,7 @@ extension BrowserViewController: ReaderModeBarViewDelegate { let setupPopover = { [unowned self] in if let popoverPresentationController = readerModeStyleViewController.popoverPresentationController { - popoverPresentationController.backgroundColor = UIColor.Photon.White100 + popoverPresentationController.backgroundColor = UIColor.Photon.White100 // todo: dynamic popoverPresentationController.delegate = self popoverPresentationController.sourceView = readerModeBar popoverPresentationController.sourceRect = CGRect(x: readerModeBar.frame.width/2, y: UIConstants.ToolbarHeight, width: 1, height: 1) diff --git a/Client/Frontend/Browser/Toolbars/ToolbarHelper.swift b/Client/Frontend/Browser/Toolbars/ToolbarHelper.swift index a3fdbe6a320..7a8c027ca6f 100644 --- a/Client/Frontend/Browser/Toolbars/ToolbarHelper.swift +++ b/Client/Frontend/Browser/Toolbars/ToolbarHelper.swift @@ -9,6 +9,7 @@ import Shared class ToolbarHelper: NSObject { let toolbar: ToolbarProtocol + // TODO: remove func setTheme(theme: Theme, forButtons buttons: [Themeable]) { buttons.forEach { $0.applyTheme(theme) } } diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift index a550dda25a2..271456782c9 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift @@ -278,6 +278,8 @@ class TopToolbarView: UIView, ToolbarProtocol { } } + /// Created whenever the location bar on top is selected + /// it is "converted" from static to actual TextField private func createLocationTextField() { guard locationTextField == nil else { return } diff --git a/Client/Frontend/UIConstants.swift b/Client/Frontend/UIConstants.swift index e5985f5ce49..bae81259151 100644 --- a/Client/Frontend/UIConstants.swift +++ b/Client/Frontend/UIConstants.swift @@ -29,6 +29,7 @@ struct BrowserColor { } } +// Most of these should be removed extension UIColor { // These are defaults from http://design.firefox.com/photon/visuals/color.html struct Defaults { From f357eb1a8122749afa66be8312ac918b28d797bf Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 2 Aug 2019 16:23:45 -0400 Subject: [PATCH 06/73] Fixed theming issue with home page and tabs. --- Client/Frontend/Browser/BrowserViewController.swift | 1 + Client/Frontend/Browser/TabsBar/TabBarCell.swift | 7 ++++--- .../Frontend/Browser/TabsBar/TabsBarViewController.swift | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index ad549ef28c6..abc1827b80c 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -733,6 +733,7 @@ class BrowserViewController: UIViewController { let homePanelController = FavoritesViewController(profile: profile) homePanelController.delegate = self homePanelController.view.alpha = 0 + homePanelController.applyTheme(Theme.of(tabManager.selectedTab)) self.favoritesViewController = homePanelController diff --git a/Client/Frontend/Browser/TabsBar/TabBarCell.swift b/Client/Frontend/Browser/TabsBar/TabBarCell.swift index 1e81d765f52..d971336e7cc 100644 --- a/Client/Frontend/Browser/TabsBar/TabBarCell.swift +++ b/Client/Frontend/Browser/TabsBar/TabBarCell.swift @@ -90,17 +90,18 @@ class TabBarCell: UICollectionViewCell { override var isSelected: Bool { didSet(selected) { + let theme = Theme.of(tab) closeButton.tintColor = PrivateBrowsingManager.shared.isPrivateBrowsing ? UIColor.white : UIColor.black if selected { titleLabel.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.semibold) closeButton.isHidden = false - titleLabel.textColor = PrivateBrowsingManager.shared.isPrivateBrowsing ? UIColor.white : UIColor.black - backgroundColor = PrivateBrowsingManager.shared.isPrivateBrowsing ? BraveUX.DarkToolbarsBackgroundSolidColor : BraveUX.ToolbarsBackgroundSolidColor + titleLabel.textColor = theme.colors.tints.header + backgroundColor = theme.colors.home } // Prevent swipe and release outside- deselects cell. else if currentIndex != tabManager?.currentDisplayedIndex { titleLabel.font = UIFont.systemFont(ofSize: 12) - titleLabel.textColor = PrivateBrowsingManager.shared.isPrivateBrowsing ? UIColor(white: 1.0, alpha: 0.4) : UIColor(white: 0.0, alpha: 0.4) + titleLabel.textColor = theme.colors.tints.header.withAlphaComponent(0.4) closeButton.isHidden = true backgroundColor = .clear } diff --git a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift index ef7369fbcc4..93cb4b7bfcc 100644 --- a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift +++ b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift @@ -274,6 +274,7 @@ extension TabsBarViewController: UICollectionViewDataSource { cell.tabManager = tabManager cell.tab = tab + cell.titleLabel.text = tab.displayTitle cell.currentIndex = indexPath.row cell.separatorLineRight.isHidden = (indexPath.row != tabList.count() - 1) From 5c9a457fd7b04cc881eefb07ad6f8855dd43c5e5 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Thu, 8 Aug 2019 15:23:54 -1000 Subject: [PATCH 07/73] Unselected TabBarCell now follow addressBar color for deselection. --- Client/Frontend/Browser/TabsBar/TabBarCell.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/Frontend/Browser/TabsBar/TabBarCell.swift b/Client/Frontend/Browser/TabsBar/TabBarCell.swift index d971336e7cc..02bd87d7273 100644 --- a/Client/Frontend/Browser/TabsBar/TabBarCell.swift +++ b/Client/Frontend/Browser/TabsBar/TabBarCell.swift @@ -103,7 +103,7 @@ class TabBarCell: UICollectionViewCell { titleLabel.font = UIFont.systemFont(ofSize: 12) titleLabel.textColor = theme.colors.tints.header.withAlphaComponent(0.4) closeButton.isHidden = true - backgroundColor = .clear + backgroundColor = theme.colors.addressBar } } } From 20ae592a3ac68f92519dc3652e48f7bb837e9136 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Thu, 8 Aug 2019 16:47:32 -1000 Subject: [PATCH 08/73] Fixed up URL / Address bar coloring. --- Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift b/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift index 6d250f0ef0f..7bdfbd48047 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift @@ -73,9 +73,9 @@ extension UrlBarTextField: Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - backgroundColor = .yellow + backgroundColor = theme.colors.addressBar textColor = theme.colors.tints.header clearButtonTintColor = textColor -// highlightColor = .green + highlightColor = textColor!.withAlphaComponent(0.2) } } From f4eaed832ed2090436fb87f22eb139a49f5d8bfd Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 9 Aug 2019 16:26:30 -1000 Subject: [PATCH 09/73] Added `accent` color to theming file. --- Client/Frontend/Widgets/Themes/Theme.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index e11f443c2e1..278d59cb663 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -59,12 +59,14 @@ class Theme: Equatable, Decodable { let homeStr = try container.decode(String.self, forKey: .home) let addressBarStr = try container.decode(String.self, forKey: .addressBar) let borderStr = try container.decode(String.self, forKey: .border) + let accentStr = try container.decode(String.self, forKey: .accent) header = UIColor(colorString: headerStr) footer = UIColor(colorString: footerStr) home = UIColor(colorString: homeStr) addressBar = UIColor(colorString: addressBarStr) border = UIColor(colorString: borderStr) + accent = UIColor(colorString: accentStr) stats = try container.decode(Stat.self, forKey: .stats) tints = try container.decode(Tint.self, forKey: .tints) @@ -76,6 +78,7 @@ class Theme: Equatable, Decodable { let home: UIColor let addressBar: UIColor let border: UIColor + let accent: UIColor let stats: Stat struct Stat: Decodable { @@ -211,6 +214,7 @@ private extension Theme { "home": "0xffffff", "addressBar": "0xD7D7E0", "border": "0x000000", + "accent": "0xccdded", "tints": { "home": "0x434351", "header": "0x434351", @@ -257,6 +261,7 @@ private extension Theme { "home": "0x210950", "addressBar": "0x3D2742", "border": "0xffffff", + "accent": "0xcf68ff", "tints": { "home": "0xE7E6E9", "header": "0xE7E6E9", @@ -301,6 +306,7 @@ fileprivate enum ThemeCodingKeys: String, CodingKey { case home case addressBar case border + case accent case tints enum TintCodingKeys: String, CodingKey { From cb924f4e91191c1ee05666bc5f793c916fc403b3 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 9 Aug 2019 16:27:33 -1000 Subject: [PATCH 10/73] Updated more attributes throughout, removing some now unneeded constant colors. --- Client/Frontend/Browser/BrowserViewController.swift | 1 - Client/Frontend/Browser/ReaderModeBarView.swift | 4 ++-- Client/Frontend/Browser/Toolbars/ToolbarButton.swift | 2 +- Client/Frontend/UIConstants.swift | 10 ---------- Client/Frontend/Widgets/TabsButton.swift | 10 +++++----- 5 files changed, 8 insertions(+), 19 deletions(-) diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index abc1827b80c..3ef38865f07 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -34,7 +34,6 @@ private let KVOs: [KVOConstants] = [ ] private struct BrowserViewControllerUX { - fileprivate static let BackgroundColor = UIConstants.AppBackgroundColor fileprivate static let ShowHeaderTapAreaHeight: CGFloat = 32 fileprivate static let BookmarkStarAnimationDuration: Double = 0.5 fileprivate static let BookmarkStarAnimationOffset: CGFloat = 80 diff --git a/Client/Frontend/Browser/ReaderModeBarView.swift b/Client/Frontend/Browser/ReaderModeBarView.swift index 0cda81a027c..0502bb3d621 100644 --- a/Client/Frontend/Browser/ReaderModeBarView.swift +++ b/Client/Frontend/Browser/ReaderModeBarView.swift @@ -91,7 +91,7 @@ extension ReaderModeBarView: Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - backgroundColor = UIColor.Browser.Background.colorFor(theme) - buttonTintColor = UIColor.Browser.Tint.colorFor(theme) + backgroundColor = theme.colors.home + buttonTintColor = theme.colors.tints.home } } diff --git a/Client/Frontend/Browser/Toolbars/ToolbarButton.swift b/Client/Frontend/Browser/Toolbars/ToolbarButton.swift index 87b0f6c77b1..90cf9a2dbe2 100644 --- a/Client/Frontend/Browser/Toolbars/ToolbarButton.swift +++ b/Client/Frontend/Browser/Toolbars/ToolbarButton.swift @@ -48,7 +48,7 @@ extension ToolbarButton: Themeable { selectedTintColor = UIColor.ToolbarButton.SelectedTint.colorFor(theme) disabledTintColor = UIColor.ToolbarButton.DisabledTint.colorFor(theme) - unselectedTintColor = UIColor.Browser.Tint.colorFor(theme) + unselectedTintColor = theme.colors.tints.home tintColor = isEnabled ? unselectedTintColor : disabledTintColor imageView?.tintColor = tintColor } diff --git a/Client/Frontend/UIConstants.swift b/Client/Frontend/UIConstants.swift index bae81259151..33f0299e2c7 100644 --- a/Client/Frontend/UIConstants.swift +++ b/Client/Frontend/UIConstants.swift @@ -42,17 +42,9 @@ extension UIColor { } struct Browser { - static let Background = BrowserColor(normal: Photon.Grey10, pbm: Photon.Grey70) static let Text = BrowserColor(normal: .white, pbm: Photon.Grey60) static let URLBarDivider = BrowserColor(normal: Photon.Grey90A10, pbm: Photon.Grey60) static let LocationBarBackground = Photon.Grey30 - static let Tint = BrowserColor(normal: Photon.Grey80, pbm: Photon.Grey30) - } - - struct URLBar { - static let Border = BrowserColor(normal: Photon.Grey50, pbm: Photon.Grey80) - static let ActiveBorder = BrowserColor(normal: Photon.Blue50A30, pbm: Photon.Grey60) - static let Tint = BrowserColor(normal: Photon.Blue50A30, pbm: Photon.Grey10) } struct TextField { @@ -62,7 +54,6 @@ extension UIColor { static let ReaderModeButtonSelected = BrowserColor(normal: Photon.Blue40, pbm: Defaults.MobilePrivatePurple) static let ReaderModeButtonUnselected = BrowserColor(normal: Photon.Grey50, pbm: Photon.Grey40) static let PageOptionsSelected = ReaderModeButtonSelected - static let PageOptionsUnselected = UIColor.Browser.Tint static let Separator = BrowserColor(normal: #colorLiteral(red: 0.7333333333, green: 0.7333333333, blue: 0.8039215686, alpha: 1), pbm: Photon.Grey70) } @@ -79,7 +70,6 @@ extension UIColor { } struct TabTray { - static let Background = Browser.Background static let ToolbarButtonTint = BrowserColor(normal: Photon.Grey80, pbm: Photon.Grey30) } diff --git a/Client/Frontend/Widgets/TabsButton.swift b/Client/Frontend/Widgets/TabsButton.swift index 1d693062845..cf8bc95a783 100644 --- a/Client/Frontend/Widgets/TabsButton.swift +++ b/Client/Frontend/Widgets/TabsButton.swift @@ -124,11 +124,11 @@ extension TabsButton: Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - titleBackgroundColor = UIColor.Browser.Background.colorFor(theme) - textColor = UIColor.Browser.Tint.colorFor(theme) - countLabel.textColor = UIColor.Browser.Tint.colorFor(theme) - borderView.color = UIColor.Browser.Tint.colorFor(theme) - labelBackground.backgroundColor = UIColor.Browser.Background.colorFor(theme) + titleBackgroundColor = theme.colors.home + textColor = theme.colors.tints.home + countLabel.textColor = theme.colors.tints.home + borderView.color = theme.colors.tints.home + labelBackground.backgroundColor = theme.colors.home } } From 517f0024637e15ce9c0ee6bad020c86415b72833 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 9 Aug 2019 16:43:14 -1000 Subject: [PATCH 11/73] Removed all `BrowserColor` code. --- .../Browser/BrowserTrayAnimators.swift | 4 +- .../Browser/TabTrayButtonExtensions.swift | 2 +- .../Frontend/Browser/TabTrayController.swift | 14 +++---- .../Browser/Toolbars/ToolbarButton.swift | 4 +- .../Toolbars/UrlBar/TopToolbarView.swift | 3 +- Client/Frontend/UIConstants.swift | 37 +------------------ 6 files changed, 16 insertions(+), 48 deletions(-) diff --git a/Client/Frontend/Browser/BrowserTrayAnimators.swift b/Client/Frontend/Browser/BrowserTrayAnimators.swift index 9c1ef4f2081..b1b115042c2 100644 --- a/Client/Frontend/Browser/BrowserTrayAnimators.swift +++ b/Client/Frontend/Browser/BrowserTrayAnimators.swift @@ -77,7 +77,7 @@ private extension TrayToBrowserAnimator { cell.layer.borderWidth = 0.0 bvc.tabTrayDidDismiss(tabTray) - UIApplication.shared.windows.first?.backgroundColor = TabTrayControllerUX.BackgroundColor.colorFor(tabTray.privateMode ? .private : .regular) + UIApplication.shared.windows.first?.backgroundColor = TabTrayControllerUX.BackgroundColor tabTray.navigationController?.setNeedsStatusBarAppearanceUpdate() tabTray.toolbar.transform = CGAffineTransform(translationX: 0, y: UIConstants.BottomToolbarHeight) tabCollectionViewSnapshot.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) @@ -207,7 +207,7 @@ private extension BrowserToTrayAnimator { cell.frame = finalFrame cell.titleBackgroundView.transform = .identity cell.layoutIfNeeded() - UIApplication.shared.windows.first?.backgroundColor = TabTrayControllerUX.BackgroundColor.colorFor(tabTray.privateMode ? .private : .regular) + UIApplication.shared.windows.first?.backgroundColor = TabTrayControllerUX.BackgroundColor tabTray.navigationController?.setNeedsStatusBarAppearanceUpdate() cell.layer.borderWidth = TabTrayControllerUX.DefaultBorderWidth diff --git a/Client/Frontend/Browser/TabTrayButtonExtensions.swift b/Client/Frontend/Browser/TabTrayButtonExtensions.swift index 9f8eb3eb95f..2884f34ffd6 100644 --- a/Client/Frontend/Browser/TabTrayButtonExtensions.swift +++ b/Client/Frontend/Browser/TabTrayButtonExtensions.swift @@ -30,7 +30,7 @@ class PrivateModeButton: InsetButton, Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - setTitleColor(UIColor.TabTray.ToolbarButtonTint.colorFor(theme), for: .normal) + setTitleColor(UIColor.TabTray.ToolbarButtonTint, for: .normal) imageView?.tintColor = tintColor isSelected = theme.isPrivate accessibilityValue = isSelected ? Strings.TabPrivateModeToggleAccessibilityValueOn : Strings.TabPrivateModeToggleAccessibilityValueOff diff --git a/Client/Frontend/Browser/TabTrayController.swift b/Client/Frontend/Browser/TabTrayController.swift index 42df8503b04..6440053a674 100644 --- a/Client/Frontend/Browser/TabTrayController.swift +++ b/Client/Frontend/Browser/TabTrayController.swift @@ -11,8 +11,8 @@ import BraveShared struct TabTrayControllerUX { static let CornerRadius = CGFloat(6.0) static let DefaultBorderWidth = 1.0 / UIScreen.main.scale - static let BackgroundColor = UIColor.TopTabs.Background - static let CellBackgroundColor = UIColor.TopTabs.Background + static let BackgroundColor = UIColor.Photon.Grey80 + static let CellBackgroundColor = BackgroundColor static let ToolbarFont = UIFont.systemFont(ofSize: 17.0, weight: .medium) static let TextBoxHeight = CGFloat(32.0) static let FaviconSize = CGFloat(20) @@ -398,7 +398,7 @@ class TabTrayController: UIViewController, Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - collectionView?.backgroundColor = TabTrayControllerUX.BackgroundColor.colorFor(theme) + collectionView?.backgroundColor = TabTrayControllerUX.BackgroundColor collectionView?.visibleCells.compactMap({ $0 as? TabCell }).forEach { $0.applyTheme(theme) } toolbar.applyTheme(theme) } @@ -1172,9 +1172,9 @@ class TrayToolbar: UIView, Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - UIApplication.shared.windows.first?.backgroundColor = TabTrayControllerUX.BackgroundColor.colorFor(theme) - addTabButton.tintColor = UIColor.TabTray.ToolbarButtonTint.colorFor(theme) // Needs to be changed - doneButton.tintColor = UIColor.TabTray.ToolbarButtonTint.colorFor(theme) - backgroundColor = TabTrayControllerUX.BackgroundColor.colorFor(theme) + UIApplication.shared.windows.first?.backgroundColor = TabTrayControllerUX.BackgroundColor + addTabButton.tintColor = UIColor.TabTray.ToolbarButtonTint + doneButton.tintColor = UIColor.TabTray.ToolbarButtonTint + backgroundColor = TabTrayControllerUX.BackgroundColor } } diff --git a/Client/Frontend/Browser/Toolbars/ToolbarButton.swift b/Client/Frontend/Browser/Toolbars/ToolbarButton.swift index 90cf9a2dbe2..d44def540ec 100644 --- a/Client/Frontend/Browser/Toolbars/ToolbarButton.swift +++ b/Client/Frontend/Browser/Toolbars/ToolbarButton.swift @@ -46,8 +46,8 @@ extension ToolbarButton: Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - selectedTintColor = UIColor.ToolbarButton.SelectedTint.colorFor(theme) - disabledTintColor = UIColor.ToolbarButton.DisabledTint.colorFor(theme) + selectedTintColor = theme.colors.accent + disabledTintColor = UIColor.Photon.Grey30 // Maybe use accent color + some constant alpha? unselectedTintColor = theme.colors.tints.home tintColor = isEnabled ? unselectedTintColor : disabledTintColor imageView?.tintColor = tintColor diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift index 271456782c9..e6da305505f 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift @@ -566,7 +566,8 @@ extension TopToolbarView: Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - progressBar.setGradientColors(startColor: UIColor.LoadingBar.Start.colorFor(theme), endColor: UIColor.LoadingBar.End.colorFor(theme)) + // Currently do not use gradient, hence same start/end color + progressBar.setGradientColors(startColor: theme.colors.accent, endColor: theme.colors.accent) currentTheme = theme cancelButton.setTitleColor(theme.colors.tints.header, for: .normal) diff --git a/Client/Frontend/UIConstants.swift b/Client/Frontend/UIConstants.swift index 33f0299e2c7..2236c07fa03 100644 --- a/Client/Frontend/UIConstants.swift +++ b/Client/Frontend/UIConstants.swift @@ -35,47 +35,14 @@ extension UIColor { struct Defaults { static let MobileGreyF = UIColor(rgb: 0x636369) static let iOSHighlightBlue = UIColor(rgb: 0xccdded) // This color should exactly match the ios text highlight - static let Purple60A30 = UIColor(rgba: 0x8000d74c) + static let Purple60A30 = UIColor(rgba: 0x8000d74c) // Maybe use this color for private theme?? static let MobilePrivatePurple = UIColor(rgb: 0xcf68ff) static let PaleBlue = UIColor(rgb: 0xB0D5FB) static let LightBeige = UIColor(rgb: 0xf0e6dc) } - struct Browser { - static let Text = BrowserColor(normal: .white, pbm: Photon.Grey60) - static let URLBarDivider = BrowserColor(normal: Photon.Grey90A10, pbm: Photon.Grey60) - static let LocationBarBackground = Photon.Grey30 - } - - struct TextField { - static let Background = BrowserColor(normal: .white, pbm: Defaults.MobileGreyF) - static let TextAndTint = BrowserColor(normal: Photon.Grey80, pbm: .white) - static let Highlight = BrowserColor(normal: Defaults.iOSHighlightBlue, pbm: Defaults.Purple60A30) - static let ReaderModeButtonSelected = BrowserColor(normal: Photon.Blue40, pbm: Defaults.MobilePrivatePurple) - static let ReaderModeButtonUnselected = BrowserColor(normal: Photon.Grey50, pbm: Photon.Grey40) - static let PageOptionsSelected = ReaderModeButtonSelected - static let Separator = BrowserColor(normal: #colorLiteral(red: 0.7333333333, green: 0.7333333333, blue: 0.8039215686, alpha: 1), pbm: Photon.Grey70) - - } - - // The back/forward/refresh/menu button (bottom toolbar) - struct ToolbarButton { - static let SelectedTint = BrowserColor(normal: Photon.Blue40, pbm: Photon.Purple50) - static let DisabledTint = BrowserColor(normal: Photon.Grey30, pbm: Photon.Grey50) - } - - struct LoadingBar { - static let Start = BrowserColor(normal: Photon.Blue50A30, pbm: Photon.Purple50) - static let End = BrowserColor(normal: Photon.Blue50, pbm: Photon.Magenta50) - } - struct TabTray { - static let ToolbarButtonTint = BrowserColor(normal: Photon.Grey80, pbm: Photon.Grey30) - } - - struct TopTabs { - static let PrivateModeTint = BrowserColor(normal: Photon.Grey10, pbm: Photon.Grey40) - static let Background = BrowserColor(normal: Photon.White100, pbm: Photon.Grey80) + static let ToolbarButtonTint = Photon.Grey50 // Could attempt to use some sort of alpha } } From 0abb459b9dbe291c3f008417a65ff04c6fe9edf1 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Mon, 12 Aug 2019 15:41:05 -1000 Subject: [PATCH 12/73] Fixed up tab tray to respect better color theming. --- Client/Frontend/Browser/BrowserTrayAnimators.swift | 4 ++-- .../Frontend/Browser/TabTrayButtonExtensions.swift | 2 +- Client/Frontend/Browser/TabTrayController.swift | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Client/Frontend/Browser/BrowserTrayAnimators.swift b/Client/Frontend/Browser/BrowserTrayAnimators.swift index b1b115042c2..8cd03f10b49 100644 --- a/Client/Frontend/Browser/BrowserTrayAnimators.swift +++ b/Client/Frontend/Browser/BrowserTrayAnimators.swift @@ -77,7 +77,7 @@ private extension TrayToBrowserAnimator { cell.layer.borderWidth = 0.0 bvc.tabTrayDidDismiss(tabTray) - UIApplication.shared.windows.first?.backgroundColor = TabTrayControllerUX.BackgroundColor + UIApplication.shared.windows.first?.backgroundColor = tabTray.collectionView.backgroundColor tabTray.navigationController?.setNeedsStatusBarAppearanceUpdate() tabTray.toolbar.transform = CGAffineTransform(translationX: 0, y: UIConstants.BottomToolbarHeight) tabCollectionViewSnapshot.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) @@ -207,7 +207,7 @@ private extension BrowserToTrayAnimator { cell.frame = finalFrame cell.titleBackgroundView.transform = .identity cell.layoutIfNeeded() - UIApplication.shared.windows.first?.backgroundColor = TabTrayControllerUX.BackgroundColor + UIApplication.shared.windows.first?.backgroundColor = tabTray.collectionView.backgroundColor tabTray.navigationController?.setNeedsStatusBarAppearanceUpdate() cell.layer.borderWidth = TabTrayControllerUX.DefaultBorderWidth diff --git a/Client/Frontend/Browser/TabTrayButtonExtensions.swift b/Client/Frontend/Browser/TabTrayButtonExtensions.swift index 2884f34ffd6..2e250bdaecd 100644 --- a/Client/Frontend/Browser/TabTrayButtonExtensions.swift +++ b/Client/Frontend/Browser/TabTrayButtonExtensions.swift @@ -30,7 +30,7 @@ class PrivateModeButton: InsetButton, Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - setTitleColor(UIColor.TabTray.ToolbarButtonTint, for: .normal) + setTitleColor(theme.colors.home, for: .normal) imageView?.tintColor = tintColor isSelected = theme.isPrivate accessibilityValue = isSelected ? Strings.TabPrivateModeToggleAccessibilityValueOn : Strings.TabPrivateModeToggleAccessibilityValueOff diff --git a/Client/Frontend/Browser/TabTrayController.swift b/Client/Frontend/Browser/TabTrayController.swift index 6440053a674..68e9473d398 100644 --- a/Client/Frontend/Browser/TabTrayController.swift +++ b/Client/Frontend/Browser/TabTrayController.swift @@ -11,8 +11,6 @@ import BraveShared struct TabTrayControllerUX { static let CornerRadius = CGFloat(6.0) static let DefaultBorderWidth = 1.0 / UIScreen.main.scale - static let BackgroundColor = UIColor.Photon.Grey80 - static let CellBackgroundColor = BackgroundColor static let ToolbarFont = UIFont.systemFont(ofSize: 17.0, weight: .medium) static let TextBoxHeight = CGFloat(32.0) static let FaviconSize = CGFloat(20) @@ -293,7 +291,7 @@ class TabTrayController: UIViewController, Themeable { self.collectionView.reloadData() } -// MARK: View Controller Callbacks + // MARK: View Controller Callbacks override func viewDidLoad() { super.viewDidLoad() @@ -398,7 +396,7 @@ class TabTrayController: UIViewController, Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - collectionView?.backgroundColor = TabTrayControllerUX.BackgroundColor + collectionView?.backgroundColor = theme.colors.home collectionView?.visibleCells.compactMap({ $0 as? TabCell }).forEach { $0.applyTheme(theme) } toolbar.applyTheme(theme) } @@ -1172,9 +1170,11 @@ class TrayToolbar: UIView, Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - UIApplication.shared.windows.first?.backgroundColor = TabTrayControllerUX.BackgroundColor + backgroundColor = theme.colors.home + UIApplication.shared.windows.first?.backgroundColor = backgroundColor + addTabButton.tintColor = UIColor.TabTray.ToolbarButtonTint - doneButton.tintColor = UIColor.TabTray.ToolbarButtonTint - backgroundColor = TabTrayControllerUX.BackgroundColor + doneButton.tintColor = addTabButton.tintColor + } } From b8def89d30b1539077878aecccad23bf2f58bacb Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Mon, 12 Aug 2019 16:10:01 -1000 Subject: [PATCH 13/73] Removed TabTray color constants. --- Client/Frontend/Browser/TabTrayController.swift | 2 +- Client/Frontend/UIConstants.swift | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Client/Frontend/Browser/TabTrayController.swift b/Client/Frontend/Browser/TabTrayController.swift index 68e9473d398..86eb5699b7c 100644 --- a/Client/Frontend/Browser/TabTrayController.swift +++ b/Client/Frontend/Browser/TabTrayController.swift @@ -1173,7 +1173,7 @@ class TrayToolbar: UIView, Themeable { backgroundColor = theme.colors.home UIApplication.shared.windows.first?.backgroundColor = backgroundColor - addTabButton.tintColor = UIColor.TabTray.ToolbarButtonTint + addTabButton.tintColor = theme.colors.tints.footer doneButton.tintColor = addTabButton.tintColor } diff --git a/Client/Frontend/UIConstants.swift b/Client/Frontend/UIConstants.swift index 2236c07fa03..9612d3d8927 100644 --- a/Client/Frontend/UIConstants.swift +++ b/Client/Frontend/UIConstants.swift @@ -40,10 +40,6 @@ extension UIColor { static let PaleBlue = UIColor(rgb: 0xB0D5FB) static let LightBeige = UIColor(rgb: 0xf0e6dc) } - - struct TabTray { - static let ToolbarButtonTint = Photon.Grey50 // Could attempt to use some sort of alpha - } } public struct UIConstants { From 77d28078b990b1a27804505fe58e64f071dbb009 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Mon, 12 Aug 2019 16:11:11 -1000 Subject: [PATCH 14/73] Using Theme.of in more necessary places. --- Client/Frontend/Browser/TabTrayController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/Frontend/Browser/TabTrayController.swift b/Client/Frontend/Browser/TabTrayController.swift index 86eb5699b7c..d6058bfa9de 100644 --- a/Client/Frontend/Browser/TabTrayController.swift +++ b/Client/Frontend/Browser/TabTrayController.swift @@ -337,7 +337,7 @@ class TabTrayController: UIViewController, Themeable { NotificationCenter.default.addObserver(self, selector: #selector(appDidBecomeActiveNotification), name: UIApplication.didBecomeActiveNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(dynamicFontChanged), name: .DynamicFontChanged, object: nil) - applyTheme(privateMode ? .private : .regular) + applyTheme(Theme.of(tabManager.selectedTab)) } override func viewWillAppear(_ animated: Bool) { @@ -807,7 +807,7 @@ fileprivate class TabManagerDataSource: NSObject, UICollectionViewDataSource { } tabCell.screenshotView.image = tab.screenshot - tabCell.applyTheme(PrivateBrowsingManager.shared.isPrivateBrowsing ? .private : .regular) + tabCell.applyTheme(Theme.of(tab)) return tabCell } From b4611aa22cc0ac92d2b73cf5d4a255bfd200ce70 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Mon, 12 Aug 2019 16:40:58 -1000 Subject: [PATCH 15/73] Refactored ToolbarButton to be more stylistically flexible. --- .../BottomToolbar/BottomToolbarView.swift | 10 +++--- .../Browser/Toolbars/ToolbarButton.swift | 35 +++++++++++-------- .../Toolbars/UrlBar/TabLocationView.swift | 4 +-- .../Toolbars/UrlBar/TopToolbarView.swift | 12 +++---- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift b/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift index 7bf2282eec2..e3c46969c11 100644 --- a/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift +++ b/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift @@ -11,11 +11,11 @@ class BottomToolbarView: UIView, ToolbarProtocol { weak var tabToolbarDelegate: ToolbarDelegate? let tabsButton = TabsButton() - let forwardButton = ToolbarButton() - let backButton = ToolbarButton() - let shareButton = ToolbarButton() - let addTabButton = ToolbarButton() - let menuButton = ToolbarButton() + let forwardButton = ToolbarButton(top: false) + let backButton = ToolbarButton(top: false) + let shareButton = ToolbarButton(top: false) + let addTabButton = ToolbarButton(top: false) + let menuButton = ToolbarButton(top: false) let actionButtons: [Themeable & UIButton] var helper: ToolbarHelper? diff --git a/Client/Frontend/Browser/Toolbars/ToolbarButton.swift b/Client/Frontend/Browser/Toolbars/ToolbarButton.swift index d44def540ec..c7923466e88 100644 --- a/Client/Frontend/Browser/Toolbars/ToolbarButton.swift +++ b/Client/Frontend/Browser/Toolbars/ToolbarButton.swift @@ -5,17 +5,21 @@ import UIKit class ToolbarButton: UIButton { - var selectedTintColor: UIColor! - var unselectedTintColor: UIColor! - var disabledTintColor: UIColor! + fileprivate var selectedTintColor: UIColor? + fileprivate var primaryTintColor: UIColor? + fileprivate var disabledTintColor: UIColor? - override init(frame: CGRect) { - super.init(frame: frame) + let top: Bool + + required init(top: Bool) { + self.top = top + super.init(frame: .zero) adjustsImageWhenHighlighted = false - selectedTintColor = tintColor - unselectedTintColor = tintColor - disabledTintColor = UIColor.Photon.Grey50 - imageView?.contentMode = .scaleAspectFit //exc bad access + imageView?.contentMode = .scaleAspectFit + } + + override init(frame: CGRect) { + fatalError("init(coder:) has not been implemented") } required init?(coder aDecoder: NSCoder) { @@ -24,13 +28,13 @@ class ToolbarButton: UIButton { override open var isHighlighted: Bool { didSet { - self.tintColor = isHighlighted ? selectedTintColor : unselectedTintColor + self.tintColor = isHighlighted ? selectedTintColor : primaryTintColor } } override open var isEnabled: Bool { didSet { - self.tintColor = isEnabled ? unselectedTintColor : disabledTintColor + self.tintColor = isEnabled ? primaryTintColor : disabledTintColor } } @@ -47,9 +51,10 @@ extension ToolbarButton: Themeable { styleChildren(theme: theme) selectedTintColor = theme.colors.accent - disabledTintColor = UIColor.Photon.Grey30 // Maybe use accent color + some constant alpha? - unselectedTintColor = theme.colors.tints.home - tintColor = isEnabled ? unselectedTintColor : disabledTintColor - imageView?.tintColor = tintColor + primaryTintColor = top ? theme.colors.tints.header : theme.colors.tints.footer + disabledTintColor = primaryTintColor?.withAlphaComponent(0.4) + + // Logic is slightly weird, but necessary for proper styling at launch + tintColor = isEnabled ? primaryTintColor : disabledTintColor } } diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift b/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift index 3d0e292ca37..1458c293c23 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift @@ -161,7 +161,7 @@ class TabLocationView: UIView { return readerModeButton }() - lazy var reloadButton = ToolbarButton().then { + lazy var reloadButton = ToolbarButton(top: true).then { $0.accessibilityIdentifier = "TabToolbar.stopReloadButton" $0.accessibilityLabel = Strings.TabToolbarReloadButtonAccessibilityLabel $0.setImage(#imageLiteral(resourceName: "nav-refresh").template, for: .normal) @@ -172,7 +172,7 @@ class TabLocationView: UIView { } lazy var shieldsButton: ToolbarButton = { - let button = ToolbarButton() + let button = ToolbarButton(top: true) button.setImage(UIImage(imageLiteralResourceName: "shields-menu-icon"), for: .normal) button.addTarget(self, action: #selector(didClickBraveShieldsButton), for: .touchUpInside) button.imageView?.contentMode = .center diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift index e6da305505f..5d6d96219c4 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift @@ -139,11 +139,11 @@ class TopToolbarView: UIView, ToolbarProtocol { return button }() - var bookmarkButton = ToolbarButton() - var forwardButton = ToolbarButton() - var shareButton = ToolbarButton() - var addTabButton = ToolbarButton() - lazy var menuButton = ToolbarButton().then { + var bookmarkButton = ToolbarButton(top: true) + var forwardButton = ToolbarButton(top: true) + var shareButton = ToolbarButton(top: true) + var addTabButton = ToolbarButton(top: true) + lazy var menuButton = ToolbarButton(top: true).then { // $0.contentMode = .center $0.setImage(#imageLiteral(resourceName: "nav-menu").template, for: .normal) $0.accessibilityLabel = Strings.AppMenuButtonAccessibilityLabel @@ -152,7 +152,7 @@ class TopToolbarView: UIView, ToolbarProtocol { } var backButton: ToolbarButton = { - let backButton = ToolbarButton() + let backButton = ToolbarButton(top: true) backButton.accessibilityIdentifier = "TopToolbarView.backButton" return backButton }() From b1c9c52bea11aacf2a1a4cad41e046548a6f496e Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Mon, 12 Aug 2019 17:20:57 -1000 Subject: [PATCH 16/73] Fixed up TabsButton for theming. --- .../Browser/TabTrayButtonExtensions.swift | 2 +- .../BottomToolbar/BottomToolbarView.swift | 2 +- Client/Frontend/Widgets/TabsButton.swift | 69 ++++++++----------- 3 files changed, 31 insertions(+), 42 deletions(-) diff --git a/Client/Frontend/Browser/TabTrayButtonExtensions.swift b/Client/Frontend/Browser/TabTrayButtonExtensions.swift index 2e250bdaecd..61acbcbf9d7 100644 --- a/Client/Frontend/Browser/TabTrayButtonExtensions.swift +++ b/Client/Frontend/Browser/TabTrayButtonExtensions.swift @@ -48,7 +48,7 @@ extension UIButton { extension TabsButton { static func tabTrayButton() -> TabsButton { - let tabsButton = TabsButton() + let tabsButton = TabsButton(top: true) tabsButton.countLabel.text = "0" tabsButton.accessibilityLabel = Strings.Show_Tabs return tabsButton diff --git a/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift b/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift index e3c46969c11..2437837c6ca 100644 --- a/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift +++ b/Client/Frontend/Browser/Toolbars/BottomToolbar/BottomToolbarView.swift @@ -10,7 +10,7 @@ import BraveShared class BottomToolbarView: UIView, ToolbarProtocol { weak var tabToolbarDelegate: ToolbarDelegate? - let tabsButton = TabsButton() + let tabsButton = TabsButton(top: false) let forwardButton = ToolbarButton(top: false) let backButton = ToolbarButton(top: false) let shareButton = ToolbarButton(top: false) diff --git a/Client/Frontend/Widgets/TabsButton.swift b/Client/Frontend/Widgets/TabsButton.swift index cf8bc95a783..9fdd29cd5d6 100644 --- a/Client/Frontend/Widgets/TabsButton.swift +++ b/Client/Frontend/Widgets/TabsButton.swift @@ -7,8 +7,6 @@ import SnapKit import Shared private struct TabsButtonUX { - static let TitleColor: UIColor = UIColor.Photon.Grey80 - static let TitleBackgroundColor: UIColor = UIColor.Photon.White100 static let CornerRadius: CGFloat = 2 static let TitleFont: UIFont = UIConstants.DefaultChromeSmallFontBold static let BorderStrokeWidth: CGFloat = 1.5 @@ -18,33 +16,27 @@ class TabsButton: UIButton { var textColor = UIColor.Photon.White100 { didSet { - countLabel.textColor = textColor - borderView.color = textColor + updateButtonVisuals() } } - var titleBackgroundColor = UIColor.Photon.White100 { - didSet { - labelBackground.backgroundColor = titleBackgroundColor - } - } - var highlightTextColor: UIColor? - var highlightBackgroundColor: UIColor? + + // Explicit, should crash if not setup properly + var highlightTextColor: UIColor! private var currentCount: Int? + private var top: Bool override var isHighlighted: Bool { didSet { - if isHighlighted { - countLabel.textColor = textColor - borderView.color = titleBackgroundColor - labelBackground.backgroundColor = titleBackgroundColor - } else { - countLabel.textColor = textColor - borderView.color = textColor - labelBackground.backgroundColor = titleBackgroundColor - } + updateButtonVisuals() } } + + private func updateButtonVisuals() { + let foregroundColor: UIColor = isHighlighted ? highlightTextColor : textColor + countLabel.textColor = foregroundColor + borderView.color = foregroundColor + } lazy var countLabel: UILabel = { let label = UILabel() @@ -66,6 +58,7 @@ class TabsButton: UIButton { let background = UIView() background.layer.cornerRadius = TabsButtonUX.CornerRadius background.isUserInteractionEnabled = false + background.backgroundColor = .clear return background }() @@ -76,28 +69,27 @@ class TabsButton: UIButton { border.isUserInteractionEnabled = false return border }() - - override init(frame: CGRect) { - super.init(frame: frame) - insideButton.addSubview(labelBackground) - insideButton.addSubview(borderView) - insideButton.addSubview(countLabel) + + required init(top: Bool) { + self.top = top + super.init(frame: .zero) + [labelBackground, borderView, countLabel].forEach(insideButton.addSubview) addSubview(insideButton) isAccessibilityElement = true - accessibilityTraits.insert(.button) + accessibilityTraits.insert(.button) self.accessibilityLabel = Strings.Show_Tabs } + + override init(frame: CGRect) { + fatalError("init(coder:) has not been implemented") + } override func updateConstraints() { super.updateConstraints() - labelBackground.snp.remakeConstraints { (make) -> Void in - make.edges.equalTo(insideButton) - } - borderView.snp.remakeConstraints { (make) -> Void in - make.edges.equalTo(insideButton) - } - countLabel.snp.remakeConstraints { (make) -> Void in - make.edges.equalTo(insideButton) + [labelBackground, borderView, countLabel].forEach { + $0.snp.remakeConstraints { make in + make.edges.equalTo(insideButton) + } } insideButton.snp.remakeConstraints { (make) -> Void in make.size.equalTo(19) @@ -124,11 +116,8 @@ extension TabsButton: Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - titleBackgroundColor = theme.colors.home - textColor = theme.colors.tints.home - countLabel.textColor = theme.colors.tints.home - borderView.color = theme.colors.tints.home - labelBackground.backgroundColor = theme.colors.home + textColor = top ? theme.colors.tints.header : theme.colors.tints.footer + highlightTextColor = theme.colors.accent } } From 3b7c2e963d741ab659c1ac2508d5249eb81cffb3 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Mon, 12 Aug 2019 17:31:27 -1000 Subject: [PATCH 17/73] Fixed reader mode button to use accent color for selection. --- .../Browser/Toolbars/UrlBar/ReaderModeButton.swift | 8 ++++++-- .../Browser/Toolbars/UrlBar/TabLocationView.swift | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/ReaderModeButton.swift b/Client/Frontend/Browser/Toolbars/UrlBar/ReaderModeButton.swift index b3c8e27b43c..b6e27e1bed8 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/ReaderModeButton.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/ReaderModeButton.swift @@ -21,13 +21,13 @@ class ReaderModeButton: UIButton { override var isSelected: Bool { didSet { - self.tintColor = (isHighlighted || isSelected) ? selectedTintColor : unselectedTintColor + updateAppearance() } } override open var isHighlighted: Bool { didSet { - self.tintColor = (isHighlighted || isSelected) ? selectedTintColor : unselectedTintColor + updateAppearance() } } @@ -37,6 +37,10 @@ class ReaderModeButton: UIButton { } } + private func updateAppearance() { + self.tintColor = (isHighlighted || isSelected) ? selectedTintColor : unselectedTintColor + } + private var _readerModeState: ReaderModeState = .unavailable var readerModeState: ReaderModeState { diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift b/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift index 1458c293c23..255185ac5a8 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift @@ -392,8 +392,7 @@ extension TabLocationView: Themeable { urlTextField.textColor = theme.colors.tints.addressBar readerModeButton.unselectedTintColor = theme.colors.tints.header - // TODO: Should probably be dealt with better - readerModeButton.selectedTintColor = theme.colors.tints.header.withAlphaComponent(0.2) + readerModeButton.selectedTintColor = theme.colors.accent separatorLine.backgroundColor = theme.colors.border.withAlphaComponent(theme.colors.transparencies.borderAlpha) } From c93646eb728450c00b030d2a45610ba46769e1c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=C2=A0Buczek?= Date: Sun, 16 Jun 2019 14:19:44 +0200 Subject: [PATCH 18/73] migrate to Swift5/Xcode 11 --- BraveShared/Analytics/UrpService.swift | 18 +++---- Cartfile | 14 +++--- Cartfile.resolved | 12 ++--- Client.xcodeproj/project.pbxproj | 48 +++++++++---------- .../Browser/BrowserViewController.swift | 4 +- .../Browser/Search/SearchSuggestClient.swift | 10 ++-- Client/Utils/FaviconFetcher.swift | 6 +-- 7 files changed, 54 insertions(+), 58 deletions(-) diff --git a/BraveShared/Analytics/UrpService.swift b/BraveShared/Analytics/UrpService.swift index 2dc02bfd04e..a5fcc0565cb 100644 --- a/BraveShared/Analytics/UrpService.swift +++ b/BraveShared/Analytics/UrpService.swift @@ -19,7 +19,7 @@ struct UrpService { let host: String private let apiKey: String - let sessionManager: SessionManager + let sessionManager: Session init?(host: String, apiKey: String) { self.host = host @@ -28,17 +28,13 @@ struct UrpService { guard let hostUrl = try? host.asURL(), let normalizedHost = hostUrl.normalizedHost else { return nil } // Certificate pinning - let serverTrustPolicies: [String: ServerTrustPolicy] = [ - normalizedHost: .pinCertificates( - certificates: ServerTrustPolicy.certificates(), - validateCertificateChain: true, - validateHost: true - ) + let serverTrustPolicies: [String: PinnedCertificatesTrustEvaluator] = [ + normalizedHost: PinnedCertificatesTrustEvaluator() ] - sessionManager = SessionManager( - serverTrustPolicyManager: ServerTrustPolicyManager( - policies: serverTrustPolicies + sessionManager = Session( + serverTrustManager: ServerTrustManager( + evaluators: serverTrustPolicies ) ) } @@ -100,7 +96,7 @@ struct UrpService { } } -extension SessionManager { +extension Session { /// All requests to referral api use PUT method, accept and receive json. func urpApiRequest(endPoint: URL, params: [String: String], completion: @escaping (DataResponse) -> Void) { self.request(endPoint, method: .put, parameters: params, encoding: JSONEncoding.default).responseJSON { response in diff --git a/Cartfile b/Cartfile index 273de0bffc0..c40bfcd6164 100644 --- a/Cartfile +++ b/Cartfile @@ -1,18 +1,18 @@ -github "Alamofire/Alamofire" "4.8.2" +github "Alamofire/Alamofire" "5.0.0-beta.4" github "garvankeeley/Deferred" "9.9.2" github "SnapKit/SnapKit" "5.0.1" github "rs/SDWebImage" "4.4.6" github "swisspol/GCDWebServer" "3.5.2" github "kif-framework/KIF" "v3.7.5" +github "jrendel/SwiftKeychainWrapper" "3.4.0" github "AgileBits/onepassword-app-extension" "add-framework-support" -github "jrendel/SwiftKeychainWrapper" "3.2.0" github "DaveWoodCom/XCGLogger" "7.0.0" -github "cezheng/Fuzi" "2.2.1" -github "SwiftyJSON/SwiftyJSON" "4.2.0" +github "cezheng/Fuzi" "3.1.0" +github "SwiftyJSON/SwiftyJSON" "5.0.0" github "garvankeeley/JSONSchema.swift" "9.9.0" github "path/FastImageCache" "1.5.1" github "facebook/pop" "1.0.12" -github "xmartlabs/Eureka" "4.3.1" -github "venmo/Static" "v3.0.3" +github "xmartlabs/Eureka" "5.0.0" +github "venmo/Static" "v4.0.0" github "brave/brave-rewards-ios" "master" -github "airbnb/lottie-ios" "master" +github "airbnb/lottie-ios" "master" \ No newline at end of file diff --git a/Cartfile.resolved b/Cartfile.resolved index b85352d5870..54d07ef7ccf 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,18 +1,18 @@ github "AgileBits/onepassword-app-extension" "bcc4cc97fed9a6e73fa204f2e61138e353cb3ef7" -github "Alamofire/Alamofire" "4.8.2" +github "Alamofire/Alamofire" "5.0.0-beta.4" github "DaveWoodCom/XCGLogger" "7.0.0" github "SnapKit/SnapKit" "5.0.1" -github "SwiftyJSON/SwiftyJSON" "4.2.0" +github "SwiftyJSON/SwiftyJSON" "5.0.0" github "airbnb/lottie-ios" "531eb22d47a9439a2344fdaf96832189f2c6e925" github "brave/brave-rewards-ios" "8083f6e5619b6b5202866abe1ee47fea6763d4d9" -github "cezheng/Fuzi" "2.2.1" +github "cezheng/Fuzi" "3.1.0" github "facebook/pop" "1.0.12" github "garvankeeley/Deferred" "9.9.2" github "garvankeeley/JSONSchema.swift" "9.9.0" -github "jrendel/SwiftKeychainWrapper" "3.2.0" +github "jrendel/SwiftKeychainWrapper" "3.4.0" github "kif-framework/KIF" "v3.7.5" github "path/FastImageCache" "1.5.1" github "rs/SDWebImage" "4.4.6" github "swisspol/GCDWebServer" "3.5.2" -github "venmo/Static" "v3.0.3" -github "xmartlabs/Eureka" "4.3.1" +github "venmo/Static" "v4.0.0" +github "xmartlabs/Eureka" "5.0.0" diff --git a/Client.xcodeproj/project.pbxproj b/Client.xcodeproj/project.pbxproj index 458f2a8b8b6..929b92cb0dd 100644 --- a/Client.xcodeproj/project.pbxproj +++ b/Client.xcodeproj/project.pbxproj @@ -6795,7 +6795,7 @@ SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Fennec; @@ -6855,7 +6855,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -6916,7 +6916,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -6977,7 +6977,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -6999,7 +6999,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Shared/Shared-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Fennec; }; @@ -7024,7 +7024,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Storage/Storage-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Fennec; }; @@ -7403,7 +7403,7 @@ SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -7470,7 +7470,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -7538,7 +7538,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -7606,7 +7606,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -7932,7 +7932,7 @@ SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -7998,7 +7998,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -8065,7 +8065,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -8132,7 +8132,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -8517,7 +8517,7 @@ PRODUCT_MODULE_NAME = Client; PRODUCT_NAME = Client; SWIFT_OBJC_BRIDGING_HEADER = "$(PROJECT_DIR)/Client-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Firefox; }; @@ -8568,7 +8568,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Shared/Shared-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Firefox; }; @@ -8593,7 +8593,7 @@ SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Storage/Storage-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-O"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Firefox; }; @@ -8933,7 +8933,7 @@ PRODUCT_NAME = Client; SWIFT_ACTIVE_COMPILATION_CONDITIONS = BUDDYBUILD; SWIFT_OBJC_BRIDGING_HEADER = "$(PROJECT_DIR)/Client-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Fennec_Enterprise; }; @@ -8953,7 +8953,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Shared/Shared-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Fennec_Enterprise; }; @@ -8977,7 +8977,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Storage/Storage-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Fennec_Enterprise; }; @@ -9314,7 +9314,7 @@ PRODUCT_MODULE_NAME = Client; PRODUCT_NAME = Client; SWIFT_OBJC_BRIDGING_HEADER = "$(PROJECT_DIR)/Client-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = FirefoxBeta; }; @@ -9364,7 +9364,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Shared/Shared-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = FirefoxBeta; }; @@ -9389,7 +9389,7 @@ SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Storage/Storage-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-O"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = FirefoxBeta; }; @@ -9556,7 +9556,7 @@ PRODUCT_NAME = Client; SWIFT_ACTIVE_COMPILATION_CONDITIONS = BUDDYBUILD; SWIFT_OBJC_BRIDGING_HEADER = "$(PROJECT_DIR)/Client-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Fennec; }; diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index 5328f77ecee..ecb01299463 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -2669,7 +2669,7 @@ extension BrowserViewController: ContextMenuHelperDelegate { application.endBackgroundTask(taskId) }) - Alamofire.request(url).validate(statusCode: 200..<300).response { response in + AF.request(url).validate(statusCode: 200..<300).response { response in // Only set the image onto the pasteboard if the pasteboard hasn't changed since // fetching the image; otherwise, in low-bandwidth situations, // we might be overwriting something that the user has subsequently added. @@ -2702,7 +2702,7 @@ extension BrowserViewController: ContextMenuHelperDelegate { } private func getData(_ url: URL, success: @escaping (Data) -> Void) { - Alamofire.request(url).validate(statusCode: 200..<300).response { response in + AF.request(url).validate(statusCode: 200..<300).response { response in if let data = response.data { success(data) } diff --git a/Client/Frontend/Browser/Search/SearchSuggestClient.swift b/Client/Frontend/Browser/Search/SearchSuggestClient.swift index e6e4e4d8ec9..cfd7cbe9a02 100644 --- a/Client/Frontend/Browser/Search/SearchSuggestClient.swift +++ b/Client/Frontend/Browser/Search/SearchSuggestClient.swift @@ -21,12 +21,12 @@ class SearchSuggestClient { fileprivate weak var request: Request? fileprivate let userAgent: String - lazy fileprivate var alamofire: SessionManager = { + lazy fileprivate var alamofire: Session = { let configuration = URLSessionConfiguration.ephemeral - var defaultHeaders = SessionManager.default.session.configuration.httpAdditionalHeaders ?? [:] + var defaultHeaders = Session.default.session.configuration.httpAdditionalHeaders ?? [:] defaultHeaders["User-Agent"] = self.userAgent configuration.httpAdditionalHeaders = defaultHeaders - return SessionManager(configuration: configuration) + return Session(configuration: configuration) }() init(searchEngine: OpenSearchEngine, userAgent: String) { @@ -45,7 +45,7 @@ class SearchSuggestClient { request = alamofire.request(url!) .validate(statusCode: 200..<300) .responseJSON { response in - if let error = response.result.error { + if let error = response.result as? Error { callback(nil, error as NSError?) return } @@ -53,7 +53,7 @@ class SearchSuggestClient { // The response will be of the following format: // ["foobar",["foobar","foobar2000 mac","foobar skins",...]] // That is, an array of at least two elements: the search term and an array of suggestions. - let array = response.result.value as? NSArray + let array = response.result as Any as? NSArray if array?.count ?? 0 < 2 { let error = NSError(domain: SearchSuggestClientErrorDomain, code: SearchSuggestClientErrorInvalidResponse, userInfo: nil) callback(nil, error) diff --git a/Client/Utils/FaviconFetcher.swift b/Client/Utils/FaviconFetcher.swift index ef1b76b15b0..058f965a73a 100644 --- a/Client/Utils/FaviconFetcher.swift +++ b/Client/Utils/FaviconFetcher.swift @@ -99,13 +99,13 @@ open class FaviconFetcher: NSObject, XMLParserDelegate { return deferred } - lazy fileprivate var alamofire: SessionManager = { + lazy fileprivate var alamofire: Session = { let configuration = URLSessionConfiguration.default - var defaultHeaders = SessionManager.default.session.configuration.httpAdditionalHeaders ?? [:] + var defaultHeaders = Session.default.session.configuration.httpAdditionalHeaders ?? [:] defaultHeaders["User-Agent"] = FaviconFetcher.userAgent configuration.httpAdditionalHeaders = defaultHeaders configuration.timeoutIntervalForRequest = 5 - return SessionManager(configuration: configuration) + return Session(configuration: configuration) }() fileprivate func fetchDataForURL(_ url: URL) -> Deferred> { From afbc261173b7f03f8846a9a2bc64faf3da011a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=C2=A0Buczek?= Date: Wed, 7 Aug 2019 18:16:39 +0200 Subject: [PATCH 19/73] Update Alamofire to beta 7. --- Cartfile | 4 ++-- Cartfile.resolved | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cartfile b/Cartfile index c40bfcd6164..ad326b4d57f 100644 --- a/Cartfile +++ b/Cartfile @@ -1,4 +1,4 @@ -github "Alamofire/Alamofire" "5.0.0-beta.4" +github "Alamofire/Alamofire" "5.0.0-beta.7" github "garvankeeley/Deferred" "9.9.2" github "SnapKit/SnapKit" "5.0.1" github "rs/SDWebImage" "4.4.6" @@ -15,4 +15,4 @@ github "facebook/pop" "1.0.12" github "xmartlabs/Eureka" "5.0.0" github "venmo/Static" "v4.0.0" github "brave/brave-rewards-ios" "master" -github "airbnb/lottie-ios" "master" \ No newline at end of file +github "airbnb/lottie-ios" "master" diff --git a/Cartfile.resolved b/Cartfile.resolved index 54d07ef7ccf..e275a1e5dfb 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,5 +1,5 @@ github "AgileBits/onepassword-app-extension" "bcc4cc97fed9a6e73fa204f2e61138e353cb3ef7" -github "Alamofire/Alamofire" "5.0.0-beta.4" +github "Alamofire/Alamofire" "5.0.0-beta.7" github "DaveWoodCom/XCGLogger" "7.0.0" github "SnapKit/SnapKit" "5.0.1" github "SwiftyJSON/SwiftyJSON" "5.0.0" From a96047525a210603c58961b8084664b52db928d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=C2=A0Buczek?= Date: Wed, 7 Aug 2019 19:18:21 +0200 Subject: [PATCH 20/73] Update tests to swift5, fix SearchSuggestion Alamofire change. --- Client.xcodeproj/project.pbxproj | 79 ++++++++++--------- .../Browser/Search/SearchSuggestClient.swift | 23 +++--- ClientTests/ClientTests.swift | 3 +- 3 files changed, 56 insertions(+), 49 deletions(-) diff --git a/Client.xcodeproj/project.pbxproj b/Client.xcodeproj/project.pbxproj index 929b92cb0dd..5eca7ad8f48 100644 --- a/Client.xcodeproj/project.pbxproj +++ b/Client.xcodeproj/project.pbxproj @@ -7036,7 +7036,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "$(FRAMEWORK_BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Storage/Storage-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = Fennec; @@ -7092,7 +7092,7 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = Fennec; @@ -7140,7 +7140,7 @@ SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; VALIDATE_PRODUCT = YES; }; @@ -7189,7 +7189,7 @@ SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; VALIDATE_PRODUCT = YES; }; @@ -7242,7 +7242,7 @@ SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/XCUITests/XCUITests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_TARGET_NAME = Client; }; name = Fennec; @@ -7285,7 +7285,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_TARGET_NAME = Client; VALIDATE_PRODUCT = YES; }; @@ -7329,7 +7329,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_TARGET_NAME = Client; VALIDATE_PRODUCT = YES; }; @@ -7676,7 +7676,7 @@ SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; @@ -7736,7 +7736,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; VALIDATE_PRODUCT = YES; @@ -7797,7 +7797,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; VALIDATE_PRODUCT = YES; @@ -7858,7 +7858,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; VALIDATE_PRODUCT = YES; @@ -8202,7 +8202,7 @@ SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; @@ -8262,7 +8262,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; VALIDATE_PRODUCT = YES; @@ -8323,7 +8323,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; VALIDATE_PRODUCT = YES; @@ -8384,7 +8384,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; VALIDATE_PRODUCT = YES; @@ -8402,7 +8402,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/UITests/UITests-Bridging-Header.h"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = Fennec; @@ -8535,7 +8535,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "$(BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = ClientTests; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = Firefox; @@ -8547,7 +8547,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "org.allizom.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = UITests; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Firefox; }; @@ -8607,7 +8607,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "$(FRAMEWORK_BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Storage/Storage-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = Firefox; @@ -8619,7 +8619,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "$(FRAMEWORK_BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = L10nSnapshotTests; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_TARGET_NAME = Client; USES_XCTRUNNER = YES; }; @@ -8632,7 +8632,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "$(FRAMEWORK_BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = L10nSnapshotTests; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_TARGET_NAME = Client; USES_XCTRUNNER = YES; }; @@ -8645,7 +8645,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "$(FRAMEWORK_BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = L10nSnapshotTests; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_TARGET_NAME = Client; USES_XCTRUNNER = YES; }; @@ -8695,7 +8695,7 @@ SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; VALIDATE_PRODUCT = YES; }; @@ -8745,7 +8745,7 @@ SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; VALIDATE_PRODUCT = YES; }; @@ -8795,7 +8795,7 @@ SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; VALIDATE_PRODUCT = YES; }; @@ -8994,7 +8994,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "$(BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = ClientTests; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = Fennec_Enterprise; @@ -9010,7 +9010,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/UITests/UITests-Bridging-Header.h"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = Fennec_Enterprise; @@ -9023,7 +9023,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "$(FRAMEWORK_BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Storage/Storage-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = Fennec_Enterprise; @@ -9038,7 +9038,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "$(FRAMEWORK_BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Shared/Shared-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = Fennec_Enterprise; @@ -9050,7 +9050,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "$(FRAMEWORK_BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = L10nSnapshotTests; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_TARGET_NAME = Client; USES_XCTRUNNER = YES; }; @@ -9062,6 +9062,7 @@ LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "$(FRAMEWORK_BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = MarketingUITests; + SWIFT_VERSION = 5.0; }; name = Fennec_Enterprise; }; @@ -9112,7 +9113,7 @@ SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/XCUITests/XCUITests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_TARGET_NAME = Client; }; name = Fennec_Enterprise; @@ -9168,7 +9169,7 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = Fennec_Enterprise; @@ -9183,7 +9184,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "$(FRAMEWORK_BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Shared/Shared-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = Fennec; @@ -9199,7 +9200,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "$(FRAMEWORK_BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Shared/Shared-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = Firefox; @@ -9331,7 +9332,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "$(BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = ClientTests; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = FirefoxBeta; @@ -9343,7 +9344,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "org.allizom.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = UITests; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = FirefoxBeta; }; @@ -9403,7 +9404,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "$(FRAMEWORK_BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Storage/Storage-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = FirefoxBeta; @@ -9419,7 +9420,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "$(FRAMEWORK_BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "$SRCROOT/Shared/Shared-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = FirefoxBeta; @@ -9573,7 +9574,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "$(BASE_BUNDLE_ID).$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = ClientTests; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Client.app/Client"; }; name = Fennec; diff --git a/Client/Frontend/Browser/Search/SearchSuggestClient.swift b/Client/Frontend/Browser/Search/SearchSuggestClient.swift index cfd7cbe9a02..e645a277e78 100644 --- a/Client/Frontend/Browser/Search/SearchSuggestClient.swift +++ b/Client/Frontend/Browser/Search/SearchSuggestClient.swift @@ -45,25 +45,30 @@ class SearchSuggestClient { request = alamofire.request(url!) .validate(statusCode: 200..<300) .responseJSON { response in - if let error = response.result as? Error { + do { + _ = try response.result.get() + } catch { callback(nil, error as NSError?) - return } + + let responseError = NSError(domain: SearchSuggestClientErrorDomain, code: SearchSuggestClientErrorInvalidResponse, userInfo: nil) // The response will be of the following format: // ["foobar",["foobar","foobar2000 mac","foobar skins",...]] // That is, an array of at least two elements: the search term and an array of suggestions. - let array = response.result as Any as? NSArray - if array?.count ?? 0 < 2 { - let error = NSError(domain: SearchSuggestClientErrorDomain, code: SearchSuggestClientErrorInvalidResponse, userInfo: nil) - callback(nil, error) + guard let array = try? response.result.get() as? NSArray else { + callback(nil, responseError) + return + } + + if array.count < 2 { + callback(nil, responseError) return } - let suggestions = array?[1] as? [String] + let suggestions = array[1] as? [String] if suggestions == nil { - let error = NSError(domain: SearchSuggestClientErrorDomain, code: SearchSuggestClientErrorInvalidResponse, userInfo: nil) - callback(nil, error) + callback(nil, responseError) return } diff --git a/ClientTests/ClientTests.swift b/ClientTests/ClientTests.swift index daa1785d303..eea4f179bad 100644 --- a/ClientTests/ClientTests.swift +++ b/ClientTests/ClientTests.swift @@ -72,7 +72,8 @@ class ClientTests: XCTestCase { let expectation = self.expectation(description: "Validate host for \(host)") let request = URLRequest(url: URL(string: "http://\(host):6571/about/license")!) var response: HTTPURLResponse? - Alamofire.request(request).authenticate(usingCredential: WebServer.sharedInstance.credentials).response { (res) -> Void in + + AF.request(request).authenticate(with: WebServer.sharedInstance.credentials).response { (res) -> Void in response = res.response expectation.fulfill() } From e4fc23cb4154ad1674b11537b76b1000ae90cef3 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Tue, 13 Aug 2019 11:49:01 -1000 Subject: [PATCH 21/73] Cleaned up TabsButton creation. --- Client/Frontend/Browser/TabTrayButtonExtensions.swift | 9 --------- .../Browser/Toolbars/UrlBar/TopToolbarView.swift | 6 +----- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/Client/Frontend/Browser/TabTrayButtonExtensions.swift b/Client/Frontend/Browser/TabTrayButtonExtensions.swift index 61acbcbf9d7..ed50f493894 100644 --- a/Client/Frontend/Browser/TabTrayButtonExtensions.swift +++ b/Client/Frontend/Browser/TabTrayButtonExtensions.swift @@ -45,12 +45,3 @@ extension UIButton { return newTab } } - -extension TabsButton { - static func tabTrayButton() -> TabsButton { - let tabsButton = TabsButton(top: true) - tabsButton.countLabel.text = "0" - tabsButton.accessibilityLabel = Strings.Show_Tabs - return tabsButton - } -} diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift index 5d6d96219c4..07ecd8fae31 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift @@ -110,11 +110,7 @@ class TopToolbarView: UIView, ToolbarProtocol { let line = UIView() - lazy var tabsButton: TabsButton = { - let tabsButton = TabsButton.tabTrayButton() - tabsButton.accessibilityIdentifier = "TopToolbarView.tabsButton" - return tabsButton - }() + let tabsButton = TabsButton(top: true) fileprivate lazy var progressBar: GradientProgressBar = { let progressBar = GradientProgressBar() From b1539b22eb54231e7719acfdc24c5d01b8989472 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Tue, 13 Aug 2019 11:49:47 -1000 Subject: [PATCH 22/73] Added theming comment to TabTray for unconventional logic. --- Client/Frontend/Browser/TabTrayController.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Client/Frontend/Browser/TabTrayController.swift b/Client/Frontend/Browser/TabTrayController.swift index d6058bfa9de..c8c91e2382d 100644 --- a/Client/Frontend/Browser/TabTrayController.swift +++ b/Client/Frontend/Browser/TabTrayController.swift @@ -231,6 +231,11 @@ class TabTrayController: UIViewController, Themeable { PrivateBrowsingManager.shared.isPrivateBrowsing = privateMode tabDataSource.tabs = tabManager.tabsForCurrentMode + /* + * This is a little tricky since this menu is one of the only places inside of the appliation + * that has a state without gauranteeing a tab exists. Most UI elements should use `theme` or at the least + * the related tab's theme, here this is not possible, so using hardened values 😕😭 + */ applyTheme(privateMode ? .private : .regular) collectionView?.reloadData() setNeedsStatusBarAppearanceUpdate() From 1c25db381723caa8194400f57799b2667ba59ada Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Tue, 13 Aug 2019 12:33:01 -1000 Subject: [PATCH 23/73] Fixed up the private mode toggle button. --- Client/Frontend/Browser/TabTrayButtonExtensions.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Client/Frontend/Browser/TabTrayButtonExtensions.swift b/Client/Frontend/Browser/TabTrayButtonExtensions.swift index ed50f493894..60e3c83e8fb 100644 --- a/Client/Frontend/Browser/TabTrayButtonExtensions.swift +++ b/Client/Frontend/Browser/TabTrayButtonExtensions.swift @@ -6,11 +6,9 @@ import UIKit import Shared class PrivateModeButton: InsetButton, Themeable { - var light: Bool = false - override var isSelected: Bool { didSet { - backgroundColor = isSelected ? UIColor.Photon.Purple60 : .clear + accessibilityValue = isSelected ? Strings.TabPrivateModeToggleAccessibilityValueOn : Strings.TabPrivateModeToggleAccessibilityValueOff } } @@ -30,10 +28,11 @@ class PrivateModeButton: InsetButton, Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - setTitleColor(theme.colors.home, for: .normal) + setTitleColor(theme.colors.tints.footer, for: .normal) imageView?.tintColor = tintColor isSelected = theme.isPrivate - accessibilityValue = isSelected ? Strings.TabPrivateModeToggleAccessibilityValueOn : Strings.TabPrivateModeToggleAccessibilityValueOff + + backgroundColor = isSelected ? theme.colors.accent : .clear } } From 979d5e621a24433c87ffccb1e5b09e8ab025c839 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Tue, 13 Aug 2019 15:30:26 -1000 Subject: [PATCH 24/73] Updated main menu to support themes. --- .../Browser/BrowserViewController.swift | 8 ++--- .../Menu/MenuViewController.swift | 30 ++++++++++++------- .../Browser/Toolbars/ToolbarHelper.swift | 2 +- .../Browser/Toolbars/ToolbarProtocols.swift | 2 +- .../Popover/PopoverContainerView.swift | 8 +++++ .../Frontend/Popover/PopoverController.swift | 8 +++++ 6 files changed, 42 insertions(+), 16 deletions(-) diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index 3ef38865f07..d3318bb4284 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -1677,9 +1677,7 @@ extension BrowserViewController: TopToolbarDelegate { } func topToolbarDidTapMenuButton(_ topToolbar: TopToolbarView) { - let homePanel = MenuViewController(bvc: self, tab: tabManager.selectedTab) - let popover = PopoverController(contentController: homePanel, contentSizeBehavior: .preferredContentSize) - popover.present(from: topToolbar.menuButton, on: self) + tabToolbarDidPressMenu(topToolbar) } } @@ -1726,9 +1724,11 @@ extension BrowserViewController: ToolbarDelegate { } } - func tabToolbarDidPressMenu(_ tabToolbar: ToolbarProtocol, button: UIButton) { + func tabToolbarDidPressMenu(_ tabToolbar: ToolbarProtocol) { let homePanel = MenuViewController(bvc: self, tab: tabManager.selectedTab) let popover = PopoverController(contentController: homePanel, contentSizeBehavior: .preferredContentSize) + // Not dynamic, but trivial at this point, given how UI is currently setup + popover.color = Theme.of(tabManager.selectedTab).colors.home popover.present(from: tabToolbar.menuButton, on: self) } diff --git a/Client/Frontend/Browser/Toolbars/BottomToolbar/Menu/MenuViewController.swift b/Client/Frontend/Browser/Toolbars/BottomToolbar/Menu/MenuViewController.swift index aa9f704362a..ca1aee55b65 100644 --- a/Client/Frontend/Browser/Toolbars/BottomToolbar/Menu/MenuViewController.swift +++ b/Client/Frontend/Browser/Toolbars/BottomToolbar/Menu/MenuViewController.swift @@ -26,7 +26,6 @@ private class MenuCell: UITableViewCell { $0.trailing.equalTo(self).inset(12) $0.leading.equalTo(iconView.snp.trailing) } - labelView.textColor = .black separatorInset = UIEdgeInsets(top: 0, left: iconLength, bottom: 0, right: 0) } @available(*, unavailable) @@ -66,11 +65,11 @@ class MenuViewController: UITableViewController { var icon: UIImage { switch self { - case .bookmarks: return #imageLiteral(resourceName: "menu_bookmarks") - case .history: return #imageLiteral(resourceName: "menu-history") - case .settings: return #imageLiteral(resourceName: "menu-settings") - case .add: return #imageLiteral(resourceName: "menu-add-bookmark") - case .share: return #imageLiteral(resourceName: "nav-share") + case .bookmarks: return #imageLiteral(resourceName: "menu_bookmarks").template + case .history: return #imageLiteral(resourceName: "menu-history").template + case .settings: return #imageLiteral(resourceName: "menu-settings").template + case .add: return #imageLiteral(resourceName: "menu-add-bookmark").template + case .share: return #imageLiteral(resourceName: "nav-share").template } } } @@ -110,6 +109,7 @@ class MenuViewController: UITableViewController { tableView.separatorColor = UX.separatorColor tableView.rowHeight = UX.rowHeight + tableView.backgroundColor = .clear tableView.contentInset = UIEdgeInsets(top: UX.topBottomInset, left: 0, bottom: UX.topBottomInset, right: 0) @@ -121,10 +121,6 @@ class MenuViewController: UITableViewController { tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 1)) - // TODO: Make the background view transparent with alpha 0.6 - // simple setting its alpha doesn't seem to work. - tableView.backgroundColor = #colorLiteral(red: 0.9529411765, green: 0.9529411765, blue: 0.9647058824, alpha: 1) - let size = CGSize(width: 200, height: UIScreen.main.bounds.height) let fit = view.systemLayoutSizeFitting( @@ -167,12 +163,26 @@ class MenuViewController: UITableViewController { cell.labelView.text = button.title cell.iconView.image = button.icon + + let homeColor = Theme.of(tab).colors.tints.home + cell.iconView.tintColor = homeColor.withAlphaComponent(0.6) + cell.labelView.textColor = homeColor cell.tag = button.rawValue cell.backgroundColor = .clear return cell } + override func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) { + let cell = tableView.cellForRow(at: indexPath) + cell?.contentView.backgroundColor = Theme.of(tab).colors.home.withAlphaComponent(0.5) + } + + override func tableView(_ tableView: UITableView, didUnhighlightRowAt indexPath: IndexPath) { + let cell = tableView.cellForRow(at: indexPath) + cell?.contentView.backgroundColor = .clear + } + // MARK: - Actions private enum DoneButtonPosition { case left, right } diff --git a/Client/Frontend/Browser/Toolbars/ToolbarHelper.swift b/Client/Frontend/Browser/Toolbars/ToolbarHelper.swift index 7a8c027ca6f..615ecf0f603 100644 --- a/Client/Frontend/Browser/Toolbars/ToolbarHelper.swift +++ b/Client/Frontend/Browser/Toolbars/ToolbarHelper.swift @@ -51,7 +51,7 @@ class ToolbarHelper: NSObject { } func didClickMenu() { - toolbar.tabToolbarDelegate?.tabToolbarDidPressMenu(toolbar, button: toolbar.backButton) + toolbar.tabToolbarDelegate?.tabToolbarDidPressMenu(toolbar) } func didClickBack() { diff --git a/Client/Frontend/Browser/Toolbars/ToolbarProtocols.swift b/Client/Frontend/Browser/Toolbars/ToolbarProtocols.swift index 85aa473ca86..0e7cc14da1e 100644 --- a/Client/Frontend/Browser/Toolbars/ToolbarProtocols.swift +++ b/Client/Frontend/Browser/Toolbars/ToolbarProtocols.swift @@ -44,7 +44,7 @@ protocol ToolbarDelegate: class { func tabToolbarDidLongPressBack(_ tabToolbar: ToolbarProtocol, button: UIButton) func tabToolbarDidLongPressForward(_ tabToolbar: ToolbarProtocol, button: UIButton) func tabToolbarDidPressTabs(_ tabToolbar: ToolbarProtocol, button: UIButton) - func tabToolbarDidPressMenu(_ tabToolbar: ToolbarProtocol, button: UIButton) + func tabToolbarDidPressMenu(_ tabToolbar: ToolbarProtocol) func tabToolbarDidLongPressTabs(_ tabToolbar: ToolbarProtocol, button: UIButton) func tabToolbarDidPressShare() func tabToolbarDidPressAddTab(_ tabToolbar: ToolbarProtocol, button: UIButton) diff --git a/Client/Frontend/Popover/PopoverContainerView.swift b/Client/Frontend/Popover/PopoverContainerView.swift index 5881024430b..bb0218f04ca 100644 --- a/Client/Frontend/Popover/PopoverContainerView.swift +++ b/Client/Frontend/Popover/PopoverContainerView.swift @@ -47,6 +47,14 @@ extension PopoverController { } } + /// Color of menu + var color: UIColor? { + didSet { + contentView.backgroundColor = color + shadowView.backgroundColor = color + } + } + /// The view where you will place the content controller's view let contentView = UIView().then { $0.backgroundColor = PopoverUX.backgroundColor diff --git a/Client/Frontend/Popover/PopoverController.swift b/Client/Frontend/Popover/PopoverController.swift index afdd29c4789..2a148c8c607 100644 --- a/Client/Frontend/Popover/PopoverController.swift +++ b/Client/Frontend/Popover/PopoverController.swift @@ -69,6 +69,14 @@ class PopoverController: UIViewController { /// Whether or not to automatically dismiss the popup when the device orientation changes var dismissesOnOrientationChanged = true + /// Defines the desired color for the entire popup menu + /// Child controller may specify their own `backgroundColor`, however arrow/carrot color is also handled here + var color: UIColor? { + didSet { + containerView.color = color + } + } + let contentSizeBehavior: ContentSizeBehavior private var containerViewHeightConstraint: NSLayoutConstraint? From 58b21ae9b055015fc5c29310092fcaed3b9b4dae Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Tue, 13 Aug 2019 20:12:06 -1000 Subject: [PATCH 25/73] Relocated theming json files. --- Client.xcodeproj/project.pbxproj | 20 +++------- Client/Assets/Themes/darkTheme.json | 39 +++++++++++++++++++ Client/Assets/Themes/lightTheme.json | 39 +++++++++++++++++++ Client/Assets/Themes/privateTheme.json | 39 +++++++++++++++++++ Client/Frontend/Widgets/Themes/darkTheme.json | 38 ------------------ .../Frontend/Widgets/Themes/lightTheme.json | 38 ------------------ .../Frontend/Widgets/Themes/privateTheme.json | 38 ------------------ 7 files changed, 123 insertions(+), 128 deletions(-) create mode 100644 Client/Assets/Themes/darkTheme.json create mode 100644 Client/Assets/Themes/lightTheme.json create mode 100644 Client/Assets/Themes/privateTheme.json delete mode 100644 Client/Frontend/Widgets/Themes/darkTheme.json delete mode 100644 Client/Frontend/Widgets/Themes/lightTheme.json delete mode 100644 Client/Frontend/Widgets/Themes/privateTheme.json diff --git a/Client.xcodeproj/project.pbxproj b/Client.xcodeproj/project.pbxproj index ff176f88de2..94b519d0b57 100644 --- a/Client.xcodeproj/project.pbxproj +++ b/Client.xcodeproj/project.pbxproj @@ -438,8 +438,8 @@ 4F514FD41ACD8F2C0022D7EA /* HistoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F514FD31ACD8F2C0022D7EA /* HistoryTests.swift */; }; 4F97573B1AFA6F37006ECC24 /* readerContent.html in Resources */ = {isa = PBXBuildFile; fileRef = 4F9757391AFA6F37006ECC24 /* readerContent.html */; }; 55A747171DC46FC400CE1B57 /* HomePageUITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A747161DC46FC400CE1B57 /* HomePageUITest.swift */; }; - 59350AFB22612D95004D7445 /* DisplayTextFieldTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59350AFA22612D95004D7445 /* DisplayTextFieldTest.swift */; }; 592F521E2217327C0078395E /* HttpCookieExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 592F521D2217327B0078395E /* HttpCookieExtension.swift */; }; + 59350AFB22612D95004D7445 /* DisplayTextFieldTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59350AFA22612D95004D7445 /* DisplayTextFieldTest.swift */; }; 5953AAEF2226E9D800A92DE1 /* HttpCookieExtensionTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5953AAEE2226E9D800A92DE1 /* HttpCookieExtensionTest.swift */; }; 595E0EDB21CAD97C00813D49 /* CookieControl.js in Resources */ = {isa = PBXBuildFile; fileRef = 595E0EDA21CAD97C00813D49 /* CookieControl.js */; }; 595E0EE121CAEF5B00813D49 /* FileManagerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 595E0EE021CAEF5B00813D49 /* FileManagerExtension.swift */; }; @@ -482,12 +482,10 @@ 5D1DC57220AE005400905E5A /* JSInjector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1DC56820AE005400905E5A /* JSInjector.swift */; }; 5D1DC57320AE005400905E5A /* SyncSite.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1DC56920AE005400905E5A /* SyncSite.swift */; }; 5D1DC57420AE005400905E5A /* ios-sync.js in Resources */ = {isa = PBXBuildFile; fileRef = 5D1DC56A20AE005400905E5A /* ios-sync.js */; }; + 5D21AE082303B70E00B30D97 /* Themes in Resources */ = {isa = PBXBuildFile; fileRef = 5D21AE002303B70E00B30D97 /* Themes */; }; 5D24AF8221BA459000F9506A /* BlocklistName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D24AF8121BA459000F9506A /* BlocklistName.swift */; }; 5D24AF8421BA489A00F9506A /* ContentBlocker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D24AF8321BA489A00F9506A /* ContentBlocker.swift */; }; 5D24AF9021BA4D7700F9506A /* ContentBlockerRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D24AF8F21BA4D7700F9506A /* ContentBlockerRegion.swift */; }; - 5D26E8A522E117750015D7E9 /* privateTheme.json in Resources */ = {isa = PBXBuildFile; fileRef = 5D26E8A422E117750015D7E9 /* privateTheme.json */; }; - 5D26E8A722E1177B0015D7E9 /* darkTheme.json in Resources */ = {isa = PBXBuildFile; fileRef = 5D26E8A622E1177A0015D7E9 /* darkTheme.json */; }; - 5D26E8A922E117800015D7E9 /* lightTheme.json in Resources */ = {isa = PBXBuildFile; fileRef = 5D26E8A822E1177F0015D7E9 /* lightTheme.json */; }; 5D6DDEF3214003A6001FF0AE /* DAU.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D6DDEE6214003A6001FF0AE /* DAU.swift */; }; 5D6DDEFE2141B6A1001FF0AE /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D6DDEF62141B6A0001FF0AE /* Preferences.swift */; }; 5D6DDF0021428CF0001FF0AE /* DAUTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D6DDEFF21428CF0001FF0AE /* DAUTests.swift */; }; @@ -1600,9 +1598,9 @@ 5929A9F221B6AF03005ECF8D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; 5929A9F321B6AF0F005ECF8D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Shared.strings; sourceTree = ""; }; 5929A9F421B6AF18005ECF8D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; - 59350AFA22612D95004D7445 /* DisplayTextFieldTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayTextFieldTest.swift; sourceTree = ""; }; 592F521D2217327B0078395E /* HttpCookieExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HttpCookieExtension.swift; sourceTree = ""; }; 59347A7822E22F2000C38919 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/BraveShared.strings"; sourceTree = ""; }; + 59350AFA22612D95004D7445 /* DisplayTextFieldTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayTextFieldTest.swift; sourceTree = ""; }; 5953AAEE2226E9D800A92DE1 /* HttpCookieExtensionTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HttpCookieExtensionTest.swift; sourceTree = ""; }; 595E0EDA21CAD97C00813D49 /* CookieControl.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = CookieControl.js; sourceTree = ""; }; 595E0EE021CAEF5B00813D49 /* FileManagerExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileManagerExtension.swift; sourceTree = ""; }; @@ -1846,12 +1844,10 @@ 5D1DC56820AE005400905E5A /* JSInjector.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSInjector.swift; sourceTree = ""; }; 5D1DC56920AE005400905E5A /* SyncSite.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncSite.swift; sourceTree = ""; }; 5D1DC56A20AE005400905E5A /* ios-sync.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = "ios-sync.js"; sourceTree = ""; }; + 5D21AE002303B70E00B30D97 /* Themes */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Themes; sourceTree = ""; }; 5D24AF8121BA459000F9506A /* BlocklistName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlocklistName.swift; sourceTree = ""; }; 5D24AF8321BA489A00F9506A /* ContentBlocker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentBlocker.swift; sourceTree = ""; }; 5D24AF8F21BA4D7700F9506A /* ContentBlockerRegion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentBlockerRegion.swift; sourceTree = ""; }; - 5D26E8A422E117750015D7E9 /* privateTheme.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = privateTheme.json; sourceTree = ""; }; - 5D26E8A622E1177A0015D7E9 /* darkTheme.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = darkTheme.json; sourceTree = ""; }; - 5D26E8A822E1177F0015D7E9 /* lightTheme.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = lightTheme.json; sourceTree = ""; }; 5D6DDEE6214003A6001FF0AE /* DAU.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DAU.swift; sourceTree = ""; }; 5D6DDEF62141B6A0001FF0AE /* Preferences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = ""; }; 5D6DDEFF21428CF0001FF0AE /* DAUTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DAUTests.swift; sourceTree = ""; }; @@ -3365,9 +3361,6 @@ isa = PBXGroup; children = ( 7B3631E91C244FEE00D12AF9 /* Theme.swift */, - 5D26E8A422E117750015D7E9 /* privateTheme.json */, - 5D26E8A822E1177F0015D7E9 /* lightTheme.json */, - 5D26E8A622E1177A0015D7E9 /* darkTheme.json */, ); path = Themes; sourceTree = ""; @@ -4224,6 +4217,7 @@ D03F8F22200EAC1E003C2224 /* AllFramesAtDocumentStart.js */, D0FCF8041FE4772D004A7995 /* MainFrameAtDocumentEnd.js */, D0FCF8051FE4772D004A7995 /* MainFrameAtDocumentStart.js */, + 5D21AE002303B70E00B30D97 /* Themes */, 3BC659581E5BA505006D560F /* top_sites.json */, 3BC659481E5BA4AE006D560F /* TopSites */, C6345ECA2113B3A000CFB983 /* SearchPlugins */, @@ -5156,14 +5150,12 @@ 3BC659591E5BA505006D560F /* top_sites.json in Resources */, E4B7B7631A793CF20022C5E0 /* CharisSILI.ttf in Resources */, E4CD9F541A71506400318571 /* Reader.html in Resources */, - 5D26E8A722E1177B0015D7E9 /* darkTheme.json in Resources */, C6345ECB2113B3A000CFB983 /* SearchPlugins in Resources */, F930CDAC227000F200A23FE1 /* U2F.js in Resources */, 5D7001C222249F7B00E576FB /* ShortNameToFileMapping.json in Resources */, 4422D55921BFFB7F00BF1855 /* unicode.py in Resources */, 7B2142FE1E5E055000CDD3FC /* InfoPlist.strings in Resources */, E69922171B94E3EF007C480D /* Licenses.html in Resources */, - 5D26E8A522E117750015D7E9 /* privateTheme.json in Resources */, E4CD9F5B1A71506C00318571 /* Reader.css in Resources */, D0FCF8061FE4772D004A7995 /* AllFramesAtDocumentEnd.js in Resources */, 27658273217130D900754B2F /* DigiCertHighAssurance.cer in Resources */, @@ -5187,8 +5179,8 @@ D308EE561CBF0BF5006843F2 /* CertError.css in Resources */, 4422D4AD21BFFB7600BF1855 /* LICENSE in Resources */, E4B7B7641A793CF20022C5E0 /* CharisSILR.ttf in Resources */, + 5D21AE082303B70E00B30D97 /* Themes in Resources */, 4422D56D21BFFB7F00BF1855 /* make_unicode_groups.py in Resources */, - 5D26E8A922E117800015D7E9 /* lightTheme.json in Resources */, E4B7B7681A793CF20022C5E0 /* FiraSans-Bold.ttf in Resources */, E4B7B7781A793CF20022C5E0 /* FiraSans-Italic.ttf in Resources */, 0BA1E00E1B03FB0B007675AF /* NetError.html in Resources */, diff --git a/Client/Assets/Themes/darkTheme.json b/Client/Assets/Themes/darkTheme.json new file mode 100644 index 00000000000..46453f98367 --- /dev/null +++ b/Client/Assets/Themes/darkTheme.json @@ -0,0 +1,39 @@ +{ + "uuid": "C900A41F-2C02-4664-9DE4-C170956339AC", + "title": "Default dark", + "url": "www.brave.com", + "description": "The standard default dark theme", + "thumbnail": "https://www.google.com", + "isDark": true, + "enabled": true, + + "colors": { + "header": "0x1B0C32", + "footer": "0x1B0C32", + "home": "0x210950", + "addressBar": "0x3D2742", + "border": "0xffffff", + "accent": "0xcf68ff", + "tints": { + "home": "0xE7E6E9", + "header": "0xE7E6E9", + "footer": "0xE7E6E9", + "addressBar": "0xE7E6E9" + }, + "transparencies": { + "addressBarAlpha": 1.0, + "borderAlpha": 0.2, + }, + "stats": { + "ads": "0xFA4214", + "trackers": "0xFA4214", + "httpse": "0x9339D4", + "timeSaved": "0xffffff" + } + }, + "images": { + "header": "https://www.google.com", + "footer": "https://www.google.com", + "home": "https://www.google.com", + } +} diff --git a/Client/Assets/Themes/lightTheme.json b/Client/Assets/Themes/lightTheme.json new file mode 100644 index 00000000000..9d9cc1be750 --- /dev/null +++ b/Client/Assets/Themes/lightTheme.json @@ -0,0 +1,39 @@ +{ + "uuid": "ECE618A3-D6FC-45A4-94F2-1793C40AE927", + "title": "Default light", + "url": "www.brave.com", + "description": "The standard default light theme", + "thumbnail": "https://www.google.com", + "isDark": false, + "enabled": true, + + "colors": { + "header": "0xffffff", + "footer": "0xffffff", + "home": "0xffffff", + "addressBar": "0xD7D7E0", + "border": "0x000000", + "accent": "0xccdded", + "tints": { + "home": "0x434351", + "header": "0x434351", + "footer": "0x434351", + "addressBar": "0x434351" + }, + "transparencies": { + "addressBarAlpha": 1.0, + "borderAlpha": 0.2, + }, + "stats": { + "ads": "0xFA4214", + "trackers": "0xFA4214", + "httpse": "0x9339D4", + "timeSaved": "0x222326" + } + }, + "images": { + "header": "https://www.google.com", + "footer": "https://www.google.com", + "home": "https://www.google.com", + } +} diff --git a/Client/Assets/Themes/privateTheme.json b/Client/Assets/Themes/privateTheme.json new file mode 100644 index 00000000000..edb0164d8fc --- /dev/null +++ b/Client/Assets/Themes/privateTheme.json @@ -0,0 +1,39 @@ +{ + "uuid": "D5CB0D9A-5467-432C-AB35-1A78C55CFB41", + "title": "Default private", + "url": "www.brave.com", + "description": "The standard default private theme", + "thumbnail": "https://www.google.com", + "isDark": true, + "enabled": true, + + "colors": { + "header": "0x1B0C32", + "footer": "0x1B0C32", + "home": "0x210950", + "addressBar": "0x3D2742", + "border": "0xffffff", + "accent": "0xcf68ff", + "tints": { + "home": "0xE7E6E9", + "header": "0xE7E6E9", + "footer": "0xE7E6E9", + "addressBar": "0xE7E6E9" + }, + "transparencies": { + "addressBarAlpha": 1.0, + "borderAlpha": 0.2, + }, + "stats": { + "ads": "0xFA4214", + "trackers": "0xFA4214", + "httpse": "0x9339D4", + "timeSaved": "0xffffff" + } + }, + "images": { + "header": "https://www.google.com", + "footer": "https://www.google.com", + "home": "https://www.google.com", + } +} diff --git a/Client/Frontend/Widgets/Themes/darkTheme.json b/Client/Frontend/Widgets/Themes/darkTheme.json deleted file mode 100644 index 5544a63e07c..00000000000 --- a/Client/Frontend/Widgets/Themes/darkTheme.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "uuid": "FAIDSFJELWEF2" - "title": "Default dark", - "url": "www.brave.com", - "description": "The standard default dark theme", - "thumb": "", - "isDark": true, - "enabled": true, - - "colors": { - "header": "0x000000", - "footer": "0x000000", - "home": "0x0A0A0A", - "addressBar": "0x262626", - "border": "0xffffff", - "tints": { - "home": "0xE7E6E9", - "header": "0xE7E6E9", - "footer": "0xE7E6E9", - "addressBar": "0xE7E6E9" - }, - "transparencies": { - "addressBarAlpha": 1.0, - "borderAlpha": 0.2, - }, - "stats": { - "ads": "0xFA4214", - "trackers": "", - "httpse": "0x9339D4", - "timeSaved": "0xffffff" - } - }, - "images": { - "header": "", - "footer": "", - "home": "", - } -} diff --git a/Client/Frontend/Widgets/Themes/lightTheme.json b/Client/Frontend/Widgets/Themes/lightTheme.json deleted file mode 100644 index a701904c480..00000000000 --- a/Client/Frontend/Widgets/Themes/lightTheme.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "uuid": "FAIDSFJELWEF" - "title": "Default light", - "url": "www.brave.com", - "description": "The standard default light theme", - "thumb": "", - "isDark": false, - "enabled": true, - - "colors": { - "header": "0xffffff", - "footer": "0xffffff", - "home": "0xffffff", - "addressBar": "0xD7D7E0", - "border": "0x000000", - "tints": { - "home": "0x434351", - "header": "0x434351", - "footer": "0x434351", - "addressBar": "0x434351" - }, - "transparencies": { - "addressBarAlpha": 1.0, - "borderAlpha": 0.2, - }, - "stats": { - "ads": "0xFA4214", - "trackers": "", - "httpse": "0x9339D4", - "timeSaved": "0x222326" - } - }, - "images": { - "header": "", - "footer": "", - "home": "", - } -} diff --git a/Client/Frontend/Widgets/Themes/privateTheme.json b/Client/Frontend/Widgets/Themes/privateTheme.json deleted file mode 100644 index 39b5d4225cb..00000000000 --- a/Client/Frontend/Widgets/Themes/privateTheme.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "uuid": "FAIDSFJELWEF3" - "title": "Default private", - "url": "www.brave.com", - "description": "The standard default private theme", - "thumb": "", - "isDark": true, - "enabled": true, - - "colors": { - "header": "0x1B0C32", - "footer": "0x1B0C32", - "home": "0x210950", - "addressBar": "0x3D2742", - "border": "0xffffff", - "tints": { - "home": "0xE7E6E9", - "header": "0xE7E6E9", - "footer": "0xE7E6E9", - "addressBar": "0xE7E6E9" - }, - "transparencies": { - "addressBarAlpha": 1.0, - "borderAlpha": 0.2, - }, - "stats": { - "ads": "0xFA4214", - "trackers": "", - "httpse": "0x9339D4", - "timeSaved": "0xffffff" - } - }, - "images": { - "header": "", - "footer": "", - "home": "", - } -} From 616effab9a97d1401449b93d0f33cbd6d69e4416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=C2=A0Buczek?= Date: Thu, 15 Aug 2019 01:26:33 +0200 Subject: [PATCH 26/73] Update bootstrap script and KIF framework. --- Cartfile | 4 ++-- Cartfile.resolved | 2 +- bootstrap.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cartfile b/Cartfile index ad326b4d57f..3904e3b91a0 100644 --- a/Cartfile +++ b/Cartfile @@ -3,8 +3,7 @@ github "garvankeeley/Deferred" "9.9.2" github "SnapKit/SnapKit" "5.0.1" github "rs/SDWebImage" "4.4.6" github "swisspol/GCDWebServer" "3.5.2" -github "kif-framework/KIF" "v3.7.5" -github "jrendel/SwiftKeychainWrapper" "3.4.0" +github "kif-framework/KIF" "v3.7.8" github "AgileBits/onepassword-app-extension" "add-framework-support" github "DaveWoodCom/XCGLogger" "7.0.0" github "cezheng/Fuzi" "3.1.0" @@ -16,3 +15,4 @@ github "xmartlabs/Eureka" "5.0.0" github "venmo/Static" "v4.0.0" github "brave/brave-rewards-ios" "master" github "airbnb/lottie-ios" "master" +github "jrendel/SwiftKeychainWrapper" "3.4.0" diff --git a/Cartfile.resolved b/Cartfile.resolved index e275a1e5dfb..c35f207dbb2 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -10,7 +10,7 @@ github "facebook/pop" "1.0.12" github "garvankeeley/Deferred" "9.9.2" github "garvankeeley/JSONSchema.swift" "9.9.0" github "jrendel/SwiftKeychainWrapper" "3.4.0" -github "kif-framework/KIF" "v3.7.5" +github "kif-framework/KIF" "v3.7.8" github "path/FastImageCache" "1.5.1" github "rs/SDWebImage" "4.4.6" github "swisspol/GCDWebServer" "3.5.2" diff --git a/bootstrap.sh b/bootstrap.sh index e6b5da59a52..62856ad115e 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -54,7 +54,7 @@ if [ ! -z "$XCS_BOT_ID" ]; then CARTHAGE_VERBOSE="--verbose" fi -SWIFT_VERSION=4.2 carthage bootstrap $CARTHAGE_VERBOSE --platform ios --color auto --cache-builds --no-use-binaries +SWIFT_VERSION=5.0 carthage bootstrap $CARTHAGE_VERBOSE --platform ios --color auto --cache-builds --no-use-binaries # Install Node.js dependencies and build user scripts From 705f07e82182e011cbbe3dbbc08ce650f448a006 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Wed, 14 Aug 2019 14:36:21 -1000 Subject: [PATCH 27/73] Added theme file navigation for identifying desired themes. --- Client/Frontend/Widgets/Themes/Theme.swift | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index 278d59cb663..5d6e6a68d7d 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -176,6 +176,17 @@ class Theme: Equatable, Decodable { return PrivateBrowsingManager.shared.isPrivateBrowsing ? .private : .regular } + static func from(id: String) -> Theme? { + + let themePath = Theme.ThemeDirectory.appendingPathComponent(id).path + guard + let themeData = FileManager.default.contents(atPath: themePath), + let theme = try? JSONDecoder().decode(Theme.self, from: themeData) else { + return nil + } + return theme + } + // Maybe wrap in a `mode` struct, however, most UI will only care about theme.data /// Regular browsing. static let regular: Theme = { @@ -189,6 +200,24 @@ class Theme: Equatable, Decodable { return try! JSONDecoder().decode(Theme.self, from: themeData) }() + static let allThemes: [Theme] = { + do { + let filenames = try FileManager.default.contentsOfDirectory(at: Theme.ThemeDirectory, includingPropertiesForKeys: []) + + let final = filenames.filter { + $0.pathExtension == "json" + }.compactMap { + Theme.from(id: $0.lastPathComponent) + }.filter { + $0.enabled + } + + return final + } catch { + fatalError("`Themes` directory is not available!") + } + }() + static func == (lhs: Theme, rhs: Theme) -> Bool { return lhs.uuid == rhs.uuid } From 3fad383818b7dcb200927ec8f9184d905ef0bfcc Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 16 Aug 2019 15:11:53 -1000 Subject: [PATCH 28/73] Wired in settings UI, and created default theming enum to support this. --- BraveShared/BraveStrings.swift | 1 + Client/Application/ClientPreferences.swift | 6 +- ...ACE618A3-D6FC-45A4-94F2-1793C40AE927.json} | 2 +- ...B900A41F-2C02-4664-9DE4-C170956339AC.json} | 2 +- ...C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json} | 2 +- .../Settings/SettingsViewController.swift | 30 ++++++++-- Client/Frontend/Widgets/Themes/Theme.swift | 58 +++++++++++++++++-- 7 files changed, 88 insertions(+), 13 deletions(-) rename Client/Assets/Themes/{lightTheme.json => ACE618A3-D6FC-45A4-94F2-1793C40AE927.json} (95%) rename Client/Assets/Themes/{darkTheme.json => B900A41F-2C02-4664-9DE4-C170956339AC.json} (95%) rename Client/Assets/Themes/{privateTheme.json => C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json} (95%) diff --git a/BraveShared/BraveStrings.swift b/BraveShared/BraveStrings.swift index 9d54d1fdc69..768a683d304 100644 --- a/BraveShared/BraveStrings.swift +++ b/BraveShared/BraveStrings.swift @@ -440,6 +440,7 @@ extension Strings { extension Strings { public static let Block_Popups = NSLocalizedString("BlockPopups", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Block Popups", comment: "Setting to enable popup blocking") public static let Show_Tabs_Bar = NSLocalizedString("ShowTabsBar", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Show Tabs Bar", comment: "Setting to show/hide the tabs bar") + public static let Normal_Mode_Theme = NSLocalizedString("NormalModeTheme", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Theme for Normal Browsing", comment: "Setting to choose the user interface theme for normal browsing mode, contains choices like 'light' or 'dark' themes") public static let Private_Browsing_Only = NSLocalizedString("PrivateBrowsingOnly", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Private Browsing Only", comment: "Setting to keep app in private mode") public static let Brave_Shield_Defaults = NSLocalizedString("BraveShieldDefaults", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Brave Shield Defaults", comment: "Section title for adbblock, tracking protection, HTTPS-E, and cookies") public static let Block_Ads_and_Tracking = NSLocalizedString("BlockAdsAndTracking", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Block Ads & Tracking", comment: "") diff --git a/Client/Application/ClientPreferences.swift b/Client/Application/ClientPreferences.swift index f4df808e4c0..1a2931420ea 100644 --- a/Client/Application/ClientPreferences.swift +++ b/Client/Application/ClientPreferences.swift @@ -41,7 +41,11 @@ extension Preferences { static let blockPopups = Option(key: "general.block-popups", default: true) /// Controls how the tab bar should be shown (or not shown) static let tabBarVisibility = Option(key: "general.tab-bar-visiblity", default: TabBarVisibility.always.rawValue) - + /// Defines the user's normal browsing theme + /// `system`, follows the current OS display mode + static let themeNormalMode = Option(key: "general.normal-mode-theme", default: Theme.DefaultTheme.system.id) + static let themePrivateMode = Option(key: "general.private-mode-theme", default: "") + /// Whether or not a user has enabled Night Mode. /// /// Currently unused diff --git a/Client/Assets/Themes/lightTheme.json b/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json similarity index 95% rename from Client/Assets/Themes/lightTheme.json rename to Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json index 9d9cc1be750..eb32711bab8 100644 --- a/Client/Assets/Themes/lightTheme.json +++ b/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json @@ -1,5 +1,5 @@ { - "uuid": "ECE618A3-D6FC-45A4-94F2-1793C40AE927", + "uuid": "ACE618A3-D6FC-45A4-94F2-1793C40AE927", "title": "Default light", "url": "www.brave.com", "description": "The standard default light theme", diff --git a/Client/Assets/Themes/darkTheme.json b/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json similarity index 95% rename from Client/Assets/Themes/darkTheme.json rename to Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json index 46453f98367..c2c7d5d5e4d 100644 --- a/Client/Assets/Themes/darkTheme.json +++ b/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json @@ -1,5 +1,5 @@ { - "uuid": "C900A41F-2C02-4664-9DE4-C170956339AC", + "uuid": "B900A41F-2C02-4664-9DE4-C170956339AC", "title": "Default dark", "url": "www.brave.com", "description": "The standard default dark theme", diff --git a/Client/Assets/Themes/privateTheme.json b/Client/Assets/Themes/C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json similarity index 95% rename from Client/Assets/Themes/privateTheme.json rename to Client/Assets/Themes/C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json index edb0164d8fc..ed8e86b3ac8 100644 --- a/Client/Assets/Themes/privateTheme.json +++ b/Client/Assets/Themes/C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json @@ -1,5 +1,5 @@ { - "uuid": "D5CB0D9A-5467-432C-AB35-1A78C55CFB41", + "uuid": "C5CB0D9A-5467-432C-AB35-1A78C55CFB41", "title": "Default private", "url": "www.brave.com", "description": "The standard default private theme", diff --git a/Client/Frontend/Settings/SettingsViewController.swift b/Client/Frontend/Settings/SettingsViewController.swift index b517975d14d..611c12eb70c 100644 --- a/Client/Frontend/Settings/SettingsViewController.swift +++ b/Client/Frontend/Settings/SettingsViewController.swift @@ -142,6 +142,13 @@ class SettingsViewController: TableViewController { ] ) + // TODO: This can be further abstracted to align with an entire OptionSelectionVC for both tab and theme visibility + let reloadCell = { (row: Row, displayString: String) in + if let indexPath = self.dataSource.indexPath(rowUUID: row.uuid, sectionUUID: general.uuid) { + self.dataSource.sections[indexPath.section].rows[indexPath.row].detailText = displayString + } + } + if UIDevice.current.userInterfaceIdiom == .pad { general.rows.append( Row(text: Strings.Show_Tabs_Bar, accessory: .switchToggle(value: Preferences.General.tabBarVisibility.value == TabBarVisibility.always.rawValue, { Preferences.General.tabBarVisibility.value = $0 ? TabBarVisibility.always.rawValue : TabBarVisibility.never.rawValue }), cellClass: MultilineValue1Cell.self) @@ -155,10 +162,7 @@ class SettingsViewController: TableViewController { selectedOption: TabBarVisibility(rawValue: Preferences.General.tabBarVisibility.value), optionChanged: { [unowned self] _, option in Preferences.General.tabBarVisibility.value = option.rawValue - - if let indexPath = self.dataSource.indexPath(rowUUID: row.uuid, sectionUUID: general.uuid) { - self.dataSource.sections[indexPath.section].rows[indexPath.row].detailText = option.displayString - } + reloadCell(row, option.displayString) } ) optionsViewController.headerText = Strings.Show_Tabs_Bar @@ -167,6 +171,24 @@ class SettingsViewController: TableViewController { general.rows.append(row) } + let themeSubtitle = Theme.DefaultTheme(rawValue: Preferences.General.themeNormalMode.value)?.displayString + var row = Row(text: Strings.Normal_Mode_Theme, detailText: themeSubtitle, accessory: .disclosureIndicator, cellClass: MultilineSubtitleCell.self) + row.selection = { [unowned self] in + let optionsViewController = OptionSelectionViewController( + options: Theme.DefaultTheme.allCases, + selectedOption: Theme.DefaultTheme(rawValue: Preferences.General.themeNormalMode.value), + optionChanged: { [unowned self] _, option in + Preferences.General.themeNormalMode.value = option.rawValue + reloadCell(row, option.displayString) + + // Update theme! + } + ) + optionsViewController.headerText = Strings.Normal_Mode_Theme + self.navigationController?.pushViewController(optionsViewController, animated: true) + } + general.rows.append(row) + return general }() diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index 5d6e6a68d7d..3fda6de3604 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -25,6 +25,44 @@ extension Themeable { } class Theme: Equatable, Decodable { + + enum ThemeError: Error { + case invalidTheme(id: String) + } + + enum DefaultTheme: String, CaseIterable, RepresentableOptionType { + case system = "Z71ED37E-EC3E-436E-AD5F-B22748306A6B" + case light = "ACE618A3-D6FC-45A4-94F2-1793C40AE927" + case dark = "B900A41F-2C02-4664-9DE4-C170956339AC" + case `private` = "C5CB0D9A-5467-432C-AB35-1A78C55CFB41" + +// let id: String +// private init(id: String) { +// self.id = id +// } + + // TODO: Remove with `rawValue` + var id: String { + return self.rawValue + } + + var theme: Theme? { + return try? Theme.from(id: self.id) + } + + static var normalThemes: [Theme] { + return [DefaultTheme.light.theme, DefaultTheme.dark.theme].compactMap { $0 } + } + + public var displayString: String { + if self == .system { + return "System Theme" + } + return self.theme?.title ?? self.id + } + } + + fileprivate static let ThemeDirectory = Bundle.main.resourceURL!.appendingPathComponent("Themes") required init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: ThemeCodingKeys.self) @@ -154,6 +192,7 @@ class Theme: Equatable, Decodable { return description } + // This should be removed probably /// Returns whether the theme is private or not. var isPrivate: Bool { return self.isDark @@ -176,14 +215,21 @@ class Theme: Equatable, Decodable { return PrivateBrowsingManager.shared.isPrivateBrowsing ? .private : .regular } - static func from(id: String) -> Theme? { + static var themeMemoryBank: [String: Theme] = [:] + static func from(id: String) throws -> Theme { + + if let inMemoryTheme = themeMemoryBank[id] { + return inMemoryTheme + } - let themePath = Theme.ThemeDirectory.appendingPathComponent(id).path + let themePath = Theme.ThemeDirectory.appendingPathComponent(id).appendingPathExtension("json").path guard let themeData = FileManager.default.contents(atPath: themePath), let theme = try? JSONDecoder().decode(Theme.self, from: themeData) else { - return nil + throw ThemeError.invalidTheme(id: id) } + + themeMemoryBank[id] = theme return theme } @@ -206,8 +252,10 @@ class Theme: Equatable, Decodable { let final = filenames.filter { $0.pathExtension == "json" - }.compactMap { - Theme.from(id: $0.lastPathComponent) + }.compactMap { fullPath -> Theme? in + var path = fullPath.lastPathComponent + path.removeLast(5) // Removing JSON extension + return try? Theme.from(id: path) }.filter { $0.enabled } From a9b317a0d985ca36451faac51454de7be796d65c Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 16 Aug 2019 15:47:14 -1000 Subject: [PATCH 29/73] Actually use preference for setting theme! --- .../Browser/BrowserViewController.swift | 7 ++- Client/Frontend/Widgets/Themes/Theme.swift | 46 ++++++++++--------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index f1cf965d720..6fdb055a52d 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -200,6 +200,7 @@ class BrowserViewController: UIViewController { // Observe some user preferences Preferences.Privacy.privateBrowsingOnly.observe(from: self) Preferences.General.tabBarVisibility.observe(from: self) + Preferences.General.themeNormalMode.observe(from: self) Preferences.Shields.allShields.forEach { $0.observe(from: self) } Preferences.Privacy.blockAllCookies.observe(from: self) // Lists need to be compiled before attempting tab restoration @@ -2024,6 +2025,8 @@ extension BrowserViewController: TabManagerDelegate { topToolbar.hideProgressBar() } + // TODO: Theme: Maybe check against Theme instead of type?? + // TODO: Theme: store past theme and block if change unneeded if tab.type != previous?.type { let theme = Theme.of(tab) applyTheme(theme) @@ -2933,7 +2936,7 @@ extension BrowserViewController: Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - // Maybe just set to clear color? + // TODO: Theme: Maybe just set to clear color? statusBarOverlay.backgroundColor = topToolbar.backgroundColor setNeedsStatusBarAppearanceUpdate() } @@ -3061,6 +3064,8 @@ extension BrowserViewController: PreferencesObserver { switch key { case Preferences.General.tabBarVisibility.key: updateTabsBarVisibility() + case Preferences.General.themeNormalMode.key: + applyTheme(Theme.of(tabManager.selectedTab)) case Preferences.Privacy.privateBrowsingOnly.key: let isPrivate = Preferences.Privacy.privateBrowsingOnly.value switchToPrivacyMode(isPrivate: isPrivate) diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index 3fda6de3604..1a423d1c953 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import Foundation +import BraveShared protocol Themeable { @@ -26,28 +27,19 @@ extension Themeable { class Theme: Equatable, Decodable { - enum ThemeError: Error { - case invalidTheme(id: String) - } - enum DefaultTheme: String, CaseIterable, RepresentableOptionType { case system = "Z71ED37E-EC3E-436E-AD5F-B22748306A6B" case light = "ACE618A3-D6FC-45A4-94F2-1793C40AE927" case dark = "B900A41F-2C02-4664-9DE4-C170956339AC" case `private` = "C5CB0D9A-5467-432C-AB35-1A78C55CFB41" -// let id: String -// private init(id: String) { -// self.id = id -// } - - // TODO: Remove with `rawValue` + // TODO: Theme: Remove with `rawValue` var id: String { return self.rawValue } - var theme: Theme? { - return try? Theme.from(id: self.id) + var theme: Theme { + return Theme.from(id: self.id) } static var normalThemes: [Theme] { @@ -58,7 +50,7 @@ class Theme: Equatable, Decodable { if self == .system { return "System Theme" } - return self.theme?.title ?? self.id + return self.theme.title } } @@ -203,20 +195,31 @@ class Theme: Equatable, Decodable { /// - parameter tab: An object representing a Tab. /// - returns: A Tab theme. static func of(_ tab: Tab?) -> Theme { - if let tab = tab { + guard let tab = tab else { + // TODO: Theme: Fix this + return PrivateBrowsingManager.shared.isPrivateBrowsing ? .private : .regular + } + + let themeType = { () -> Preferences.Option in switch TabType.of(tab) { case .regular: - return .regular + return Preferences.General.themeNormalMode case .private: - return .private - + return Preferences.General.themePrivateMode } - } - return PrivateBrowsingManager.shared.isPrivateBrowsing ? .private : .regular + }() + + let chosenTheme = DefaultTheme(rawValue: themeType.value) + return chosenTheme?.theme ?? DefaultTheme.system.theme } static var themeMemoryBank: [String: Theme] = [:] - static func from(id: String) throws -> Theme { + static func from(id: String) -> Theme { + var id = id + if id == DefaultTheme.system.id { + // TODO: Pull system default, not 'light' necessarily + id = DefaultTheme.light.id + } if let inMemoryTheme = themeMemoryBank[id] { return inMemoryTheme @@ -226,7 +229,8 @@ class Theme: Equatable, Decodable { guard let themeData = FileManager.default.contents(atPath: themePath), let theme = try? JSONDecoder().decode(Theme.self, from: themeData) else { - throw ThemeError.invalidTheme(id: id) + // TODO: Theme: Maybe throw error, but fallback to `system` / default / light + fatalError("Theme file not found for: \(id)... no good") } themeMemoryBank[id] = theme From f19172fe1f419adc61d59ecaee435b7366ea9db7 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 16 Aug 2019 16:25:21 -1000 Subject: [PATCH 30/73] Updated JSON file for dark mode. --- .../B900A41F-2C02-4664-9DE4-C170956339AC.json | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json b/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json index c2c7d5d5e4d..e801dbcdf5f 100644 --- a/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json +++ b/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json @@ -8,12 +8,12 @@ "enabled": true, "colors": { - "header": "0x1B0C32", - "footer": "0x1B0C32", - "home": "0x210950", - "addressBar": "0x3D2742", + "header": "0x000000", + "footer": "0x000000", + "home": "0x0A0A0A", + "addressBar": "0x262626", "border": "0xffffff", - "accent": "0xcf68ff", + "accent": "0xff631c", "tints": { "home": "0xE7E6E9", "header": "0xE7E6E9", @@ -26,7 +26,7 @@ }, "stats": { "ads": "0xFA4214", - "trackers": "0xFA4214", + "trackers": "", "httpse": "0x9339D4", "timeSaved": "0xffffff" } @@ -37,3 +37,4 @@ "home": "https://www.google.com", } } + From f94b3ffd487f4282fbfe77729b0b8cc1f65e7101 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 16 Aug 2019 16:25:49 -1000 Subject: [PATCH 31/73] Updated the theme preference for private mode with correct UUID. --- Client/Application/ClientPreferences.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/Application/ClientPreferences.swift b/Client/Application/ClientPreferences.swift index 1a2931420ea..738ff518110 100644 --- a/Client/Application/ClientPreferences.swift +++ b/Client/Application/ClientPreferences.swift @@ -44,7 +44,7 @@ extension Preferences { /// Defines the user's normal browsing theme /// `system`, follows the current OS display mode static let themeNormalMode = Option(key: "general.normal-mode-theme", default: Theme.DefaultTheme.system.id) - static let themePrivateMode = Option(key: "general.private-mode-theme", default: "") + static let themePrivateMode = Option(key: "general.private-mode-theme", default: "C5CB0D9A-5467-432C-AB35-1A78C55CFB41") /// Whether or not a user has enabled Night Mode. /// From ea3a9926b565775973a43303f05a52271b6cd289 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 16 Aug 2019 16:28:34 -1000 Subject: [PATCH 32/73] Updated prefferedStatusBarStyle. --- .../Frontend/Browser/BrowserViewController.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index 6fdb055a52d..9b37204fc75 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -208,14 +208,18 @@ class BrowserViewController: UIViewController { } override var preferredStatusBarStyle: UIStatusBarStyle { - switch Theme.of(tabManager.selectedTab) { - case Theme.regular: - return .default - case Theme.private: - return .lightContent - default: + let isDark = Theme.of(tabManager.selectedTab).isDark + if isDark { return .lightContent } + + // Light content, so using other status bar options + + if #available(iOS 13.0, *) { + return .darkContent + } + + return .default } func shouldShowFooterForTraitCollection(_ previousTraitCollection: UITraitCollection) -> Bool { From 381ab4579db8a13019c52d129d93031b0ed857da Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 16 Aug 2019 16:29:06 -1000 Subject: [PATCH 33/73] Removed stale reference to tab.theme, which was never used. --- Client/Frontend/Browser/Tab.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Client/Frontend/Browser/Tab.swift b/Client/Frontend/Browser/Tab.swift index 45ce9340fd0..39163cbd8a6 100644 --- a/Client/Frontend/Browser/Tab.swift +++ b/Client/Frontend/Browser/Tab.swift @@ -55,8 +55,6 @@ class Tab: NSObject { return type.isPrivate } - var theme: Theme = Theme.regular - var contentIsSecure = false var tabState: TabState { From 61c4ca50cbb40e8b968c22881114b3bde1022e5a Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 16 Aug 2019 16:29:31 -1000 Subject: [PATCH 34/73] Removed hardcoded theme reference to top toolbar. --- .../Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift index 07ecd8fae31..60b82ae091d 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift @@ -66,7 +66,7 @@ class TopToolbarView: UIView, ToolbarProtocol { } } - fileprivate var currentTheme: Theme = .regular + fileprivate var currentTheme: Theme? var toolbarIsShowing = false @@ -303,7 +303,10 @@ class TopToolbarView: UIView, ToolbarProtocol { make.edges.equalTo(self.locationView).inset(insets) } - locationTextField.applyTheme(currentTheme) + if let theme = currentTheme { + // If no theme exists here, then this will be styled after parent calls `applyTheme` at a later point + locationTextField.applyTheme(theme) + } } override func becomeFirstResponder() -> Bool { From 2fea40fee1173dafe15f4f634491af5d1c799702 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 16 Aug 2019 16:56:15 -1000 Subject: [PATCH 35/73] Switched over to solely using dynamic themes. Better support for tab tray theme. --- .../Browser/BrowserTrayAnimators.swift | 2 +- .../Frontend/Browser/TabTrayController.swift | 18 +-- .../Browser/Toolbars/ToolbarHelper.swift | 7 - Client/Frontend/Widgets/Themes/Theme.swift | 127 ++---------------- 4 files changed, 19 insertions(+), 135 deletions(-) diff --git a/Client/Frontend/Browser/BrowserTrayAnimators.swift b/Client/Frontend/Browser/BrowserTrayAnimators.swift index 8cd03f10b49..bf9923ddc28 100644 --- a/Client/Frontend/Browser/BrowserTrayAnimators.swift +++ b/Client/Frontend/Browser/BrowserTrayAnimators.swift @@ -344,7 +344,7 @@ private func createTransitionCellFromTab(_ tab: Tab?, withFrame frame: CGRect) - } else { cell.favicon.image = #imageLiteral(resourceName: "defaultFavicon") } - cell.applyTheme(PrivateBrowsingManager.shared.isPrivateBrowsing ? .private : .regular) + cell.applyTheme(Theme.of(tab)) return cell } diff --git a/Client/Frontend/Browser/TabTrayController.swift b/Client/Frontend/Browser/TabTrayController.swift index c8c91e2382d..c1cdaac4242 100644 --- a/Client/Frontend/Browser/TabTrayController.swift +++ b/Client/Frontend/Browser/TabTrayController.swift @@ -194,11 +194,9 @@ class TabCell: UICollectionViewCell, Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - backgroundHolder.backgroundColor = theme == .private ? UX.HomePanel.BackgroundColorPBM : UX.HomePanel.BackgroundColor + backgroundHolder.backgroundColor = theme.colors.home screenshotView.backgroundColor = backgroundHolder.backgroundColor - if theme == .private { - favicon.tintColor = UIColor.Photon.White100 - } + favicon.tintColor = theme.colors.tints.home } } @@ -228,15 +226,15 @@ class TabTrayController: UIViewController, Themeable { fileprivate(set) internal var privateMode: Bool = false { didSet { + // Should be set immediately before other logic executes PrivateBrowsingManager.shared.isPrivateBrowsing = privateMode - tabDataSource.tabs = tabManager.tabsForCurrentMode /* * This is a little tricky since this menu is one of the only places inside of the appliation * that has a state without gauranteeing a tab exists. Most UI elements should use `theme` or at the least * the related tab's theme, here this is not possible, so using hardened values 😕😭 */ - applyTheme(privateMode ? .private : .regular) + applyTheme(Theme.of(nil)) collectionView?.reloadData() setNeedsStatusBarAppearanceUpdate() } @@ -398,12 +396,14 @@ class TabTrayController: UIViewController, Themeable { } } + var themeableChildren: [Themeable?]? { + let cells = collectionView?.visibleCells.compactMap({ $0 as? TabCell }) ?? [] + return [toolbar] + cells + } + func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - collectionView?.backgroundColor = theme.colors.home - collectionView?.visibleCells.compactMap({ $0 as? TabCell }).forEach { $0.applyTheme(theme) } - toolbar.applyTheme(theme) } /// Reset the empty private browsing state (hide the details, unhide the learn more button) if it was changed diff --git a/Client/Frontend/Browser/Toolbars/ToolbarHelper.swift b/Client/Frontend/Browser/Toolbars/ToolbarHelper.swift index 615ecf0f603..e20364b5354 100644 --- a/Client/Frontend/Browser/Toolbars/ToolbarHelper.swift +++ b/Client/Frontend/Browser/Toolbars/ToolbarHelper.swift @@ -9,11 +9,6 @@ import Shared class ToolbarHelper: NSObject { let toolbar: ToolbarProtocol - // TODO: remove - func setTheme(theme: Theme, forButtons buttons: [Themeable]) { - buttons.forEach { $0.applyTheme(theme) } - } - init(toolbar: ToolbarProtocol) { self.toolbar = toolbar super.init() @@ -46,8 +41,6 @@ class ToolbarHelper: NSObject { let longPressGestureForwardButton = UILongPressGestureRecognizer(target: self, action: #selector(didLongPressForward)) toolbar.forwardButton.addGestureRecognizer(longPressGestureForwardButton) toolbar.forwardButton.addTarget(self, action: #selector(didClickForward), for: .touchUpInside) - - setTheme(theme: .regular, forButtons: toolbar.actionButtons) } func didClickMenu() { diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index 1a423d1c953..11e7283f0cc 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -175,10 +175,6 @@ class Theme: Equatable, Decodable { let home: URL } - lazy var available: [Theme] = { - return [Theme.regular, Theme.private] - }() - /// Textual representation suitable for debugging. var debugDescription: String { return description @@ -195,10 +191,14 @@ class Theme: Equatable, Decodable { /// - parameter tab: An object representing a Tab. /// - returns: A Tab theme. static func of(_ tab: Tab?) -> Theme { - guard let tab = tab else { - // TODO: Theme: Fix this - return PrivateBrowsingManager.shared.isPrivateBrowsing ? .private : .regular - } + guard let tab = tab else { + // This is important, used when switching modes when no tab is present + // TODO: Theme: unit test + let themeBasedOnMode = PrivateBrowsingManager.shared.isPrivateBrowsing + ? Preferences.General.themePrivateMode + : Preferences.General.themeNormalMode + return Theme.from(id: themeBasedOnMode.value) + } let themeType = { () -> Preferences.Option in switch TabType.of(tab) { @@ -237,19 +237,6 @@ class Theme: Equatable, Decodable { return theme } - // Maybe wrap in a `mode` struct, however, most UI will only care about theme.data - /// Regular browsing. - static let regular: Theme = { - let themeData = normalTheme().data(using: String.Encoding.utf8)! - return try! JSONDecoder().decode(Theme.self, from: themeData) - }() - - /// Private browsing. - static let `private`: Theme = { - let themeData = privateTheme().data(using: String.Encoding.utf8)! - return try! JSONDecoder().decode(Theme.self, from: themeData) - }() - static let allThemes: [Theme] = { do { let filenames = try FileManager.default.contentsOfDirectory(at: Theme.ThemeDirectory, includingPropertiesForKeys: []) @@ -259,7 +246,7 @@ class Theme: Equatable, Decodable { }.compactMap { fullPath -> Theme? in var path = fullPath.lastPathComponent path.removeLast(5) // Removing JSON extension - return try? Theme.from(id: path) + return Theme.from(id: path) }.filter { $0.enabled } @@ -275,102 +262,6 @@ class Theme: Equatable, Decodable { } } -private extension Theme { - - static func normalTheme() -> String { - return """ - - { - "uuid": "FAIDSFJELWEF", - "title": "Default light", - "url": "www.brave.com", - "description": "The standard default light theme", - "thumbnail": "https://www.google.com", - "isDark": false, - "enabled": true, - - "colors": { - "header": "0xffffff", - "footer": "0xffffff", - "home": "0xffffff", - "addressBar": "0xD7D7E0", - "border": "0x000000", - "accent": "0xccdded", - "tints": { - "home": "0x434351", - "header": "0x434351", - "footer": "0x434351", - "addressBar": "0x434351" - }, - "transparencies": { - "addressBarAlpha": 1.0, - "borderAlpha": 0.2, - }, - "stats": { - "ads": "0xFA4214", - "trackers": "0xFA4214", - "httpse": "0x9339D4", - "timeSaved": "0x222326" - } - }, - "images": { - "header": "https://www.google.com", - "footer": "https://www.google.com", - "home": "https://www.google.com", - } - } - - - - """ - } - - static func privateTheme() -> String { - return """ - { - "uuid": "FAIDSFJELWEF3", - "title": "Default private", - "url": "www.brave.com", - "description": "The standard default private theme", - "thumbnail": "https://www.google.com", - "isDark": true, - "enabled": true, - - "colors": { - "header": "0x1B0C32", - "footer": "0x1B0C32", - "home": "0x210950", - "addressBar": "0x3D2742", - "border": "0xffffff", - "accent": "0xcf68ff", - "tints": { - "home": "0xE7E6E9", - "header": "0xE7E6E9", - "footer": "0xE7E6E9", - "addressBar": "0xE7E6E9" - }, - "transparencies": { - "addressBarAlpha": 1.0, - "borderAlpha": 0.2, - }, - "stats": { - "ads": "0xFA4214", - "trackers": "0xFA4214", - "httpse": "0x9339D4", - "timeSaved": "0xffffff" - } - }, - "images": { - "header": "https://www.google.com", - "footer": "https://www.google.com", - "home": "https://www.google.com", - } - } - - """ - } -} - fileprivate enum ThemeCodingKeys: String, CodingKey { case uuid case title From e224369bb35c78ebf3fe2e0944704217fcd1f0ba Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Tue, 20 Aug 2019 11:51:27 -1000 Subject: [PATCH 36/73] Fixed up most Settings children VC's colorings. --- Client.xcodeproj/project.pbxproj | 4 ++ Client/Application/AppDelegate.swift | 7 --- Client/Extensions/AppearanceExtensions.swift | 25 +++++++++++ .../Browser/BrowserViewController.swift | 14 ++++++ .../ClearPrivateDataTableViewController.swift | 4 -- .../OptionSelectionViewController.swift | 7 --- .../SearchSettingsTableViewController.swift | 6 --- ...SettingsTableSectionHeaderFooterView.swift | 43 ++----------------- .../Settings/SettingsViewController.swift | 27 ++++++++---- Client/Frontend/UIConstants.swift | 1 + 10 files changed, 65 insertions(+), 73 deletions(-) create mode 100644 Client/Extensions/AppearanceExtensions.swift diff --git a/Client.xcodeproj/project.pbxproj b/Client.xcodeproj/project.pbxproj index cd4a798bf99..6e1b2df2bd9 100644 --- a/Client.xcodeproj/project.pbxproj +++ b/Client.xcodeproj/project.pbxproj @@ -493,6 +493,7 @@ 5D6DDEFE2141B6A1001FF0AE /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D6DDEF62141B6A0001FF0AE /* Preferences.swift */; }; 5D6DDF0021428CF0001FF0AE /* DAUTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D6DDEFF21428CF0001FF0AE /* DAUTests.swift */; }; 5D7001C222249F7B00E576FB /* ShortNameToFileMapping.json in Resources */ = {isa = PBXBuildFile; fileRef = 5D7001BA22249F7A00E576FB /* ShortNameToFileMapping.json */; }; + 5D8AE6AF230C76B60096C845 /* AppearanceExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D8AE6AE230C76B60096C845 /* AppearanceExtensions.swift */; }; 5DE5250D218CE92C000DFAA6 /* block-ads.json in Resources */ = {isa = PBXBuildFile; fileRef = 5DE52508218CE92B000DFAA6 /* block-ads.json */; }; 5DE5250E218CE92C000DFAA6 /* block-images.json in Resources */ = {isa = PBXBuildFile; fileRef = 5DE52509218CE92B000DFAA6 /* block-images.json */; }; 5DE5250F218CE92C000DFAA6 /* upgrade-http.json in Resources */ = {isa = PBXBuildFile; fileRef = 5DE5250A218CE92B000DFAA6 /* upgrade-http.json */; }; @@ -1859,6 +1860,7 @@ 5D6DDEF62141B6A0001FF0AE /* Preferences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = ""; }; 5D6DDEFF21428CF0001FF0AE /* DAUTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DAUTests.swift; sourceTree = ""; }; 5D7001BA22249F7A00E576FB /* ShortNameToFileMapping.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ShortNameToFileMapping.json; sourceTree = ""; }; + 5D8AE6AE230C76B60096C845 /* AppearanceExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppearanceExtensions.swift; path = Extensions/AppearanceExtensions.swift; sourceTree = ""; }; 5DE52508218CE92B000DFAA6 /* block-ads.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "block-ads.json"; sourceTree = ""; }; 5DE52509218CE92B000DFAA6 /* block-images.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "block-images.json"; sourceTree = ""; }; 5DE5250A218CE92B000DFAA6 /* upgrade-http.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "upgrade-http.json"; sourceTree = ""; }; @@ -2736,6 +2738,7 @@ 595E0EE021CAEF5B00813D49 /* FileManagerExtension.swift */, 592F521D2217327B0078395E /* HttpCookieExtension.swift */, F930CDAD2270015C00A23FE1 /* U2FExtensions.swift */, + 5D8AE6AE230C76B60096C845 /* AppearanceExtensions.swift */, ); indentWidth = 4; name = Extensions; @@ -5852,6 +5855,7 @@ A83E5AB71C1D993D0026D912 /* UIPasteboardExtensions.swift in Sources */, C6B81B8A212D84BD00996084 /* ImageCacheType.swift in Sources */, D8EFFA0C1FF5B1FA001D3A09 /* NavigationRouter.swift in Sources */, + 5D8AE6AF230C76B60096C845 /* AppearanceExtensions.swift in Sources */, D0E55C4F1FB4FD23006DC274 /* FormPostHelper.swift in Sources */, E650754E1E37F6AE006961AC /* GeometryExtensions.swift in Sources */, D3972BF41C22412B00035B87 /* TitleActivityItemProvider.swift in Sources */, diff --git a/Client/Application/AppDelegate.swift b/Client/Application/AppDelegate.swift index 0a5b3da20e3..88764e82aa6 100644 --- a/Client/Application/AppDelegate.swift +++ b/Client/Application/AppDelegate.swift @@ -262,13 +262,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati } AdblockResourceDownloader.shared.startLoading() - - UINavigationBar.appearance().tintColor = BraveUX.BraveOrange - - (UISwitch.appearance() as UISwitch).do { - $0.tintColor = BraveUX.SwitchTintColor - $0.onTintColor = BraveUX.BraveOrange - } return shouldPerformAdditionalDelegateHandling } diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift new file mode 100644 index 00000000000..f5e1e1b1cba --- /dev/null +++ b/Client/Extensions/AppearanceExtensions.swift @@ -0,0 +1,25 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import Foundation + +extension UILabel { + @objc dynamic var appearanceTextColor: UIColor! { + get { return self.textColor } + set { self.textColor = newValue } + } +} + +extension UITableView { + @objc dynamic var appearanceBackgroundColor: UIColor? { + get { return self.backgroundColor } + set { self.backgroundColor = newValue } + } + + @objc dynamic var appearanceSeparatorColor: UIColor? { + get { return self.separatorColor } + set { self.separatorColor = newValue } + } +} + diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index 9b37204fc75..469942f5d9a 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -2940,6 +2940,20 @@ extension BrowserViewController: Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) + // `appearance` modifications do not seem to fully reset UI components. + UINavigationBar.appearance().tintColor = theme.colors.accent + (UISwitch.appearance() as UISwitch).do { + $0.tintColor = theme.colors.accent + $0.onTintColor = theme.colors.accent + } + + UITableView.appearance().appearanceBackgroundColor = theme.colors.addressBar + UITableView.appearance().appearanceSeparatorColor = theme.colors.border.withAlphaComponent(theme.colors.transparencies.borderAlpha) + + UILabel.appearance(whenContainedInInstancesOf: [UITableViewCell.self]).appearanceTextColor = theme.colors.tints.home + + UITableViewCell.appearance().backgroundColor = theme.colors.home + // TODO: Theme: Maybe just set to clear color? statusBarOverlay.backgroundColor = topToolbar.backgroundColor setNeedsStatusBarAppearanceUpdate() diff --git a/Client/Frontend/Settings/ClearPrivateDataTableViewController.swift b/Client/Frontend/Settings/ClearPrivateDataTableViewController.swift index c140a3d59e1..f73203b77d6 100644 --- a/Client/Frontend/Settings/ClearPrivateDataTableViewController.swift +++ b/Client/Frontend/Settings/ClearPrivateDataTableViewController.swift @@ -66,9 +66,6 @@ class ClearPrivateDataTableViewController: UITableViewController { title = Strings.ClearPrivateData tableView.register(SettingsTableSectionHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: SectionHeaderFooterIdentifier) - - tableView.separatorColor = UIConstants.TableViewSeparatorColor - tableView.backgroundColor = UIConstants.TableViewHeaderBackgroundColor } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { @@ -77,7 +74,6 @@ class ClearPrivateDataTableViewController: UITableViewController { if indexPath.section == SectionToggles { cell.textLabel?.text = clearables[indexPath.item].clearable.label let control = UISwitch() - control.onTintColor = UIConstants.ControlTintColor control.addTarget(self, action: #selector(switchValueChanged(_:)), for: .valueChanged) control.isOn = toggles[indexPath.item] cell.accessoryView = control diff --git a/Client/Frontend/Settings/OptionSelectionViewController.swift b/Client/Frontend/Settings/OptionSelectionViewController.swift index 380627e3982..787a92c0a77 100644 --- a/Client/Frontend/Settings/OptionSelectionViewController.swift +++ b/Client/Frontend/Settings/OptionSelectionViewController.swift @@ -93,14 +93,7 @@ class OptionSelectionViewController: TableV required init?(coder aDecoder: NSCoder) { fatalError() } - - override func viewDidLoad() { - super.viewDidLoad() - tableView.separatorColor = UIConstants.TableViewSeparatorColor - tableView.backgroundColor = UIConstants.TableViewHeaderBackgroundColor - } - private func updateRowsForSelectedOption() { for (idx, option) in options.enumerated() { if option.key == selectedOption.key { diff --git a/Client/Frontend/Settings/SearchSettingsTableViewController.swift b/Client/Frontend/Settings/SearchSettingsTableViewController.swift index ee4f197a2bf..e15e30d4620 100644 --- a/Client/Frontend/Settings/SearchSettingsTableViewController.swift +++ b/Client/Frontend/Settings/SearchSettingsTableViewController.swift @@ -46,11 +46,7 @@ class SearchSettingsTableViewController: UITableViewController { } let footer = SettingsTableSectionHeaderFooterView(frame: CGRect(width: tableView.bounds.width, height: 44)) - footer.showBottomBorder = false tableView.tableFooterView = footer - - tableView.separatorColor = SettingsUX.TableViewSeparatorColor - tableView.backgroundColor = SettingsUX.TableViewHeaderBackgroundColor } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { @@ -69,7 +65,6 @@ class SearchSettingsTableViewController: UITableViewController { cell = UITableViewCell(style: .default, reuseIdentifier: nil) cell.textLabel?.text = Strings.SearchSettingSuggestionCellTitle let toggle = UISwitch() - toggle.onTintColor = UIConstants.ControlTintColor toggle.addTarget(self, action: #selector(didToggleSearchSuggestions), for: .valueChanged) toggle.isOn = model.shouldShowSearchSuggestions cell.editingAccessoryView = toggle @@ -87,7 +82,6 @@ class SearchSettingsTableViewController: UITableViewController { cell.showsReorderControl = true let toggle = UISwitch() - toggle.onTintColor = UIConstants.ControlTintColor // This is an easy way to get from the toggle control to the corresponding index. toggle.tag = index toggle.addTarget(self, action: #selector(didToggleEngine), for: .valueChanged) diff --git a/Client/Frontend/Settings/SettingsTableSectionHeaderFooterView.swift b/Client/Frontend/Settings/SettingsTableSectionHeaderFooterView.swift index a05dd15ca38..0ae0b02e10a 100644 --- a/Client/Frontend/Settings/SettingsTableSectionHeaderFooterView.swift +++ b/Client/Frontend/Settings/SettingsTableSectionHeaderFooterView.swift @@ -5,6 +5,7 @@ import Shared import UIKit +// TODO: Theme: Remove a bunch of these struct SettingsUX { static let TableViewHeaderBackgroundColor = UIConstants.AppBackgroundColor static let TableViewHeaderTextColor = UIColor.Photon.Grey50 @@ -37,44 +38,18 @@ class SettingsTableSectionHeaderFooterView: UITableViewHeaderFooterView { } } - var showTopBorder: Bool = true { - didSet { - topBorder.isHidden = !showTopBorder - } - } - - var showBottomBorder: Bool = true { - didSet { - bottomBorder.isHidden = !showBottomBorder - } - } - lazy var titleLabel: UILabel = { var headerLabel = UILabel() - headerLabel.textColor = SettingsUX.TableViewHeaderTextColor headerLabel.font = UIFont.systemFont(ofSize: 12.0, weight: UIFont.Weight.regular) headerLabel.numberOfLines = 0 return headerLabel }() - fileprivate lazy var topBorder: UIView = { - let topBorder = UIView() - topBorder.backgroundColor = UIConstants.SeparatorColor - return topBorder - }() - - fileprivate lazy var bottomBorder: UIView = { - let bottomBorder = UIView() - bottomBorder.backgroundColor = UIConstants.SeparatorColor - return bottomBorder - }() - override init(reuseIdentifier: String?) { super.init(reuseIdentifier: reuseIdentifier) - contentView.backgroundColor = SettingsUX.TableViewHeaderBackgroundColor + backgroundView = UIView() + backgroundView?.backgroundColor = .clear addSubview(titleLabel) - addSubview(topBorder) - addSubview(bottomBorder) setupInitialConstraints() } @@ -84,23 +59,11 @@ class SettingsTableSectionHeaderFooterView: UITableViewHeaderFooterView { } func setupInitialConstraints() { - bottomBorder.snp.makeConstraints { make in - make.bottom.left.right.equalTo(self) - make.height.equalTo(0.5) - } - - topBorder.snp.makeConstraints { make in - make.top.left.right.equalTo(self) - make.height.equalTo(0.5) - } - remakeTitleAlignmentConstraints() } override func prepareForReuse() { super.prepareForReuse() - showTopBorder = true - showBottomBorder = true titleLabel.text = nil titleAlignment = .bottom } diff --git a/Client/Frontend/Settings/SettingsViewController.swift b/Client/Frontend/Settings/SettingsViewController.swift index 611c12eb70c..d7e1230bde4 100644 --- a/Client/Frontend/Settings/SettingsViewController.swift +++ b/Client/Frontend/Settings/SettingsViewController.swift @@ -86,8 +86,6 @@ class SettingsViewController: TableViewController { self.tabManager = tabManager super.init(style: .grouped) - - UITableViewCell.appearance().tintColor = BraveUX.BraveOrange } @available(*, unavailable) @@ -96,14 +94,15 @@ class SettingsViewController: TableViewController { } override func viewDidLoad() { - navigationItem.title = Strings.Settings - tableView.accessibilityIdentifier = "SettingsViewController.tableView" - tableView.separatorColor = UIConstants.TableViewSeparatorColor - tableView.backgroundColor = UIConstants.TableViewHeaderBackgroundColor - dataSource.sections = sections + + applyTheme(theme) + } + + private var theme: Theme { + Theme.of(tabManager.selectedTab) } private var sections: [Section] { @@ -180,8 +179,7 @@ class SettingsViewController: TableViewController { optionChanged: { [unowned self] _, option in Preferences.General.themeNormalMode.value = option.rawValue reloadCell(row, option.displayString) - - // Update theme! + self.applyTheme(self.theme) } ) optionsViewController.headerText = Strings.Normal_Mode_Theme @@ -434,6 +432,17 @@ class SettingsViewController: TableViewController { } } +extension TableViewController: Themeable { + func applyTheme(_ theme: Theme) { + styleChildren(theme: theme) + tableView.reloadData() + + // `UINavigationBar`'s `tintColor` set via `apperance()`, not impact + // exiting menus, so setting explicitly. + navigationController?.navigationBar.tintColor = theme.colors.accent + } +} + fileprivate class MultilineButtonCell: ButtonCell { override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { diff --git a/Client/Frontend/UIConstants.swift b/Client/Frontend/UIConstants.swift index 9612d3d8927..f46396fdf70 100644 --- a/Client/Frontend/UIConstants.swift +++ b/Client/Frontend/UIConstants.swift @@ -42,6 +42,7 @@ extension UIColor { } } +// TODO: Theme: Delete most of this public struct UIConstants { static let AboutHomePage = URL(string: "\(WebServer.sharedInstance.base)/about/home/")! From 4b3653734a4cc15c2285716313c61077dd273d45 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Tue, 20 Aug 2019 13:36:47 -1000 Subject: [PATCH 37/73] TabBar tabs now update immediately on theme change. --- Client/Frontend/Browser/TabsBar/TabsBarViewController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift index 93cb4b7bfcc..4d1ce72d7db 100644 --- a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift +++ b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift @@ -339,5 +339,6 @@ extension TabsBarViewController: Themeable { plusButton.tintColor = theme.colors.tints.header bottomLine.backgroundColor = theme.colors.border.withAlphaComponent(theme.colors.transparencies.borderAlpha) collectionView.backgroundColor = view.backgroundColor + collectionView.reloadData() } } From 91aa5275ff5fd2246f8d68de00a31ad32e623300 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Tue, 20 Aug 2019 13:37:03 -1000 Subject: [PATCH 38/73] Moved `appearance()` adjustments to theme extension. --- Client/Extensions/AppearanceExtensions.swift | 21 +++++++++++++++++++ .../Browser/BrowserViewController.swift | 14 +------------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index f5e1e1b1cba..7377d3ee06f 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -4,6 +4,27 @@ import Foundation +extension Theme { + func applyAppearanceProperties() { + + // `appearance` modifications do not seem to fully reset UI components. + UINavigationBar.appearance().tintColor = colors.accent + (UISwitch.appearance() as UISwitch).do { + $0.tintColor = colors.accent + $0.onTintColor = colors.accent + } + + UITableView.appearance().appearanceBackgroundColor = colors.addressBar + UITableView.appearance().appearanceSeparatorColor = colors.border.withAlphaComponent(colors.transparencies.borderAlpha) + UITableViewCell.appearance().tintColor = colors.accent + + UILabel.appearance(whenContainedInInstancesOf: [UITableViewCell.self]).appearanceTextColor = colors.tints.home + + UITableViewCell.appearance().backgroundColor = colors.home + + } +} + extension UILabel { @objc dynamic var appearanceTextColor: UIColor! { get { return self.textColor } diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index 469942f5d9a..8b01124e0c1 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -2940,19 +2940,7 @@ extension BrowserViewController: Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - // `appearance` modifications do not seem to fully reset UI components. - UINavigationBar.appearance().tintColor = theme.colors.accent - (UISwitch.appearance() as UISwitch).do { - $0.tintColor = theme.colors.accent - $0.onTintColor = theme.colors.accent - } - - UITableView.appearance().appearanceBackgroundColor = theme.colors.addressBar - UITableView.appearance().appearanceSeparatorColor = theme.colors.border.withAlphaComponent(theme.colors.transparencies.borderAlpha) - - UILabel.appearance(whenContainedInInstancesOf: [UITableViewCell.self]).appearanceTextColor = theme.colors.tints.home - - UITableViewCell.appearance().backgroundColor = theme.colors.home + theme.applyAppearanceProperties() // TODO: Theme: Maybe just set to clear color? statusBarOverlay.backgroundColor = topToolbar.backgroundColor From 8a5e4f3d2f9b6c3fb19f6ca21dcfecbaa2c6e825 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Tue, 20 Aug 2019 14:06:41 -1000 Subject: [PATCH 39/73] Added color adjustment to navigation headers. --- Client/Extensions/AppearanceExtensions.swift | 11 ++++++++--- Client/Frontend/Settings/SettingsViewController.swift | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index 7377d3ee06f..c624cce037b 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -8,7 +8,11 @@ extension Theme { func applyAppearanceProperties() { // `appearance` modifications do not seem to fully reset UI components. - UINavigationBar.appearance().tintColor = colors.accent + UINavigationBar.appearance().do { + $0.tintColor = colors.accent + $0.backgroundColor = colors.header + } + (UISwitch.appearance() as UISwitch).do { $0.tintColor = colors.accent $0.onTintColor = colors.accent @@ -16,11 +20,12 @@ extension Theme { UITableView.appearance().appearanceBackgroundColor = colors.addressBar UITableView.appearance().appearanceSeparatorColor = colors.border.withAlphaComponent(colors.transparencies.borderAlpha) - UITableViewCell.appearance().tintColor = colors.accent + UITableViewCell.appearance().tintColor = colors.accent + UITableViewCell.appearance().backgroundColor = colors.home + UILabel.appearance(whenContainedInInstancesOf: [UITableViewCell.self]).appearanceTextColor = colors.tints.home - UITableViewCell.appearance().backgroundColor = colors.home } } diff --git a/Client/Frontend/Settings/SettingsViewController.swift b/Client/Frontend/Settings/SettingsViewController.swift index d7e1230bde4..c71d87a3367 100644 --- a/Client/Frontend/Settings/SettingsViewController.swift +++ b/Client/Frontend/Settings/SettingsViewController.swift @@ -439,6 +439,7 @@ extension TableViewController: Themeable { // `UINavigationBar`'s `tintColor` set via `apperance()`, not impact // exiting menus, so setting explicitly. + navigationController?.navigationBar.backgroundColor = theme.colors.header navigationController?.navigationBar.tintColor = theme.colors.accent } } From 1029ff866907c44cc796556c9c919fd40d344755 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Tue, 20 Aug 2019 14:25:56 -1000 Subject: [PATCH 40/73] Fixed up table coloring for history / bookmarks. --- Client/Extensions/AppearanceExtensions.swift | 16 +++++++--------- .../Menu/Bookmarks/BookmarksViewController.swift | 14 +++++--------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index c624cce037b..2520ba7337d 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -7,17 +7,17 @@ import Foundation extension Theme { func applyAppearanceProperties() { - // `appearance` modifications do not seem to fully reset UI components. - UINavigationBar.appearance().do { - $0.tintColor = colors.accent - $0.backgroundColor = colors.header - } + // `appearance` modifications only impact UI items not current visible - (UISwitch.appearance() as UISwitch).do { + let bars = [UINavigationBar.appearance(), UIToolbar.appearance()] + bars.forEach { $0.tintColor = colors.accent - $0.onTintColor = colors.accent + $0.backgroundColor = colors.footer } + UISwitch.appearance().tintColor = colors.accent + UISwitch.appearance().onTintColor = colors.accent + UITableView.appearance().appearanceBackgroundColor = colors.addressBar UITableView.appearance().appearanceSeparatorColor = colors.border.withAlphaComponent(colors.transparencies.borderAlpha) @@ -25,8 +25,6 @@ extension Theme { UITableViewCell.appearance().backgroundColor = colors.home UILabel.appearance(whenContainedInInstancesOf: [UITableViewCell.self]).appearanceTextColor = colors.tints.home - - } } diff --git a/Client/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/BookmarksViewController.swift b/Client/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/BookmarksViewController.swift index d393d41e1fe..0d7bae7a175 100644 --- a/Client/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/BookmarksViewController.swift +++ b/Client/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/BookmarksViewController.swift @@ -22,7 +22,6 @@ class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtoco lazy var editBookmarksButton = UIBarButtonItem().then { $0.image = #imageLiteral(resourceName: "edit").template $0.style = .plain - $0.tintColor = BraveUX.LightBlue $0.target = self $0.action = #selector(onEditBookmarksButton) } @@ -30,7 +29,6 @@ class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtoco lazy var addFolderButton = UIBarButtonItem().then { $0.image = #imageLiteral(resourceName: "bookmarks_newfolder_icon").template $0.style = .plain - $0.tintColor = BraveUX.LightBlue $0.target = self $0.action = #selector(onAddBookmarksFolderButton) } @@ -62,7 +60,6 @@ class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtoco override func viewDidLoad() { super.viewDidLoad() - self.view.backgroundColor = BraveUX.BackgroundColorForSideToolbars tableView.allowsSelectionDuringEditing = true setUpToolbar() @@ -85,10 +82,10 @@ class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtoco let items = [padding, addFolderButton, flexibleSpace, editBookmarksButton, padding] setToolbarItems(items, animated: true) - navigationController?.toolbar.do { - $0.barTintColor = BraveUX.BackgroundColorForSideToolbars - $0.isTranslucent = false - } +// navigationController?.toolbar.do { +// $0.barTintColor = BraveUX.BackgroundColorForSideToolbars +// $0.isTranslucent = false +// } } override func reloadData() { @@ -198,6 +195,7 @@ class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtoco cell.addGestureRecognizer(lp) } + cell.backgroundColor = .clear cell.imageView?.contentMode = .scaleAspectFit cell.imageView?.image = FaviconFetcher.defaultFavicon cell.imageView?.layer.cornerRadius = 6 @@ -220,8 +218,6 @@ class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtoco cell.textLabel?.text = item.displayTitle ?? item.url cell.textLabel?.lineBreakMode = .byTruncatingTail - cell.contentView.backgroundColor = .white - if !item.isFolder { configCell(icon: item.domain?.favicon) cell.textLabel?.font = UIFont.systemFont(ofSize: fontSize) From e001f2a7ccc4f794a7c4fe04314ff8b6a8b57232 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Tue, 20 Aug 2019 15:21:38 -1000 Subject: [PATCH 41/73] Color adjustments for history / bookmark headers. --- Client/Extensions/AppearanceExtensions.swift | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index 2520ba7337d..682a933c7e7 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -18,13 +18,18 @@ extension Theme { UISwitch.appearance().tintColor = colors.accent UISwitch.appearance().onTintColor = colors.accent + // Will become the color for whatever in the table is .clear + // In some cases this is the header, footer, cell, or a combination of them. + // Be careful adjusting colors here, and make sure impact is well known UITableView.appearance().appearanceBackgroundColor = colors.addressBar UITableView.appearance().appearanceSeparatorColor = colors.border.withAlphaComponent(colors.transparencies.borderAlpha) UITableViewCell.appearance().tintColor = colors.accent UITableViewCell.appearance().backgroundColor = colors.home - UILabel.appearance(whenContainedInInstancesOf: [UITableViewCell.self]).appearanceTextColor = colors.tints.home + UIView.appearance(whenContainedInInstancesOf: [UITableViewHeaderFooterView.self]).appearanceBackgroundColor = colors.addressBar + + UILabel.appearance(whenContainedInInstancesOf: [UITableView.self]).appearanceTextColor = colors.tints.home } } @@ -36,14 +41,16 @@ extension UILabel { } extension UITableView { - @objc dynamic var appearanceBackgroundColor: UIColor? { - get { return self.backgroundColor } - set { self.backgroundColor = newValue } - } - @objc dynamic var appearanceSeparatorColor: UIColor? { get { return self.separatorColor } set { self.separatorColor = newValue } } } +extension UIView { + @objc dynamic var appearanceBackgroundColor: UIColor? { + get { return self.backgroundColor } + set { self.backgroundColor = newValue } + } +} + From d712f4d9fc354c33b0b30c48d9f9a5103771defe Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Tue, 20 Aug 2019 15:44:46 -1000 Subject: [PATCH 42/73] Improved bookmark editing colors. --- Client/Extensions/AppearanceExtensions.swift | 26 ++++++++++++++++--- .../Menu/Bookmarks/AddEditHeaderView.swift | 2 -- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index 682a933c7e7..b82644f0624 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -18,18 +18,31 @@ extension Theme { UISwitch.appearance().tintColor = colors.accent UISwitch.appearance().onTintColor = colors.accent + // This is a subtle "abuse" of theme colors + // In order to properly style things, `addressBar` has been utilized to offer contrast to `home`/`header`, as many of the themes utilize similar colors. + // These used colors have been mapped, primarily for table usage, and to understand how table colors relate to each other. + // Any change to a single tableView property that currently uses one of these will probably have odd behavior and must be thoroughly tested + + /// Used as color a table will use as the base (e.g. background) + let tablePrimaryColor = colors.header + /// Used to augment `tablePrimaryColor` above + let tableSecondaryColor = colors.addressBar + // Will become the color for whatever in the table is .clear // In some cases this is the header, footer, cell, or a combination of them. // Be careful adjusting colors here, and make sure impact is well known - UITableView.appearance().appearanceBackgroundColor = colors.addressBar + UITableView.appearance().appearanceBackgroundColor = tablePrimaryColor UITableView.appearance().appearanceSeparatorColor = colors.border.withAlphaComponent(colors.transparencies.borderAlpha) UITableViewCell.appearance().tintColor = colors.accent - UITableViewCell.appearance().backgroundColor = colors.home + UITableViewCell.appearance().backgroundColor = tableSecondaryColor - UIView.appearance(whenContainedInInstancesOf: [UITableViewHeaderFooterView.self]).appearanceBackgroundColor = colors.addressBar + UIView.appearance(whenContainedInInstancesOf: [UITableViewHeaderFooterView.self]).appearanceBackgroundColor = tablePrimaryColor UILabel.appearance(whenContainedInInstancesOf: [UITableView.self]).appearanceTextColor = colors.tints.home + + AddEditHeaderView.appearance().appearanceBackgroundColor = tableSecondaryColor + UITextField.appearance().appearanceTextColor = colors.tints.home } } @@ -54,3 +67,10 @@ extension UIView { } } +extension UITextField { + @objc dynamic var appearanceTextColor: UIColor? { + get { return self.textColor } + set { self.textColor = newValue } + } +} + diff --git a/Client/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/AddEditHeaderView.swift b/Client/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/AddEditHeaderView.swift index 3706886ac90..a32926689c8 100644 --- a/Client/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/AddEditHeaderView.swift +++ b/Client/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/AddEditHeaderView.swift @@ -22,8 +22,6 @@ class AddEditHeaderView: UIView { override init(frame: CGRect) { super.init(frame: frame) - - backgroundColor = .white addSubview(mainStackView) mainStackView.snp.makeConstraints { From 3fd9d21b27d7dfafee1b97277ceea0ec48dd5464 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Wed, 21 Aug 2019 15:09:36 -1000 Subject: [PATCH 43/73] Tab bar side glow effect respects theme now. --- .../Frontend/Browser/TabsBar/TabsBarViewController.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift index 4d1ce72d7db..df82892dee0 100644 --- a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift +++ b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift @@ -205,8 +205,10 @@ class TabsBarViewController: UIViewController { private func addScrollHint(for side: HintSide, maskLayer: CAGradientLayer) { maskLayer.removeFromSuperlayer() - let barsColor = PrivateBrowsingManager.shared.isPrivateBrowsing ? - UX.barsDarkBackgroundSolidColor : UX.barsBackgroundSolidColor + guard let barsColor = collectionView.backgroundColor ?? view.backgroundColor else { + // If not setup now, will be at some point, and then this can be flushed + return + } let colors = [barsColor.withAlphaComponent(0).cgColor, barsColor.cgColor] let locations = [0.9, 1.0] @@ -339,6 +341,8 @@ extension TabsBarViewController: Themeable { plusButton.tintColor = theme.colors.tints.header bottomLine.backgroundColor = theme.colors.border.withAlphaComponent(theme.colors.transparencies.borderAlpha) collectionView.backgroundColor = view.backgroundColor + overflowIndicators() + collectionView.reloadData() } } From b15b4a27e74624abc2ae1ff6bd7abd252dccb775 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Wed, 21 Aug 2019 15:16:46 -1000 Subject: [PATCH 44/73] Close button on tab bar now colored correctly. --- Client/Frontend/Browser/TabsBar/TabBarCell.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Client/Frontend/Browser/TabsBar/TabBarCell.swift b/Client/Frontend/Browser/TabsBar/TabBarCell.swift index 02bd87d7273..7364913e1fb 100644 --- a/Client/Frontend/Browser/TabsBar/TabBarCell.swift +++ b/Client/Frontend/Browser/TabsBar/TabBarCell.swift @@ -91,7 +91,8 @@ class TabBarCell: UICollectionViewCell { override var isSelected: Bool { didSet(selected) { let theme = Theme.of(tab) - closeButton.tintColor = PrivateBrowsingManager.shared.isPrivateBrowsing ? UIColor.white : UIColor.black + closeButton.tintColor = theme.colors.tints.header + if selected { titleLabel.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.semibold) closeButton.isHidden = false From 033795cb78bb1957dd213484f6fb3ecadb6b07b0 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Wed, 21 Aug 2019 15:51:15 -1000 Subject: [PATCH 45/73] Initial OS level integration. Still a number of oddities, but works pretty well, using auto-detection. --- .../Settings/SettingsViewController.swift | 2 +- Client/Frontend/Widgets/Themes/Theme.swift | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Client/Frontend/Settings/SettingsViewController.swift b/Client/Frontend/Settings/SettingsViewController.swift index c71d87a3367..5d0953cdddf 100644 --- a/Client/Frontend/Settings/SettingsViewController.swift +++ b/Client/Frontend/Settings/SettingsViewController.swift @@ -174,7 +174,7 @@ class SettingsViewController: TableViewController { var row = Row(text: Strings.Normal_Mode_Theme, detailText: themeSubtitle, accessory: .disclosureIndicator, cellClass: MultilineSubtitleCell.self) row.selection = { [unowned self] in let optionsViewController = OptionSelectionViewController( - options: Theme.DefaultTheme.allCases, + options: Theme.DefaultTheme.normalThemesOptions, selectedOption: Theme.DefaultTheme(rawValue: Preferences.General.themeNormalMode.value), optionChanged: { [unowned self] _, option in Preferences.General.themeNormalMode.value = option.rawValue diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index 11e7283f0cc..0463c415d47 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -27,7 +27,7 @@ extension Themeable { class Theme: Equatable, Decodable { - enum DefaultTheme: String, CaseIterable, RepresentableOptionType { + enum DefaultTheme: String, RepresentableOptionType { case system = "Z71ED37E-EC3E-436E-AD5F-B22748306A6B" case light = "ACE618A3-D6FC-45A4-94F2-1793C40AE927" case dark = "B900A41F-2C02-4664-9DE4-C170956339AC" @@ -42,8 +42,8 @@ class Theme: Equatable, Decodable { return Theme.from(id: self.id) } - static var normalThemes: [Theme] { - return [DefaultTheme.light.theme, DefaultTheme.dark.theme].compactMap { $0 } + static var normalThemesOptions: [DefaultTheme] { + return [DefaultTheme.system, DefaultTheme.light, DefaultTheme.dark] } public var displayString: String { @@ -218,7 +218,7 @@ class Theme: Equatable, Decodable { var id = id if id == DefaultTheme.system.id { // TODO: Pull system default, not 'light' necessarily - id = DefaultTheme.light.id + id = currentSystemThemeId } if let inMemoryTheme = themeMemoryBank[id] { @@ -237,6 +237,17 @@ class Theme: Equatable, Decodable { return theme } + private static var currentSystemThemeId: String { + // Should really be based off of preferences, a dark theme and light theme preference + + let fallback = DefaultTheme.light.id + if #available(iOS 13.0, *) { + let isDark = UITraitCollection.current.userInterfaceStyle == .dark + return isDark ? DefaultTheme.dark.id : fallback + } + return fallback + } + static let allThemes: [Theme] = { do { let filenames = try FileManager.default.contentsOfDirectory(at: Theme.ThemeDirectory, includingPropertiesForKeys: []) From 708b6fdf17770431afad81823e65633ab6e5c061 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Wed, 21 Aug 2019 17:50:10 -1000 Subject: [PATCH 46/73] Much better OS theming support for hard-to-control-views. This is used by setting the override style property on all `UIView` subclasses to control better theming across the application. --- Client/Extensions/AppearanceExtensions.swift | 46 +++++++++++++++---- .../Settings/SettingsViewController.swift | 6 +-- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index b82644f0624..05e5547236b 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -9,11 +9,11 @@ extension Theme { // `appearance` modifications only impact UI items not current visible - let bars = [UINavigationBar.appearance(), UIToolbar.appearance()] - bars.forEach { - $0.tintColor = colors.accent - $0.backgroundColor = colors.footer - } + UIToolbar.appearance().tintColor = colors.accent + UIToolbar.appearance().backgroundColor = colors.footer + + UINavigationBar.appearance().tintColor = colors.accent + UINavigationBar.appearance().appearanceBarTintColor = colors.header UISwitch.appearance().tintColor = colors.accent UISwitch.appearance().onTintColor = colors.accent @@ -43,34 +43,62 @@ extension Theme { AddEditHeaderView.appearance().appearanceBackgroundColor = tableSecondaryColor UITextField.appearance().appearanceTextColor = colors.tints.home + + if #available(iOS 13.0, *) { + UIView.appearance().appearanceOverrideUserInterfaceStyle = isDark ? .dark : .light + } } } extension UILabel { @objc dynamic var appearanceTextColor: UIColor! { get { return self.textColor } - set { self.textColor = newValue } + set { self.textColor = newValue } } } extension UITableView { @objc dynamic var appearanceSeparatorColor: UIColor? { get { return self.separatorColor } - set { self.separatorColor = newValue } + set { self.separatorColor = newValue } } } extension UIView { @objc dynamic var appearanceBackgroundColor: UIColor? { get { return self.backgroundColor } - set { self.backgroundColor = newValue } + set { self.backgroundColor = newValue } } } extension UITextField { @objc dynamic var appearanceTextColor: UIColor? { get { return self.textColor } - set { self.textColor = newValue } + set { self.textColor = newValue } + } +} + +extension UIView { + @objc dynamic var appearanceOverrideUserInterfaceStyle: UIUserInterfaceStyle { + get { + if #available(iOS 13.0, *) { + return self.overrideUserInterfaceStyle + } + return .unspecified + } + set { + if #available(iOS 13.0, *) { + self.overrideUserInterfaceStyle = newValue + } + // Ignore + } + } +} + +extension UINavigationBar { + @objc dynamic var appearanceBarTintColor: UIColor? { + get { return self.barTintColor } + set { self.barTintColor = newValue } } } diff --git a/Client/Frontend/Settings/SettingsViewController.swift b/Client/Frontend/Settings/SettingsViewController.swift index 5d0953cdddf..eef32292827 100644 --- a/Client/Frontend/Settings/SettingsViewController.swift +++ b/Client/Frontend/Settings/SettingsViewController.swift @@ -437,10 +437,10 @@ extension TableViewController: Themeable { styleChildren(theme: theme) tableView.reloadData() - // `UINavigationBar`'s `tintColor` set via `apperance()`, not impact + // View manipulations done via `apperance()` do not impact existing UI, so need to adjust manually // exiting menus, so setting explicitly. - navigationController?.navigationBar.backgroundColor = theme.colors.header - navigationController?.navigationBar.tintColor = theme.colors.accent + navigationController?.navigationBar.tintColor = UINavigationBar.appearance().tintColor + navigationController?.navigationBar.barTintColor = UINavigationBar.appearance().appearanceBarTintColor } } From 524ff8745df8004e0f27cf5275f74422df958be8 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Thu, 22 Aug 2019 15:58:55 -1000 Subject: [PATCH 47/73] Onboarding theme support! --- .../Browser/BrowserViewController.swift | 8 +++++-- .../OnboardingNavigationController.swift | 12 +++++----- .../OnboardingSearchEnginesView.swift | 23 ++++++++----------- ...nboardingSearchEnginesViewController.swift | 12 ++++------ .../Onboarding/OnboardingShieldsView.swift | 8 ++++++- .../Onboarding/OnboardingViewController.swift | 9 +++++++- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index 61490422df3..d07dabef5a4 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -590,8 +590,12 @@ class BrowserViewController: UIViewController { func presentOnboardingIntro() { if Preferences.General.basicOnboardingCompleted.value != OnboardingState.completed.rawValue { - guard let onboarding = OnboardingNavigationController(profile: profile, - onboardingType: .newUser) else { return } + guard let onboarding = OnboardingNavigationController( + profile: profile, + onboardingType: .newUser, + theme: Theme.of(tabManager.selectedTab) + ) else { return } + onboarding.onboardingDelegate = self present(onboarding, animated: true) } else { diff --git a/Client/Frontend/Browser/Onboarding/OnboardingNavigationController.swift b/Client/Frontend/Browser/Onboarding/OnboardingNavigationController.swift index f346baf7216..ad8bd8da6c5 100644 --- a/Client/Frontend/Browser/Onboarding/OnboardingNavigationController.swift +++ b/Client/Frontend/Browser/Onboarding/OnboardingNavigationController.swift @@ -47,12 +47,12 @@ class OnboardingNavigationController: UINavigationController { case shieldsInfo /// Returns new ViewController associated with the screen type - func viewController(with profile: Profile) -> OnboardingViewController { + func viewController(with profile: Profile, theme: Theme) -> OnboardingViewController { switch self { case .searchEnginePicker: - return OnboardingSearchEnginesViewController(profile: profile) + return OnboardingSearchEnginesViewController(profile: profile, theme: theme) case .shieldsInfo: - return OnboardingShieldsViewController(profile: profile) + return OnboardingShieldsViewController(profile: profile, theme: theme) } } @@ -66,11 +66,11 @@ class OnboardingNavigationController: UINavigationController { let onboardingType: OnboardingType - init?(profile: Profile, onboardingType: OnboardingType) { + init?(profile: Profile, onboardingType: OnboardingType, theme: Theme) { guard let firstScreen = onboardingType.screens.first else { return nil } self.onboardingType = onboardingType - let firstViewController = firstScreen.viewController(with: profile) + let firstViewController = firstScreen.viewController(with: profile, theme: theme) super.init(rootViewController: firstViewController) firstViewController.delegate = self @@ -96,7 +96,7 @@ extension OnboardingNavigationController: Onboardable { let index = allScreens.firstIndex { $0.type == type(of: current) } guard let nextIndex = index?.advanced(by: 1), - let nextScreen = allScreens[safe: nextIndex]?.viewController(with: current.profile) else { + let nextScreen = allScreens[safe: nextIndex]?.viewController(with: current.profile, theme: current.theme) else { log.info("Last screen reached, onboarding is complete") onboardingDelegate?.onboardingCompleted(self) return diff --git a/Client/Frontend/Browser/Onboarding/OnboardingSearchEnginesView.swift b/Client/Frontend/Browser/Onboarding/OnboardingSearchEnginesView.swift index 47a3b06d42c..010a96eb433 100644 --- a/Client/Frontend/Browser/Onboarding/OnboardingSearchEnginesView.swift +++ b/Client/Frontend/Browser/Onboarding/OnboardingSearchEnginesView.swift @@ -20,8 +20,6 @@ extension OnboardingSearchEnginesViewController { static let rowHeight: CGFloat = 54 static let imageSize: CGFloat = 32 static let cornerRadius: CGFloat = 8 - static let selectedBackgroundColor = #colorLiteral(red: 0.9411764706, green: 0.9450980392, blue: 1, alpha: 1) - static let deselectedBackgroundColor: UIColor = .white } } @@ -74,7 +72,6 @@ extension OnboardingSearchEnginesViewController { init() { super.init(frame: .zero) - backgroundColor = .white addSubview(braveLogo) @@ -186,26 +183,26 @@ extension OnboardingSearchEnginesViewController { get { return imageView?.image } } + var selectedBackgroundColor: UIColor? { + didSet { + selectedBackgroundView?.backgroundColor = selectedBackgroundColor + } + } + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) imageView?.contentMode = .scaleAspectFit layer.cornerRadius = UX.SearchEngineCell.cornerRadius - selectionStyle = .none + + selectedBackgroundView = UIView().then { + $0.layer.cornerRadius = UX.SearchEngineCell.cornerRadius + } } @available(*, unavailable) required init(coder: NSCoder) { fatalError() } - override func setSelected(_ selected: Bool, animated: Bool) { - super.setSelected(selected, animated: animated) - - backgroundColor = selected ? - UX.SearchEngineCell.selectedBackgroundColor : UX.SearchEngineCell.deselectedBackgroundColor - - textLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.medium) - } - override func layoutSubviews() { super.layoutSubviews() let size = UX.SearchEngineCell.imageSize diff --git a/Client/Frontend/Browser/Onboarding/OnboardingSearchEnginesViewController.swift b/Client/Frontend/Browser/Onboarding/OnboardingSearchEnginesViewController.swift index 547a9187c1c..1a643c66534 100644 --- a/Client/Frontend/Browser/Onboarding/OnboardingSearchEnginesViewController.swift +++ b/Client/Frontend/Browser/Onboarding/OnboardingSearchEnginesViewController.swift @@ -14,7 +14,9 @@ class OnboardingSearchEnginesViewController: OnboardingViewController { static let spaceBetweenRows: CGFloat = 8 } - let searchEngines: SearchEngines + var searchEngines: SearchEngines { + profile.searchEngines + } private var contentView: View { return view as! View // swiftlint:disable:this force_cast @@ -23,13 +25,6 @@ class OnboardingSearchEnginesViewController: OnboardingViewController { override func loadView() { view = View() } - - override init(profile: Profile) { - self.searchEngines = profile.searchEngines - super.init(profile: profile) - - //super.init(nibName: nil, bundle: nil) - } override func viewDidLoad() { super.viewDidLoad() @@ -97,6 +92,7 @@ extension OnboardingSearchEnginesViewController: UITableViewDataSource { cell.searchEngineName = searchEngine.shortName cell.searchEngineImage = searchEngine.image + cell.selectedBackgroundColor = theme.colors.accent if searchEngine == defaultEngine { tableView.selectRow(at: indexPath, animated: true, scrollPosition: .middle) diff --git a/Client/Frontend/Browser/Onboarding/OnboardingShieldsView.swift b/Client/Frontend/Browser/Onboarding/OnboardingShieldsView.swift index 8ffe88b253e..737a67e9536 100644 --- a/Client/Frontend/Browser/Onboarding/OnboardingShieldsView.swift +++ b/Client/Frontend/Browser/Onboarding/OnboardingShieldsView.swift @@ -39,7 +39,6 @@ extension OnboardingShieldsViewController { } private let descriptionView = UIView().then { - $0.backgroundColor = .white $0.layer.cornerRadius = 12 $0.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] } @@ -68,6 +67,13 @@ extension OnboardingShieldsViewController { $0.distribution = .equalCentering } + override var backgroundColor: UIColor? { + didSet { + // Needed to support rounding + descriptionView.backgroundColor = backgroundColor + } + } + init() { super.init(frame: .zero) diff --git a/Client/Frontend/Browser/Onboarding/OnboardingViewController.swift b/Client/Frontend/Browser/Onboarding/OnboardingViewController.swift index d1d9ddcff75..87e5b47838c 100644 --- a/Client/Frontend/Browser/Onboarding/OnboardingViewController.swift +++ b/Client/Frontend/Browser/Onboarding/OnboardingViewController.swift @@ -10,15 +10,22 @@ import Shared class OnboardingViewController: UIViewController { weak var delegate: Onboardable? var profile: Profile + let theme: Theme - init(profile: Profile) { + init(profile: Profile, theme: Theme) { self.profile = profile + self.theme = theme super.init(nibName: nil, bundle: nil) } @available(*, unavailable) required init(coder: NSCoder) { fatalError() } + override func viewDidLoad() { + super.viewDidLoad() + view.backgroundColor = theme.colors.home + } + /// Default behavior to present next onboarding screen. /// Override it to add custom behavior. @objc func continueTapped() { From dbdc8ef0aac83b84fe26e90d6238d00f2ecceb00 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Thu, 22 Aug 2019 17:01:14 -1000 Subject: [PATCH 48/73] Shield panel now has theming support. --- BraveShared/BraveUX.swift | 1 + .../ACE618A3-D6FC-45A4-94F2-1793C40AE927.json | 2 +- .../B900A41F-2C02-4664-9DE4-C170956339AC.json | 2 +- .../C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json | 2 +- .../Browser/BrowserViewController.swift | 1 - Client/Frontend/Shields/ShieldsView.swift | 42 ++++++++++++++----- .../Shields/ShieldsViewController.swift | 1 + 7 files changed, 36 insertions(+), 15 deletions(-) diff --git a/BraveShared/BraveUX.swift b/BraveShared/BraveUX.swift index 6b0f8db1713..ae1d9e7535b 100644 --- a/BraveShared/BraveUX.swift +++ b/BraveShared/BraveUX.swift @@ -1,5 +1,6 @@ /* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +// TODO: Theme: Clean up colors public struct BraveUX { public static let BraveCommunityURL = URL(string: "https://community.brave.com/")! public static let BravePrivacyURL = URL(string: "https://brave.com/privacy/")! diff --git a/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json b/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json index eb32711bab8..3fdfc06c4d0 100644 --- a/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json +++ b/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json @@ -26,7 +26,7 @@ }, "stats": { "ads": "0xFA4214", - "trackers": "0xFA4214", + "trackers": "0x1bc760", "httpse": "0x9339D4", "timeSaved": "0x222326" } diff --git a/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json b/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json index e801dbcdf5f..582f294dda3 100644 --- a/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json +++ b/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json @@ -26,7 +26,7 @@ }, "stats": { "ads": "0xFA4214", - "trackers": "", + "trackers": "0x1bc760", "httpse": "0x9339D4", "timeSaved": "0xffffff" } diff --git a/Client/Assets/Themes/C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json b/Client/Assets/Themes/C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json index ed8e86b3ac8..113fc47eb71 100644 --- a/Client/Assets/Themes/C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json +++ b/Client/Assets/Themes/C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json @@ -26,7 +26,7 @@ }, "stats": { "ads": "0xFA4214", - "trackers": "0xFA4214", + "trackers": "0x1bc760", "httpse": "0x9339D4", "timeSaved": "0xffffff" } diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index d07dabef5a4..f0870935d0d 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -1560,7 +1560,6 @@ extension BrowserViewController: TopToolbarDelegate { } func topToolbarDidTapBraveShieldsButton(_ topToolbar: TopToolbarView) { - // BRAVE TODO: Use actual instance guard let selectedTab = tabManager.selectedTab else { return } let shields = ShieldsViewController(tab: selectedTab) shields.shieldsSettingsChanged = { [unowned self] _ in diff --git a/Client/Frontend/Shields/ShieldsView.swift b/Client/Frontend/Shields/ShieldsView.swift index 2e08234fb13..c0b6a57a446 100644 --- a/Client/Frontend/Shields/ShieldsView.swift +++ b/Client/Frontend/Shields/ShieldsView.swift @@ -23,7 +23,6 @@ extension ShieldsViewController { // Global Shields Override let shieldOverrideControl: ToggleView = { let toggleView = ToggleView(title: Strings.Site_shield_settings, toggleSide: .right) - toggleView.titleLabel.textColor = BraveUX.GreyJ toggleView.titleLabel.font = .systemFont(ofSize: 17.0, weight: .medium) return toggleView }() @@ -63,6 +62,16 @@ extension ShieldsViewController { required init?(coder aDecoder: NSCoder) { fatalError() } + + func set(theme: Theme) { + backgroundColor = theme.colors.home + + // Overview + overviewStackView.overviewFooterLabel.textColor = overviewStackView.overviewLabel.textColor.withAlphaComponent(0.6) + + // Normal shields panel + shieldsContainerStackView.set(theme: theme) + } } class OverviewContainerStackView: UIStackView { @@ -79,7 +88,6 @@ extension ShieldsViewController { let label = UILabel() label.numberOfLines = 0 label.font = .systemFont(ofSize: 15.0) - label.textColor = .lightGray label.text = Strings.Shields_Overview_Footer return label }() @@ -103,7 +111,6 @@ extension ShieldsViewController { /// Create a header label private class func headerLabel(title: String) -> UILabel { let label = UILabel() - label.textColor = UIColor(white: 0.4, alpha: 1.0) label.font = .systemFont(ofSize: 15.0) label.text = title return label @@ -128,10 +135,10 @@ extension ShieldsViewController { // Stats let statsHeaderLabel = headerLabel(title: Strings.Blocking_Monitor) - let adsTrackersStatView = StatView(title: Strings.Ads_and_Trackers, valueColor: BraveUX.BraveOrange) - let httpsUpgradesStatView = StatView(title: Strings.HTTPS_Upgrades, valueColor: BraveUX.Green) - let scriptsBlockedStatView = StatView(title: Strings.Scripts_Blocked, valueColor: BraveUX.Purple) - let fingerprintingStatView = StatView(title: Strings.Fingerprinting_Methods, valueColor: BraveUX.GreyG) + let adsTrackersStatView = StatView(title: Strings.Ads_and_Trackers) + let httpsUpgradesStatView = StatView(title: Strings.HTTPS_Upgrades) + let scriptsBlockedStatView = StatView(title: Strings.Scripts_Blocked) + let fingerprintingStatView = StatView(title: Strings.Fingerprinting_Methods) // Settings let settingsDivider = dividerView() @@ -173,6 +180,21 @@ extension ShieldsViewController { required init(coder: NSCoder) { fatalError() } + + func set(theme: Theme) { + let stats = theme.colors.stats + [ + adsTrackersStatView: stats.ads, + httpsUpgradesStatView: stats.httpse, + scriptsBlockedStatView: stats.trackers + ].forEach { + $0.0.valueLabel.textColor = $0.1 + } + + let faddedColor = hostLabel.textColor.withAlphaComponent(0.8) + statsHeaderLabel.textColor = faddedColor + settingsHeaderLabel.textColor = faddedColor + } } /// Displays some UI that displays the block count of a stat. Set `valueLabel.text` to the stat @@ -194,11 +216,9 @@ extension ShieldsViewController { l.numberOfLines = 0 return l }() - /// Create the stat view with a given title and color - init(title: String, valueColor: UIColor) { + /// Create the stat view with a given title + init(title: String) { super.init(frame: .zero) - - valueLabel.textColor = valueColor titleLabel.text = title addSubview(valueLabel) diff --git a/Client/Frontend/Shields/ShieldsViewController.swift b/Client/Frontend/Shields/ShieldsViewController.swift index c6c00439d1c..dfb9e8ff8bc 100644 --- a/Client/Frontend/Shields/ShieldsViewController.swift +++ b/Client/Frontend/Shields/ShieldsViewController.swift @@ -144,6 +144,7 @@ class ShieldsViewController: UIViewController, PopoverContentComponent { override func loadView() { view = View() + shieldsView.set(theme: Theme.of(tab)) } override func viewDidLoad() { From 78b2ac7972afafad05dbfdee2924207633f8c4b8 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 23 Aug 2019 05:08:31 -1000 Subject: [PATCH 49/73] Updated light theme colors. --- .../Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json b/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json index 3fdfc06c4d0..32ad6237739 100644 --- a/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json +++ b/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json @@ -8,12 +8,12 @@ "enabled": true, "colors": { - "header": "0xffffff", - "footer": "0xffffff", - "home": "0xffffff", - "addressBar": "0xD7D7E0", + "header": "0xf4f4f4", + "footer": "0xf8f8f8", + "home": "0xf1f1f1", + "addressBar": "0xffffff", "border": "0x000000", - "accent": "0xccdded", + "accent": "0xfb542b", "tints": { "home": "0x434351", "header": "0x434351", @@ -26,7 +26,7 @@ }, "stats": { "ads": "0xFA4214", - "trackers": "0x1bc760", + "trackers": "0x742BC4", "httpse": "0x9339D4", "timeSaved": "0x222326" } From 52da737151061702d8c7be8cc703c0949be9dce8 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 23 Aug 2019 07:32:12 -1000 Subject: [PATCH 50/73] Fixed on-boarding search engine table color. --- .../Onboarding/OnboardingSearchEnginesViewController.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Client/Frontend/Browser/Onboarding/OnboardingSearchEnginesViewController.swift b/Client/Frontend/Browser/Onboarding/OnboardingSearchEnginesViewController.swift index 1a643c66534..7f977b97269 100644 --- a/Client/Frontend/Browser/Onboarding/OnboardingSearchEnginesViewController.swift +++ b/Client/Frontend/Browser/Onboarding/OnboardingSearchEnginesViewController.swift @@ -34,6 +34,12 @@ class OnboardingSearchEnginesViewController: OnboardingViewController { contentView.continueButton.addTarget(self, action: #selector(continueTapped), for: .touchDown) contentView.skipButton.addTarget(self, action: #selector(skipTapped), for: .touchDown) + + // This is kind of stupid, but for some reason the table's background color will not + // go away or be forced to .clear, so just mimicing + let tablebackground = UIView() + tablebackground.backgroundColor = contentView.backgroundColor + contentView.searchEnginesTable.backgroundView = tablebackground } @objc override func continueTapped() { From 3d2cec88c13abaf84df9a38def9ffaf4f26109ab Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 23 Aug 2019 14:08:06 -1000 Subject: [PATCH 51/73] Fixed up passcode UI. --- Client/Application/AppDelegate.swift | 7 +++++++ Client/Extensions/AppearanceExtensions.swift | 3 +++ .../AuthenticationManager/BasePasscodeViewController.swift | 1 - Client/Frontend/AuthenticationManager/PasscodeViews.swift | 1 - 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Client/Application/AppDelegate.swift b/Client/Application/AppDelegate.swift index a847a461f65..cbf0bc59254 100644 --- a/Client/Application/AppDelegate.swift +++ b/Client/Application/AppDelegate.swift @@ -209,6 +209,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati // Override point for customization after application launch. var shouldPerformAdditionalDelegateHandling = true + // BVC generally handles theme applying, but in some instances views are established + // before then (e.g. passcode, so can be privacy concern, meaning this should be called ASAP) + // In order to properly apply background and align this with the rest of the UI (keyboard / header) + // this needs to be called. UI could be handled internally to view systems, + // but then keyboard may misalign with Brave selected theme override + Theme.of(nil).applyAppearanceProperties() + UIScrollView.doBadSwizzleStuff() #if BUDDYBUILD diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index 05e5547236b..06332693f9f 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -8,6 +8,9 @@ extension Theme { func applyAppearanceProperties() { // `appearance` modifications only impact UI items not current visible + + // important! for privacy concerns, otherwise UI can bleed through + UIView.appearance(whenContainedInInstancesOf: [BasePasscodeViewController.self]).appearanceBackgroundColor = colors.home UIToolbar.appearance().tintColor = colors.accent UIToolbar.appearance().backgroundColor = colors.footer diff --git a/Client/Frontend/AuthenticationManager/BasePasscodeViewController.swift b/Client/Frontend/AuthenticationManager/BasePasscodeViewController.swift index c66dad96cb6..19ee1beced9 100644 --- a/Client/Frontend/AuthenticationManager/BasePasscodeViewController.swift +++ b/Client/Frontend/AuthenticationManager/BasePasscodeViewController.swift @@ -36,7 +36,6 @@ class BasePasscodeViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = SettingsUX.TableViewHeaderBackgroundColor updateRightBarButtonItem() } diff --git a/Client/Frontend/AuthenticationManager/PasscodeViews.swift b/Client/Frontend/AuthenticationManager/PasscodeViews.swift index a036d01e979..ef8c0af323a 100644 --- a/Client/Frontend/AuthenticationManager/PasscodeViews.swift +++ b/Client/Frontend/AuthenticationManager/PasscodeViews.swift @@ -142,7 +142,6 @@ class PasscodePane: UIView { init(title: String? = nil, passcodeSize: Int = 4) { codeInputView = PasscodeInputView(passcodeSize: passcodeSize) super.init(frame: .zero) - backgroundColor = SettingsUX.TableViewHeaderBackgroundColor titleLabel.text = title centerContainer.addSubview(titleLabel) From 8f780470d6123ad95c8b2a134af7c6c6407978f1 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 23 Aug 2019 14:18:04 -1000 Subject: [PATCH 52/73] Removed `system` theme option from iOS 12 --- Client/Application/ClientPreferences.swift | 4 ++-- Client/Frontend/Widgets/Themes/Theme.swift | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Client/Application/ClientPreferences.swift b/Client/Application/ClientPreferences.swift index e27eae4d926..6d1602cac03 100644 --- a/Client/Application/ClientPreferences.swift +++ b/Client/Application/ClientPreferences.swift @@ -43,8 +43,8 @@ extension Preferences { static let tabBarVisibility = Option(key: "general.tab-bar-visiblity", default: TabBarVisibility.always.rawValue) /// Defines the user's normal browsing theme /// `system`, follows the current OS display mode - static let themeNormalMode = Option(key: "general.normal-mode-theme", default: Theme.DefaultTheme.system.id) - static let themePrivateMode = Option(key: "general.private-mode-theme", default: "C5CB0D9A-5467-432C-AB35-1A78C55CFB41") + static let themeNormalMode = Option(key: "general.normal-mode-theme", default: Theme.DefaultTheme.defaultOSChoice()) + static let themePrivateMode = Option(key: "general.private-mode-theme", default: Theme.DefaultTheme.private.id) /// Sets Desktop UA for iPad by default (iOS 13+ & iPad only) static let alwaysRequestDesktopSite = Option(key: "general.always-request-desktop-site", default: UIDevice.isIpad) /// Whether or not a user has enabled Night Mode. diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index 0463c415d47..0d918789421 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -43,7 +43,12 @@ class Theme: Equatable, Decodable { } static var normalThemesOptions: [DefaultTheme] { - return [DefaultTheme.system, DefaultTheme.light, DefaultTheme.dark] + let always = [DefaultTheme.light, DefaultTheme.dark] + if #available(iOS 13.0, *) { + return [DefaultTheme.system] + always + } else { + return always + } } public var displayString: String { @@ -52,6 +57,15 @@ class Theme: Equatable, Decodable { } return self.theme.title } + + // Used for preferences + static func defaultOSChoice() -> String { + if #available(iOS 13.0, *) { + return DefaultTheme.system.id + } else { + return DefaultTheme.light.id + } + } } fileprivate static let ThemeDirectory = Bundle.main.resourceURL!.appendingPathComponent("Themes") From 38146639c590d9492a7bbc76d144ab5601bfb8b3 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 23 Aug 2019 15:21:55 -1000 Subject: [PATCH 53/73] Keyboard adjusted based on theme. --- Client/Extensions/AppearanceExtensions.swift | 1 + Client/Frontend/Browser/TabManager.swift | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index 06332693f9f..3db0aae778a 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -46,6 +46,7 @@ extension Theme { AddEditHeaderView.appearance().appearanceBackgroundColor = tableSecondaryColor UITextField.appearance().appearanceTextColor = colors.tints.home + UITextField.appearance().keyboardAppearance = isDark ? .dark : .light if #available(iOS 13.0, *) { UIView.appearance().appearanceOverrideUserInterfaceStyle = isDark ? .dark : .light diff --git a/Client/Frontend/Browser/TabManager.swift b/Client/Frontend/Browser/TabManager.swift index b9fe4ffbfa4..6e8dff55445 100644 --- a/Client/Frontend/Browser/TabManager.swift +++ b/Client/Frontend/Browser/TabManager.swift @@ -248,13 +248,6 @@ class TabManager: NSObject { } if let tab = selectedTab { TabEvent.post(.didGainFocus, for: tab) - - switch tab.type { - case .regular: - UITextField.appearance().keyboardAppearance = .light - case .private: - UITextField.appearance().keyboardAppearance = .dark - } } guard let appDelegate = UIApplication.shared.delegate as? AppDelegate, From ce12c377300aad59f6723bdc4f9e6898bd07e8ee Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 23 Aug 2019 15:39:30 -1000 Subject: [PATCH 54/73] Fixed label coloring for iOS 12. --- Client/Extensions/AppearanceExtensions.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index 3db0aae778a..ac6d1fa66db 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -18,7 +18,7 @@ extension Theme { UINavigationBar.appearance().tintColor = colors.accent UINavigationBar.appearance().appearanceBarTintColor = colors.header - UISwitch.appearance().tintColor = colors.accent +// UISwitch.appearance().tintColor = colors.accent UISwitch.appearance().onTintColor = colors.accent // This is a subtle "abuse" of theme colors @@ -50,7 +50,12 @@ extension Theme { if #available(iOS 13.0, *) { UIView.appearance().appearanceOverrideUserInterfaceStyle = isDark ? .dark : .light + } else { + // iOS 12 fixes, many styling items do not work properly in iOS 12 + UILabel.appearance().appearanceTextColor = colors.tints.home } + + } } From e3c4fd8b42a600fbf11f0183b0f80b3c23dc78b7 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 23 Aug 2019 15:47:41 -1000 Subject: [PATCH 55/73] Modified selection mechanism for private mode button. --- .../Frontend/Browser/TabTrayButtonExtensions.swift | 13 ++++++++++--- Client/Frontend/UIConstants.swift | 6 ++---- Client/Frontend/Widgets/Themes/Theme.swift | 6 ------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Client/Frontend/Browser/TabTrayButtonExtensions.swift b/Client/Frontend/Browser/TabTrayButtonExtensions.swift index 60e3c83e8fb..29557705ae1 100644 --- a/Client/Frontend/Browser/TabTrayButtonExtensions.swift +++ b/Client/Frontend/Browser/TabTrayButtonExtensions.swift @@ -9,6 +9,15 @@ class PrivateModeButton: InsetButton, Themeable { override var isSelected: Bool { didSet { accessibilityValue = isSelected ? Strings.TabPrivateModeToggleAccessibilityValueOn : Strings.TabPrivateModeToggleAccessibilityValueOff + backgroundColor = isSelected ? selectedBackgroundColor : .clear + } + } + + var selectedBackgroundColor: UIColor? { + didSet { + if isSelected { + backgroundColor = selectedBackgroundColor + } } } @@ -30,9 +39,7 @@ class PrivateModeButton: InsetButton, Themeable { setTitleColor(theme.colors.tints.footer, for: .normal) imageView?.tintColor = tintColor - isSelected = theme.isPrivate - - backgroundColor = isSelected ? theme.colors.accent : .clear + selectedBackgroundColor = theme.colors.accent } } diff --git a/Client/Frontend/UIConstants.swift b/Client/Frontend/UIConstants.swift index f46396fdf70..1dd56e7a744 100644 --- a/Client/Frontend/UIConstants.swift +++ b/Client/Frontend/UIConstants.swift @@ -6,6 +6,8 @@ import Foundation import Shared import BraveShared +// TODO: Theme: destroy! + // A browser color represents the color of UI in both Private browsing mode and normal mode struct BrowserColor { let normalColor: UIColor @@ -23,10 +25,6 @@ struct BrowserColor { func color(isPBM: Bool) -> UIColor { return isPBM ? PBMColor : normalColor } - - func colorFor(_ theme: Theme) -> UIColor { - return color(isPBM: theme.isPrivate) - } } // Most of these should be removed diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index 0d918789421..a3c7b0e06e1 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -193,12 +193,6 @@ class Theme: Equatable, Decodable { var debugDescription: String { return description } - - // This should be removed probably - /// Returns whether the theme is private or not. - var isPrivate: Bool { - return self.isDark - } /// Returns the theme of the given Tab, if the tab is nil returns a regular theme. /// From 0e5e5ac98a8172aee06349bf83c3b171ade4cf1c Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 23 Aug 2019 15:48:39 -1000 Subject: [PATCH 56/73] Removed `BrowserColor`. --- Client/Frontend/UIConstants.swift | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/Client/Frontend/UIConstants.swift b/Client/Frontend/UIConstants.swift index 1dd56e7a744..0889d8b3686 100644 --- a/Client/Frontend/UIConstants.swift +++ b/Client/Frontend/UIConstants.swift @@ -6,27 +6,6 @@ import Foundation import Shared import BraveShared -// TODO: Theme: destroy! - -// A browser color represents the color of UI in both Private browsing mode and normal mode -struct BrowserColor { - let normalColor: UIColor - let PBMColor: UIColor - init(normal: UIColor, pbm: UIColor) { - self.normalColor = normal - self.PBMColor = pbm - } - - init(normal: Int, pbm: Int) { - self.normalColor = UIColor(rgb: normal) - self.PBMColor = UIColor(rgb: pbm) - } - - func color(isPBM: Bool) -> UIColor { - return isPBM ? PBMColor : normalColor - } -} - // Most of these should be removed extension UIColor { // These are defaults from http://design.firefox.com/photon/visuals/color.html From 771f176cfe89b8fa516b18d0bef7b6c7fbf45a54 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 23 Aug 2019 19:47:52 -1000 Subject: [PATCH 57/73] Switched to window system theme override. --- Client/Extensions/AppearanceExtensions.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index ac6d1fa66db..d7d950625d4 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -49,7 +49,8 @@ extension Theme { UITextField.appearance().keyboardAppearance = isDark ? .dark : .light if #available(iOS 13.0, *) { - UIView.appearance().appearanceOverrideUserInterfaceStyle = isDark ? .dark : .light + // Overrides all views inside of itself + UIWindow.appearance().appearanceOverrideUserInterfaceStyle = isDark ? .dark : .light } else { // iOS 12 fixes, many styling items do not work properly in iOS 12 UILabel.appearance().appearanceTextColor = colors.tints.home From 8fe3082919474f3b4743c8e88b021b5819e64544 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Mon, 26 Aug 2019 15:14:38 -1000 Subject: [PATCH 58/73] Added UIView override, since Window override not enough. --- Client/Extensions/AppearanceExtensions.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index d7d950625d4..90aef086f5b 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -50,7 +50,10 @@ extension Theme { if #available(iOS 13.0, *) { // Overrides all views inside of itself + // According to docs, UIWindow override should be enough, but some labels on iOS 13 are still messed up without UIView override as well + // (e.g. shields panel) UIWindow.appearance().appearanceOverrideUserInterfaceStyle = isDark ? .dark : .light + UIView.appearance().appearanceOverrideUserInterfaceStyle = isDark ? .dark : .light } else { // iOS 12 fixes, many styling items do not work properly in iOS 12 UILabel.appearance().appearanceTextColor = colors.tints.home From f9efb39fdd2a0789b9e59c909516602fa365227c Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Mon, 26 Aug 2019 15:22:39 -1000 Subject: [PATCH 59/73] Added theming for sync screens. --- Client/Extensions/AppearanceExtensions.swift | 6 ++++-- .../Sync/SyncAddDeviceViewController.swift | 4 ---- Client/Frontend/Sync/SyncCameraView.swift | 1 - .../SyncSelectDeviceTypeViewController.swift | 17 ++++++++++++----- Client/Frontend/Sync/SyncViewController.swift | 12 ++++++------ .../Sync/SyncWelcomeViewController.swift | 2 -- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index 90aef086f5b..dd7d5040654 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -48,6 +48,10 @@ extension Theme { UITextField.appearance().appearanceTextColor = colors.tints.home UITextField.appearance().keyboardAppearance = isDark ? .dark : .light + // Sync items + SyncViewController.SyncView.appearance(whenContainedInInstancesOf: [UINavigationController.self]).appearanceBackgroundColor = colors.home + SyncDeviceTypeButton.appearance().appearanceBackgroundColor = colors.addressBar + if #available(iOS 13.0, *) { // Overrides all views inside of itself // According to docs, UIWindow override should be enough, but some labels on iOS 13 are still messed up without UIView override as well @@ -58,8 +62,6 @@ extension Theme { // iOS 12 fixes, many styling items do not work properly in iOS 12 UILabel.appearance().appearanceTextColor = colors.tints.home } - - } } diff --git a/Client/Frontend/Sync/SyncAddDeviceViewController.swift b/Client/Frontend/Sync/SyncAddDeviceViewController.swift index 2199ff4ea24..e6b6c4bed27 100644 --- a/Client/Frontend/Sync/SyncAddDeviceViewController.swift +++ b/Client/Frontend/Sync/SyncAddDeviceViewController.swift @@ -24,7 +24,6 @@ class SyncAddDeviceViewController: SyncViewController { lazy var codewordsView: UILabel = { let label = UILabel() label.font = UIFont.systemFont(ofSize: 18.0, weight: UIFont.Weight.medium) - label.textColor = BraveUX.GreyJ label.lineBreakMode = NSLineBreakMode.byWordWrapping label.numberOfLines = 0 return label @@ -93,7 +92,6 @@ class SyncAddDeviceViewController: SyncViewController { containerView = UIView() containerView.translatesAutoresizingMaskIntoConstraints = false - containerView.backgroundColor = UIColor.white containerView.layer.cornerRadius = 8 containerView.layer.masksToBounds = true @@ -155,12 +153,10 @@ class SyncAddDeviceViewController: SyncViewController { titleLabel = UILabel() titleLabel.translatesAutoresizingMaskIntoConstraints = false titleLabel.font = UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.semibold) - titleLabel.textColor = BraveUX.GreyJ titleDescriptionStackView.addArrangedSubview(titleLabel) descriptionLabel = UILabel() descriptionLabel.font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.regular) - descriptionLabel.textColor = BraveUX.GreyH descriptionLabel.numberOfLines = 0 descriptionLabel.lineBreakMode = .byTruncatingTail descriptionLabel.textAlignment = .center diff --git a/Client/Frontend/Sync/SyncCameraView.swift b/Client/Frontend/Sync/SyncCameraView.swift index 2e78e28435b..d654b787745 100644 --- a/Client/Frontend/Sync/SyncCameraView.swift +++ b/Client/Frontend/Sync/SyncCameraView.swift @@ -30,7 +30,6 @@ class SyncCameraView: UIView, AVCaptureMetadataOutputObjectsDelegate { cameraOverlayView = UIImageView(image: UIImage(named: "camera-overlay")?.withRenderingMode(.alwaysTemplate)) cameraOverlayView.contentMode = .center - cameraOverlayView.tintColor = UIColor.white addSubview(cameraOverlayView) addSubview(cameraAccessButton) addSubview(openSettingsButton) diff --git a/Client/Frontend/Sync/SyncSelectDeviceTypeViewController.swift b/Client/Frontend/Sync/SyncSelectDeviceTypeViewController.swift index 1c91e325f2d..8f506b5bd6a 100644 --- a/Client/Frontend/Sync/SyncSelectDeviceTypeViewController.swift +++ b/Client/Frontend/Sync/SyncSelectDeviceTypeViewController.swift @@ -12,16 +12,26 @@ class SyncDeviceTypeButton: UIControl { var imageView: UIImageView = UIImageView() var label: UILabel = UILabel() var type: DeviceType! + + // Color for the opposite state of `pressed` + private var pressedReversedColor = BraveUX.BraveOrange var pressed: Bool = false { didSet { + if pressed == oldValue { + // Needed with usage of `pressedReversedColor` + return + } + + let newColor = pressedReversedColor + pressedReversedColor = label.textColor + label.textColor = newColor + if pressed { - label.textColor = BraveUX.BraveOrange if let anim = POPSpringAnimation(propertyNamed: kPOPLayerScaleXY) { anim.toValue = NSValue(cgSize: CGSize(width: 0.9, height: 0.9)) layer.pop_add(anim, forKey: "size") } } else { - label.textColor = BraveUX.GreyJ if let anim = POPSpringAnimation(propertyNamed: kPOPLayerScaleXY) { anim.toValue = NSValue(cgSize: CGSize(width: 1.0, height: 1.0)) layer.pop_add(anim, forKey: "size") @@ -34,7 +44,6 @@ class SyncDeviceTypeButton: UIControl { self.init(frame: CGRect.zero) clipsToBounds = false - backgroundColor = UIColor.white layer.cornerRadius = 12 layer.shadowColor = BraveUX.GreyJ.cgColor layer.shadowRadius = 3 @@ -48,7 +57,6 @@ class SyncDeviceTypeButton: UIControl { label.text = title label.font = UIFont.systemFont(ofSize: 17.0, weight: UIFont.Weight.bold) - label.textColor = BraveUX.GreyJ label.textAlignment = .center addSubview(label) @@ -100,7 +108,6 @@ class SyncSelectDeviceTypeViewController: SyncViewController { $0.textAlignment = .center $0.numberOfLines = 0 $0.font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.regular) - $0.textColor = BraveUX.GreyH } let mainStackView = UIStackView().then { diff --git a/Client/Frontend/Sync/SyncViewController.swift b/Client/Frontend/Sync/SyncViewController.swift index 42237ff8e6f..a79f68f2068 100644 --- a/Client/Frontend/Sync/SyncViewController.swift +++ b/Client/Frontend/Sync/SyncViewController.swift @@ -5,10 +5,6 @@ import Shared import BraveShared import Data -struct SyncUX { - static let backgroundColor = UIColor(rgb: 0xF8F8F8) -} - class RoundInterfaceButton: UIButton { override func layoutSubviews() { super.layoutSubviews() @@ -18,10 +14,12 @@ class RoundInterfaceButton: UIButton { class SyncViewController: UIViewController { + override func loadView() { + view = SyncView() + } + override func viewDidLoad() { super.viewDidLoad() - - view.backgroundColor = SyncUX.backgroundColor NotificationCenter.default.addObserver(self, selector: #selector(didLeaveSyncGroup), name: Sync.Notifications.didLeaveSyncGroup, object: nil) } @@ -45,4 +43,6 @@ class SyncViewController: UIViewController { self?.navigationController?.popToRootViewController(animated: true) } } + + class SyncView: UIView {} } diff --git a/Client/Frontend/Sync/SyncWelcomeViewController.swift b/Client/Frontend/Sync/SyncWelcomeViewController.swift index c34cbc28d6b..6c3503f8176 100644 --- a/Client/Frontend/Sync/SyncWelcomeViewController.swift +++ b/Client/Frontend/Sync/SyncWelcomeViewController.swift @@ -43,7 +43,6 @@ class SyncWelcomeViewController: SyncViewController { let label = UILabel() label.translatesAutoresizingMaskIntoConstraints = false label.font = UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.semibold) - label.textColor = BraveUX.GreyJ label.text = Strings.BraveSync label.textAlignment = .center return label @@ -53,7 +52,6 @@ class SyncWelcomeViewController: SyncViewController { let label = UILabel() label.translatesAutoresizingMaskIntoConstraints = false label.font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.regular) - label.textColor = BraveUX.GreyH label.numberOfLines = 0 label.lineBreakMode = .byWordWrapping label.textAlignment = .center From c9da2e708b9256118d131f6293f05697d2a77522 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Wed, 28 Aug 2019 17:15:56 -1000 Subject: [PATCH 60/73] Fixed up addressbar, home, and header color usage. --- Client/Extensions/AppearanceExtensions.swift | 6 +++--- Client/Frontend/Browser/TabsBar/TabBarCell.swift | 2 +- .../Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index dd7d5040654..44565a89a1f 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -27,9 +27,9 @@ extension Theme { // Any change to a single tableView property that currently uses one of these will probably have odd behavior and must be thoroughly tested /// Used as color a table will use as the base (e.g. background) - let tablePrimaryColor = colors.header + let tablePrimaryColor = colors.home /// Used to augment `tablePrimaryColor` above - let tableSecondaryColor = colors.addressBar + let tableSecondaryColor = colors.header // Will become the color for whatever in the table is .clear // In some cases this is the header, footer, cell, or a combination of them. @@ -50,7 +50,7 @@ extension Theme { // Sync items SyncViewController.SyncView.appearance(whenContainedInInstancesOf: [UINavigationController.self]).appearanceBackgroundColor = colors.home - SyncDeviceTypeButton.appearance().appearanceBackgroundColor = colors.addressBar + SyncDeviceTypeButton.appearance().appearanceBackgroundColor = colors.header if #available(iOS 13.0, *) { // Overrides all views inside of itself diff --git a/Client/Frontend/Browser/TabsBar/TabBarCell.swift b/Client/Frontend/Browser/TabsBar/TabBarCell.swift index 7364913e1fb..2712ac00009 100644 --- a/Client/Frontend/Browser/TabsBar/TabBarCell.swift +++ b/Client/Frontend/Browser/TabsBar/TabBarCell.swift @@ -104,7 +104,7 @@ class TabBarCell: UICollectionViewCell { titleLabel.font = UIFont.systemFont(ofSize: 12) titleLabel.textColor = theme.colors.tints.header.withAlphaComponent(0.4) closeButton.isHidden = true - backgroundColor = theme.colors.addressBar + backgroundColor = theme.colors.header } } } diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift b/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift index 7bdfbd48047..7c62c6716bd 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift @@ -73,7 +73,7 @@ extension UrlBarTextField: Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) - backgroundColor = theme.colors.addressBar + backgroundColor = theme.colors.addressBar.withAlphaComponent(theme.colors.transparencies.addressBarAlpha) textColor = theme.colors.tints.header clearButtonTintColor = textColor highlightColor = textColor!.withAlphaComponent(0.2) From b391bfcf05fbb22c57f6e0f021f54d68f3dcabdf Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Thu, 29 Aug 2019 16:33:51 -1000 Subject: [PATCH 61/73] Updated dark and private theme files. --- .../Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json | 8 ++++---- .../Themes/C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json b/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json index 582f294dda3..2b1d5d863fa 100644 --- a/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json +++ b/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json @@ -8,10 +8,10 @@ "enabled": true, "colors": { - "header": "0x000000", - "footer": "0x000000", - "home": "0x0A0A0A", - "addressBar": "0x262626", + "header": "0x222222", + "footer": "0x222222", + "home": "0x1c1c1c", + "addressBar": "0x444444", "border": "0xffffff", "accent": "0xff631c", "tints": { diff --git a/Client/Assets/Themes/C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json b/Client/Assets/Themes/C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json index 113fc47eb71..09c2bbeb7c3 100644 --- a/Client/Assets/Themes/C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json +++ b/Client/Assets/Themes/C5CB0D9A-5467-432C-AB35-1A78C55CFB41.json @@ -10,7 +10,7 @@ "colors": { "header": "0x1B0C32", "footer": "0x1B0C32", - "home": "0x210950", + "home": "0x301B5A", "addressBar": "0x3D2742", "border": "0xffffff", "accent": "0xcf68ff", From d35ad4b075a17fa022368607b1baadc5092e6685 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Thu, 29 Aug 2019 16:34:14 -1000 Subject: [PATCH 62/73] Updated all theme copy and made it translatable. --- BraveShared/BraveStrings.swift | 9 ++++++++- .../Frontend/Settings/SettingsViewController.swift | 5 +++-- Client/Frontend/Widgets/Themes/Theme.swift | 14 +++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/BraveShared/BraveStrings.swift b/BraveShared/BraveStrings.swift index 94ddd5f29f2..7976c4afa4e 100644 --- a/BraveShared/BraveStrings.swift +++ b/BraveShared/BraveStrings.swift @@ -444,7 +444,6 @@ extension Strings { extension Strings { public static let Block_Popups = NSLocalizedString("BlockPopups", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Block Popups", comment: "Setting to enable popup blocking") public static let Show_Tabs_Bar = NSLocalizedString("ShowTabsBar", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Show Tabs Bar", comment: "Setting to show/hide the tabs bar") - public static let Normal_Mode_Theme = NSLocalizedString("NormalModeTheme", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Theme for Normal Browsing", comment: "Setting to choose the user interface theme for normal browsing mode, contains choices like 'light' or 'dark' themes") public static let Private_Browsing_Only = NSLocalizedString("PrivateBrowsingOnly", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Private Browsing Only", comment: "Setting to keep app in private mode") public static let Brave_Shield_Defaults = NSLocalizedString("BraveShieldDefaults", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Brave Shield Defaults", comment: "Section title for adbblock, tracking protection, HTTPS-E, and cookies") public static let Block_Ads_and_Tracking = NSLocalizedString("BlockAdsAndTracking", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Block Ads & Tracking", comment: "") @@ -519,6 +518,14 @@ extension Strings { public static let ShareWithMenuItem = NSLocalizedString("ShareWithMenuItem", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Share with...", comment: "Title for sharing url menu item") public static let DownloadsMenuItem = NSLocalizedString("DownloadsMenuItem", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Downloads", comment: "Title for downloads menu item") public static let DownloadsPanelEmptyStateTitle = NSLocalizedString("DownloadsPanelEmptyStateTitle", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Downloaded files will show up here.", comment: "Title for when a user has nothing downloaded onto their device, and the list is empty.") + + // MARK: - Themes + + public static let ThemesDisplayBrightness = NSLocalizedString("ThemesDisplayBrightness", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Display & Brightness", comment: "Setting to choose the user interface theme for normal browsing mode, contains choices like 'light' or 'dark' themes") + public static let ThemesDisplayBrightnessFooter = NSLocalizedString("ThemesDisplayBrightnessFooter", tableName: "BraveShared", bundle: Bundle.braveShared, value: "These settings are not applied in private browsing mode.", comment: "Text specifying that the above setting does not impact the user interface while they user is in private browsing mode.") + public static let ThemesAutomaticOption = NSLocalizedString("ThemesAutomaticOption", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Automatic", comment: "Selection to automatically color/style the user interface.") + public static let ThemesLightOption = NSLocalizedString("ThemesLightOption", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Light", comment: "Selection to color/style the user interface with a light theme.") + public static let ThemesDarkOption = NSLocalizedString("ThemesDarkOption", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Dark", comment: "Selection to color/style the user interface with a dark theme") } // MARK: - Quick Actions diff --git a/Client/Frontend/Settings/SettingsViewController.swift b/Client/Frontend/Settings/SettingsViewController.swift index 3d8e81b59e7..5c0bce175f4 100644 --- a/Client/Frontend/Settings/SettingsViewController.swift +++ b/Client/Frontend/Settings/SettingsViewController.swift @@ -171,7 +171,7 @@ class SettingsViewController: TableViewController { } let themeSubtitle = Theme.DefaultTheme(rawValue: Preferences.General.themeNormalMode.value)?.displayString - var row = Row(text: Strings.Normal_Mode_Theme, detailText: themeSubtitle, accessory: .disclosureIndicator, cellClass: MultilineSubtitleCell.self) + var row = Row(text: Strings.ThemesDisplayBrightness, detailText: themeSubtitle, accessory: .disclosureIndicator, cellClass: MultilineSubtitleCell.self) row.selection = { [unowned self] in let optionsViewController = OptionSelectionViewController( options: Theme.DefaultTheme.normalThemesOptions, @@ -182,7 +182,8 @@ class SettingsViewController: TableViewController { self.applyTheme(self.theme) } ) - optionsViewController.headerText = Strings.Normal_Mode_Theme + optionsViewController.headerText = Strings.ThemesDisplayBrightness + optionsViewController.footerText = Strings.ThemesDisplayBrightnessFooter self.navigationController?.pushViewController(optionsViewController, animated: true) } general.rows.append(row) diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index a3c7b0e06e1..bb75a133c28 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -4,6 +4,7 @@ import Foundation import BraveShared +import Shared protocol Themeable { @@ -52,10 +53,17 @@ class Theme: Equatable, Decodable { } public var displayString: String { - if self == .system { - return "System Theme" + // Due to translations needs, titles are hardcoded here, ideally they would be pulled from the + // theme files themselves. + + switch self { + case .system: return Strings.ThemesAutomaticOption + case .light: return Strings.ThemesLightOption + case .dark: return Strings.ThemesDarkOption + + // Should not be visible, but making explicit so compiler will capture any `DefaultTheme` modifications + case .private: return "" } - return self.theme.title } // Used for preferences From 82d429e75c49e0156fb37bffc54782c86f300ac2 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 30 Aug 2019 16:40:18 -1000 Subject: [PATCH 63/73] Fixed up theme for search suggestions. --- Client/Extensions/AppearanceExtensions.swift | 4 ++++ .../Browser/Search/SearchSuggestionsPromptView.swift | 5 ----- Client/Frontend/Browser/Search/SearchViewController.swift | 4 ---- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index 44565a89a1f..f17d7122486 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -52,6 +52,10 @@ extension Theme { SyncViewController.SyncView.appearance(whenContainedInInstancesOf: [UINavigationController.self]).appearanceBackgroundColor = colors.home SyncDeviceTypeButton.appearance().appearanceBackgroundColor = colors.header + // Search + UIView.appearance(whenContainedInInstancesOf: [SearchViewController.self]).appearanceBackgroundColor = colors.home + InsetButton.appearance(whenContainedInInstancesOf: [SearchViewController.self]).appearanceBackgroundColor = .clear + if #available(iOS 13.0, *) { // Overrides all views inside of itself // According to docs, UIWindow override should be enough, but some labels on iOS 13 are still messed up without UIView override as well diff --git a/Client/Frontend/Browser/Search/SearchSuggestionsPromptView.swift b/Client/Frontend/Browser/Search/SearchSuggestionsPromptView.swift index 22c7e957b7b..a122f30dbaa 100644 --- a/Client/Frontend/Browser/Search/SearchSuggestionsPromptView.swift +++ b/Client/Frontend/Browser/Search/SearchSuggestionsPromptView.swift @@ -16,7 +16,6 @@ class SearchSuggestionPromptView: UIView { static let PromptYesFont = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.bold) static let PromptNoFont = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.regular) static let PromptInsets = UIEdgeInsets(top: 15, left: 12, bottom: 15, right: 12) - static let PromptButtonColor = BraveUX.Blue } init(optionSelected: @escaping (Bool) -> Void) { @@ -24,8 +23,6 @@ class SearchSuggestionPromptView: UIView { super.init(frame: .zero) - backgroundColor = UX.PromptColor - let promptBottomBorder = UIView() promptBottomBorder.backgroundColor = BraveUX.GreyD addSubview(promptBottomBorder) @@ -44,7 +41,6 @@ class SearchSuggestionPromptView: UIView { let promptYesButton = InsetButton() promptYesButton.setTitle(Strings.Yes, for: .normal) - promptYesButton.setTitleColor(UX.PromptButtonColor, for: .normal) promptYesButton.titleLabel?.font = UX.PromptYesFont promptYesButton.titleEdgeInsets = UX.PromptInsets // If the prompt message doesn't fit, this prevents it from pushing the buttons @@ -55,7 +51,6 @@ class SearchSuggestionPromptView: UIView { let promptNoButton = InsetButton() promptNoButton.setTitle(Strings.No, for: .normal) - promptNoButton.setTitleColor(UX.PromptButtonColor, for: .normal) promptNoButton.titleLabel?.font = UX.PromptNoFont promptNoButton.titleEdgeInsets = UX.PromptInsets // If the prompt message doesn't fit, this prevents it from pushing the buttons diff --git a/Client/Frontend/Browser/Search/SearchViewController.swift b/Client/Frontend/Browser/Search/SearchViewController.swift index 057fa0a627c..11db4574ce2 100644 --- a/Client/Frontend/Browser/Search/SearchViewController.swift +++ b/Client/Frontend/Browser/Search/SearchViewController.swift @@ -82,7 +82,6 @@ class SearchViewController: SiteTableViewController, KeyboardHelperDelegate, Loa } override func viewDidLoad() { - view.backgroundColor = UIConstants.PanelBackgroundColor let blur = UIVisualEffectView(effect: UIBlurEffect(style: .light)) view.addSubview(blur) @@ -90,7 +89,6 @@ class SearchViewController: SiteTableViewController, KeyboardHelperDelegate, Loa KeyboardHelper.defaultHelper.addDelegate(self) - searchEngineScrollView.layer.backgroundColor = SearchViewControllerUX.SearchEngineScrollViewBackgroundColor searchEngineScrollView.layer.shadowRadius = 0 searchEngineScrollView.layer.shadowOpacity = 100 searchEngineScrollView.layer.shadowOffset = CGSize(width: 0, height: -SearchViewControllerUX.SearchEngineTopBorderWidth) @@ -769,8 +767,6 @@ fileprivate class SuggestionButton: InsetButton { setTitleColor(UIConstants.HighlightBlue, for: []) setTitleColor(UIColor.Photon.White100, for: .highlighted) titleLabel?.font = DynamicFontHelper.defaultHelper.DefaultMediumFont - backgroundColor = SearchViewControllerUX.SuggestionBackgroundColor - layer.borderColor = SearchViewControllerUX.SuggestionBorderColor.cgColor layer.borderWidth = SearchViewControllerUX.SuggestionBorderWidth layer.cornerRadius = SearchViewControllerUX.SuggestionCornerRadius contentEdgeInsets = SearchViewControllerUX.SuggestionInsets From 0877f496e047967475ef9aed548742f96eef1821 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 30 Aug 2019 17:11:31 -1000 Subject: [PATCH 64/73] Updated Light and Dark metadata theme files. --- .../Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json | 2 +- .../Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json b/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json index 32ad6237739..01245611cbe 100644 --- a/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json +++ b/Client/Assets/Themes/ACE618A3-D6FC-45A4-94F2-1793C40AE927.json @@ -10,7 +10,7 @@ "colors": { "header": "0xf4f4f4", "footer": "0xf8f8f8", - "home": "0xf1f1f1", + "home": "0xe8e8e8", "addressBar": "0xffffff", "border": "0x000000", "accent": "0xfb542b", diff --git a/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json b/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json index 2b1d5d863fa..33bcf1caa60 100644 --- a/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json +++ b/Client/Assets/Themes/B900A41F-2C02-4664-9DE4-C170956339AC.json @@ -8,8 +8,8 @@ "enabled": true, "colors": { - "header": "0x222222", - "footer": "0x222222", + "header": "0x282828", + "footer": "0x282828", "home": "0x1c1c1c", "addressBar": "0x444444", "border": "0xffffff", From 5e85e5cbba8e21a72fb2780b41d9c164ab8b5e2f Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Tue, 3 Sep 2019 18:42:20 -1000 Subject: [PATCH 65/73] Private mode button now themed correctly when opening menu. --- Client/Frontend/Browser/TabTrayController.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Client/Frontend/Browser/TabTrayController.swift b/Client/Frontend/Browser/TabTrayController.swift index adb6b3b960f..ab1577bdee8 100644 --- a/Client/Frontend/Browser/TabTrayController.swift +++ b/Client/Frontend/Browser/TabTrayController.swift @@ -235,6 +235,7 @@ class TabTrayController: UIViewController, Themeable { * the related tab's theme, here this is not possible, so using hardened values 😕😭 */ applyTheme(Theme.of(nil)) + toolbar.privateModeButton.isSelected = privateMode collectionView?.reloadData() setNeedsStatusBarAppearanceUpdate() } @@ -465,10 +466,9 @@ class TabTrayController: UIViewController, Themeable { tabManager.willSwitchTabMode(leavingPBM: privateMode) privateMode = !privateMode - //When we switch from Private => Regular make sure we reset _selectedIndex, fix for bug #888 + // When we switch from Private => Regular make sure we reset _selectedIndex, fix for bug #888 tabManager.resetSelectedIndex() - - toolbar.privateModeButton.isSelected = privateMode + collectionView.layoutSubviews() let toView: UIView From 7e0d1261c83f70420f3ce6cc55cf6ee5d40e38b1 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Wed, 4 Sep 2019 15:09:19 -1000 Subject: [PATCH 66/73] Updated iOS 12 theming to better support upgrading to iOS 13. --- Client/Application/ClientPreferences.swift | 2 +- Client/Frontend/Widgets/Themes/Theme.swift | 25 ++++++++++------------ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Client/Application/ClientPreferences.swift b/Client/Application/ClientPreferences.swift index b785a7e2988..551c114e4ac 100644 --- a/Client/Application/ClientPreferences.swift +++ b/Client/Application/ClientPreferences.swift @@ -43,7 +43,7 @@ extension Preferences { static let tabBarVisibility = Option(key: "general.tab-bar-visiblity", default: TabBarVisibility.always.rawValue) /// Defines the user's normal browsing theme /// `system`, follows the current OS display mode - static let themeNormalMode = Option(key: "general.normal-mode-theme", default: Theme.DefaultTheme.defaultOSChoice()) + static let themeNormalMode = Option(key: "general.normal-mode-theme", default: Theme.DefaultTheme.system.id) static let themePrivateMode = Option(key: "general.private-mode-theme", default: Theme.DefaultTheme.private.id) /// Specifies whether the bookmark button is present on toolbar static let showBookmarkToolbarShortcut = Option(key: "general.show-bookmark-toolbar-shortcut", default: UIDevice.isIpad) diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index bb75a133c28..359193c05b7 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -33,7 +33,7 @@ class Theme: Equatable, Decodable { case light = "ACE618A3-D6FC-45A4-94F2-1793C40AE927" case dark = "B900A41F-2C02-4664-9DE4-C170956339AC" case `private` = "C5CB0D9A-5467-432C-AB35-1A78C55CFB41" - + // TODO: Theme: Remove with `rawValue` var id: String { return self.rawValue @@ -44,11 +44,11 @@ class Theme: Equatable, Decodable { } static var normalThemesOptions: [DefaultTheme] { - let always = [DefaultTheme.light, DefaultTheme.dark] if #available(iOS 13.0, *) { - return [DefaultTheme.system] + always + return [DefaultTheme.system, DefaultTheme.light, DefaultTheme.dark] } else { - return always + // iOS 12 .system is treated as .light + return [DefaultTheme.system, DefaultTheme.dark] } } @@ -56,6 +56,13 @@ class Theme: Equatable, Decodable { // Due to translations needs, titles are hardcoded here, ideally they would be pulled from the // theme files themselves. + if #available(iOS 13.0, *) { + // continue + } else if self == .system { + // iOS 12 .system is treated as .light + return Strings.ThemesLightOption + } + switch self { case .system: return Strings.ThemesAutomaticOption case .light: return Strings.ThemesLightOption @@ -65,15 +72,6 @@ class Theme: Equatable, Decodable { case .private: return "" } } - - // Used for preferences - static func defaultOSChoice() -> String { - if #available(iOS 13.0, *) { - return DefaultTheme.system.id - } else { - return DefaultTheme.light.id - } - } } fileprivate static let ThemeDirectory = Bundle.main.resourceURL!.appendingPathComponent("Themes") @@ -233,7 +231,6 @@ class Theme: Equatable, Decodable { static func from(id: String) -> Theme { var id = id if id == DefaultTheme.system.id { - // TODO: Pull system default, not 'light' necessarily id = currentSystemThemeId } From b0ee4717872972abd4bcaeae417b325abc17ddf3 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Thu, 5 Sep 2019 18:35:45 -1000 Subject: [PATCH 67/73] Fix #1488: Changing Private Browsing Only, adjusts theme correctly. --- .../Settings/SettingsViewController.swift | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Client/Frontend/Settings/SettingsViewController.swift b/Client/Frontend/Settings/SettingsViewController.swift index 1b7f2290f14..80478d66984 100644 --- a/Client/Frontend/Settings/SettingsViewController.swift +++ b/Client/Frontend/Settings/SettingsViewController.swift @@ -291,7 +291,24 @@ class SettingsViewController: TableViewController { } }) ] - privacy.rows.append(BoolRow(title: Strings.Private_Browsing_Only, option: Preferences.Privacy.privateBrowsingOnly)) + privacy.rows.append( + BoolRow( + title: Strings.Private_Browsing_Only, + option: Preferences.Privacy.privateBrowsingOnly, + onValueChange: { + Preferences.Privacy.privateBrowsingOnly.value = $0 + + // Need to flush the table, hacky, but works consistenly and well + let superView = self.tableView.superview + self.tableView.removeFromSuperview() + DispatchQueue.main.async { + // Let shield toggle change propagate, otherwise theme may not be set properly + superView?.addSubview(self.tableView) + self.applyTheme(self.theme) + } + } + ) + ) return privacy }() From 21b880fd62cedd5382162868d8fca3fd6194f5c7 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Thu, 5 Sep 2019 19:12:31 -1000 Subject: [PATCH 68/73] Cleaned up a bunch of comments and cleaned up code. --- BraveShared/BraveUX.swift | 1 - Client/Frontend/Browser/BrowserViewController.swift | 3 +-- .../Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift | 2 +- .../Browser/Toolbars/UrlBar/UrlBarTextField.swift | 8 +++++--- .../Settings/SettingsTableSectionHeaderFooterView.swift | 1 - Client/Frontend/Settings/SettingsViewController.swift | 1 - Client/Frontend/Sync/SyncViewController.swift | 1 + Client/Frontend/UIConstants.swift | 4 +--- 8 files changed, 9 insertions(+), 12 deletions(-) diff --git a/BraveShared/BraveUX.swift b/BraveShared/BraveUX.swift index ae1d9e7535b..6b0f8db1713 100644 --- a/BraveShared/BraveUX.swift +++ b/BraveShared/BraveUX.swift @@ -1,6 +1,5 @@ /* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -// TODO: Theme: Clean up colors public struct BraveUX { public static let BraveCommunityURL = URL(string: "https://community.brave.com/")! public static let BravePrivacyURL = URL(string: "https://brave.com/privacy/")! diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index e9765c81499..f10a80684c6 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -2523,7 +2523,7 @@ extension BrowserViewController: ReaderModeBarViewDelegate { let setupPopover = { [unowned self] in if let popoverPresentationController = readerModeStyleViewController.popoverPresentationController { - popoverPresentationController.backgroundColor = UIColor.Photon.White100 // todo: dynamic + popoverPresentationController.backgroundColor = UIColor.Photon.White100 popoverPresentationController.delegate = self popoverPresentationController.sourceView = readerModeBar popoverPresentationController.sourceRect = CGRect(x: readerModeBar.frame.width/2, y: UIConstants.ToolbarHeight, width: 1, height: 1) @@ -2911,7 +2911,6 @@ extension BrowserViewController: Themeable { theme.applyAppearanceProperties() - // TODO: Theme: Maybe just set to clear color? statusBarOverlay.backgroundColor = topToolbar.backgroundColor setNeedsStatusBarAppearanceUpdate() } diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift index f183339cb7e..34562124250 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/TopToolbarView.swift @@ -145,7 +145,7 @@ class TopToolbarView: UIView, ToolbarProtocol { var forwardButton = ToolbarButton(top: true) var shareButton = ToolbarButton(top: true) var addTabButton = ToolbarButton(top: true) - lazy var menuButton = ToolbarButton(top: true).then { // + lazy var menuButton = ToolbarButton(top: true).then { $0.contentMode = .center $0.accessibilityIdentifier = "topToolbarView-menuButton" } diff --git a/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift b/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift index 7c62c6716bd..4795983f5ba 100644 --- a/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift +++ b/Client/Frontend/Browser/Toolbars/UrlBar/UrlBarTextField.swift @@ -74,8 +74,10 @@ extension UrlBarTextField: Themeable { styleChildren(theme: theme) backgroundColor = theme.colors.addressBar.withAlphaComponent(theme.colors.transparencies.addressBarAlpha) - textColor = theme.colors.tints.header - clearButtonTintColor = textColor - highlightColor = textColor!.withAlphaComponent(0.2) + + let text = theme.colors.tints.header + textColor = text + clearButtonTintColor = text + highlightColor = text.withAlphaComponent(0.2) } } diff --git a/Client/Frontend/Settings/SettingsTableSectionHeaderFooterView.swift b/Client/Frontend/Settings/SettingsTableSectionHeaderFooterView.swift index 0ae0b02e10a..0dc288a28d5 100644 --- a/Client/Frontend/Settings/SettingsTableSectionHeaderFooterView.swift +++ b/Client/Frontend/Settings/SettingsTableSectionHeaderFooterView.swift @@ -5,7 +5,6 @@ import Shared import UIKit -// TODO: Theme: Remove a bunch of these struct SettingsUX { static let TableViewHeaderBackgroundColor = UIConstants.AppBackgroundColor static let TableViewHeaderTextColor = UIColor.Photon.Grey50 diff --git a/Client/Frontend/Settings/SettingsViewController.swift b/Client/Frontend/Settings/SettingsViewController.swift index 80478d66984..e884a6827f6 100644 --- a/Client/Frontend/Settings/SettingsViewController.swift +++ b/Client/Frontend/Settings/SettingsViewController.swift @@ -141,7 +141,6 @@ class SettingsViewController: TableViewController { ] ) - // TODO: This can be further abstracted to align with an entire OptionSelectionVC for both tab and theme visibility let reloadCell = { (row: Row, displayString: String) in if let indexPath = self.dataSource.indexPath(rowUUID: row.uuid, sectionUUID: general.uuid) { self.dataSource.sections[indexPath.section].rows[indexPath.row].detailText = displayString diff --git a/Client/Frontend/Sync/SyncViewController.swift b/Client/Frontend/Sync/SyncViewController.swift index a79f68f2068..1f36e13b1e1 100644 --- a/Client/Frontend/Sync/SyncViewController.swift +++ b/Client/Frontend/Sync/SyncViewController.swift @@ -44,5 +44,6 @@ class SyncViewController: UIViewController { } } + // This is used for `appearance()` usage, so can target sync background views class SyncView: UIView {} } diff --git a/Client/Frontend/UIConstants.swift b/Client/Frontend/UIConstants.swift index 0889d8b3686..e5020148098 100644 --- a/Client/Frontend/UIConstants.swift +++ b/Client/Frontend/UIConstants.swift @@ -6,20 +6,18 @@ import Foundation import Shared import BraveShared -// Most of these should be removed extension UIColor { // These are defaults from http://design.firefox.com/photon/visuals/color.html struct Defaults { static let MobileGreyF = UIColor(rgb: 0x636369) static let iOSHighlightBlue = UIColor(rgb: 0xccdded) // This color should exactly match the ios text highlight - static let Purple60A30 = UIColor(rgba: 0x8000d74c) // Maybe use this color for private theme?? + static let Purple60A30 = UIColor(rgba: 0x8000d74c) static let MobilePrivatePurple = UIColor(rgb: 0xcf68ff) static let PaleBlue = UIColor(rgb: 0xB0D5FB) static let LightBeige = UIColor(rgb: 0xf0e6dc) } } -// TODO: Theme: Delete most of this public struct UIConstants { static let AboutHomePage = URL(string: "\(WebServer.sharedInstance.base)/about/home/")! From bc537a8a215e7c03281e57bab3b6d334f200ba0a Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Thu, 5 Sep 2019 19:25:45 -1000 Subject: [PATCH 69/73] Switched from using tab.type to tab.theme for theme change detection. --- Client/Frontend/Browser/BrowserViewController.swift | 8 +++----- .../Frontend/Browser/TabsBar/TabsBarViewController.swift | 1 + .../Settings/SettingsTableSectionHeaderFooterView.swift | 2 -- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Client/Frontend/Browser/BrowserViewController.swift b/Client/Frontend/Browser/BrowserViewController.swift index f10a80684c6..c33051c3938 100644 --- a/Client/Frontend/Browser/BrowserViewController.swift +++ b/Client/Frontend/Browser/BrowserViewController.swift @@ -2004,11 +2004,9 @@ extension BrowserViewController: TabManagerDelegate { topToolbar.hideProgressBar() } - // TODO: Theme: Maybe check against Theme instead of type?? - // TODO: Theme: store past theme and block if change unneeded - if tab.type != previous?.type { - let theme = Theme.of(tab) - applyTheme(theme) + let newTheme = Theme.of(tab) + if previous == nil || newTheme != Theme.of(previous) { + applyTheme(newTheme) } readerModeCache = ReaderMode.cache(for: tab) diff --git a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift index 1b4d5617b5e..7c983835bf1 100644 --- a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift +++ b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift @@ -341,6 +341,7 @@ extension TabsBarViewController: Themeable { plusButton.tintColor = theme.colors.tints.header bottomLine.backgroundColor = theme.colors.border.withAlphaComponent(theme.colors.transparencies.borderAlpha) collectionView.backgroundColor = view.backgroundColor + // Updates overflow colors too overflowIndicators() collectionView.reloadData() diff --git a/Client/Frontend/Settings/SettingsTableSectionHeaderFooterView.swift b/Client/Frontend/Settings/SettingsTableSectionHeaderFooterView.swift index 0dc288a28d5..dc15ff09ceb 100644 --- a/Client/Frontend/Settings/SettingsTableSectionHeaderFooterView.swift +++ b/Client/Frontend/Settings/SettingsTableSectionHeaderFooterView.swift @@ -46,8 +46,6 @@ class SettingsTableSectionHeaderFooterView: UITableViewHeaderFooterView { override init(reuseIdentifier: String?) { super.init(reuseIdentifier: reuseIdentifier) - backgroundView = UIView() - backgroundView?.backgroundColor = .clear addSubview(titleLabel) setupInitialConstraints() From 38f5e5dfc626813569f340137e7d6dcd28c26ee3 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Thu, 5 Sep 2019 19:31:30 -1000 Subject: [PATCH 70/73] Removed unneeded comment. --- Client/Frontend/Widgets/Themes/Theme.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index 359193c05b7..239717be90b 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -14,7 +14,6 @@ protocol Themeable { } extension Themeable { - // TODO: Remove, should be explicity done on each Themeable view, but doing this to avoid tons of compile errors var themeableChildren: [Themeable?]? { return nil } func applyTheme(_ theme: Theme) { From c8b5721aa1b9123328a609ba5f8e4aef7a434eeb Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 6 Sep 2019 04:52:32 -1000 Subject: [PATCH 71/73] Cleaned up comments. --- Client/Extensions/AppearanceExtensions.swift | 1 - Client/Frontend/Browser/TabTrayController.swift | 9 ++++----- Client/Frontend/Widgets/Themes/Theme.swift | 3 ++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Client/Extensions/AppearanceExtensions.swift b/Client/Extensions/AppearanceExtensions.swift index f17d7122486..241ba77fedc 100644 --- a/Client/Extensions/AppearanceExtensions.swift +++ b/Client/Extensions/AppearanceExtensions.swift @@ -18,7 +18,6 @@ extension Theme { UINavigationBar.appearance().tintColor = colors.accent UINavigationBar.appearance().appearanceBarTintColor = colors.header -// UISwitch.appearance().tintColor = colors.accent UISwitch.appearance().onTintColor = colors.accent // This is a subtle "abuse" of theme colors diff --git a/Client/Frontend/Browser/TabTrayController.swift b/Client/Frontend/Browser/TabTrayController.swift index ab1577bdee8..53522b487f4 100644 --- a/Client/Frontend/Browser/TabTrayController.swift +++ b/Client/Frontend/Browser/TabTrayController.swift @@ -229,11 +229,10 @@ class TabTrayController: UIViewController, Themeable { // Should be set immediately before other logic executes PrivateBrowsingManager.shared.isPrivateBrowsing = privateMode tabDataSource.tabs = tabManager.tabsForCurrentMode - /* - * This is a little tricky since this menu is one of the only places inside of the appliation - * that has a state without gauranteeing a tab exists. Most UI elements should use `theme` or at the least - * the related tab's theme, here this is not possible, so using hardened values 😕😭 - */ + + // This is a little tricky since this menu is one of the only places inside of the appliation + // that has a state without gauranteeing a tab exists. Most UI elements should use `theme` or at the least + // the related tab's theme, here this is not possible, so using hardened values 😕😭 applyTheme(Theme.of(nil)) toolbar.privateModeButton.isSelected = privateMode collectionView?.reloadData() diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index 239717be90b..9f252c24170 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -9,8 +9,9 @@ import Shared protocol Themeable { var themeableChildren: [Themeable?]? { get } + + // This method should _always_ call `styleChildren`, regardless of `themableChildren` value. func applyTheme(_ theme: Theme) - } extension Themeable { From 50fb67f57d16a1b01fc8062228b95071bfb869a1 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 6 Sep 2019 04:53:13 -1000 Subject: [PATCH 72/73] Improved ShieldView API for themeable interface. --- Client/Frontend/Shields/ShieldsView.swift | 7 +++++-- Client/Frontend/Shields/ShieldsViewController.swift | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Client/Frontend/Shields/ShieldsView.swift b/Client/Frontend/Shields/ShieldsView.swift index c0b6a57a446..ca2ebb726ba 100644 --- a/Client/Frontend/Shields/ShieldsView.swift +++ b/Client/Frontend/Shields/ShieldsView.swift @@ -8,7 +8,7 @@ import BraveShared extension ShieldsViewController { /// The custom loaded view for the `ShieldsViewController` - class View: UIView { + class View: UIView, Themeable { private let scrollView = UIScrollView() let stackView: UIStackView = { @@ -63,7 +63,10 @@ extension ShieldsViewController { fatalError() } - func set(theme: Theme) { + // MARK: - Themeable + func applyTheme(_ theme: Theme) { + styleChildren(theme: theme) + backgroundColor = theme.colors.home // Overview diff --git a/Client/Frontend/Shields/ShieldsViewController.swift b/Client/Frontend/Shields/ShieldsViewController.swift index dfb9e8ff8bc..7a3779c6bf0 100644 --- a/Client/Frontend/Shields/ShieldsViewController.swift +++ b/Client/Frontend/Shields/ShieldsViewController.swift @@ -144,7 +144,7 @@ class ShieldsViewController: UIViewController, PopoverContentComponent { override func loadView() { view = View() - shieldsView.set(theme: Theme.of(tab)) + shieldsView.applyTheme(Theme.of(tab)) } override func viewDidLoad() { From 4c90ca819042f64ca27324e55a1eebb390dc6032 Mon Sep 17 00:00:00 2001 From: Joel Reis Date: Fri, 6 Sep 2019 04:56:30 -1000 Subject: [PATCH 73/73] Removed DefaultTheme's `id` prop (use rawValue). --- Client/Application/ClientPreferences.swift | 4 ++-- Client/Frontend/Widgets/Themes/Theme.swift | 13 ++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/Client/Application/ClientPreferences.swift b/Client/Application/ClientPreferences.swift index 551c114e4ac..fdc403db0d4 100644 --- a/Client/Application/ClientPreferences.swift +++ b/Client/Application/ClientPreferences.swift @@ -43,8 +43,8 @@ extension Preferences { static let tabBarVisibility = Option(key: "general.tab-bar-visiblity", default: TabBarVisibility.always.rawValue) /// Defines the user's normal browsing theme /// `system`, follows the current OS display mode - static let themeNormalMode = Option(key: "general.normal-mode-theme", default: Theme.DefaultTheme.system.id) - static let themePrivateMode = Option(key: "general.private-mode-theme", default: Theme.DefaultTheme.private.id) + static let themeNormalMode = Option(key: "general.normal-mode-theme", default: Theme.DefaultTheme.system.rawValue) + static let themePrivateMode = Option(key: "general.private-mode-theme", default: Theme.DefaultTheme.private.rawValue) /// Specifies whether the bookmark button is present on toolbar static let showBookmarkToolbarShortcut = Option(key: "general.show-bookmark-toolbar-shortcut", default: UIDevice.isIpad) /// Sets Desktop UA for iPad by default (iOS 13+ & iPad only) diff --git a/Client/Frontend/Widgets/Themes/Theme.swift b/Client/Frontend/Widgets/Themes/Theme.swift index 9f252c24170..164183af514 100644 --- a/Client/Frontend/Widgets/Themes/Theme.swift +++ b/Client/Frontend/Widgets/Themes/Theme.swift @@ -33,14 +33,9 @@ class Theme: Equatable, Decodable { case light = "ACE618A3-D6FC-45A4-94F2-1793C40AE927" case dark = "B900A41F-2C02-4664-9DE4-C170956339AC" case `private` = "C5CB0D9A-5467-432C-AB35-1A78C55CFB41" - - // TODO: Theme: Remove with `rawValue` - var id: String { - return self.rawValue - } var theme: Theme { - return Theme.from(id: self.id) + return Theme.from(id: self.rawValue) } static var normalThemesOptions: [DefaultTheme] { @@ -230,7 +225,7 @@ class Theme: Equatable, Decodable { static var themeMemoryBank: [String: Theme] = [:] static func from(id: String) -> Theme { var id = id - if id == DefaultTheme.system.id { + if id == DefaultTheme.system.rawValue { id = currentSystemThemeId } @@ -253,10 +248,10 @@ class Theme: Equatable, Decodable { private static var currentSystemThemeId: String { // Should really be based off of preferences, a dark theme and light theme preference - let fallback = DefaultTheme.light.id + let fallback = DefaultTheme.light.rawValue if #available(iOS 13.0, *) { let isDark = UITraitCollection.current.userInterfaceStyle == .dark - return isDark ? DefaultTheme.dark.id : fallback + return isDark ? DefaultTheme.dark.rawValue : fallback } return fallback }