From b68066aee453977ad485ff43b2061c44dcce795a Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Wed, 22 Sep 2021 17:08:03 +0200 Subject: [PATCH 01/13] Update Settings and Home to use ThemeService instead of Style --- Riot/Managers/Theme/Themes/DefaultTheme.swift | 35 +++----- Tchap/Modules/Common/Style/Appearance.swift | 12 +-- Tchap/Modules/Home/HomeViewController.swift | 21 +++-- .../CountryPickerViewController.h | 3 +- .../CountryPickerViewController.m | 43 +++++---- .../Modules/Settings/SettingsViewController.m | 89 +++++++++---------- 6 files changed, 91 insertions(+), 112 deletions(-) diff --git a/Riot/Managers/Theme/Themes/DefaultTheme.swift b/Riot/Managers/Theme/Themes/DefaultTheme.swift index f38dfcf758..9d6f52423a 100644 --- a/Riot/Managers/Theme/Themes/DefaultTheme.swift +++ b/Riot/Managers/Theme/Themes/DefaultTheme.swift @@ -95,7 +95,7 @@ class DefaultTheme: NSObject, Theme { // Note: We are not using UINavigationBarAppearance on iOS 13+ atm because of UINavigationBar directly include UISearchBar on their titleView that cause crop issues with UINavigationController pop. func applyStyle(onNavigationBar navigationBar: UINavigationBar) { - navigationBar.tintColor = self.baseTextPrimaryColor + navigationBar.tintColor = self.tintColor navigationBar.titleTextAttributes = [ NSAttributedString.Key.foregroundColor: self.baseTextPrimaryColor ] @@ -108,30 +108,21 @@ class DefaultTheme: NSObject, Theme { } func applyStyle(onSearchBar searchBar: UISearchBar) { - searchBar.barStyle = .default - searchBar.tintColor = self.searchPlaceholderColor - searchBar.barTintColor = self.headerBackgroundColor + searchBar.searchBarStyle = .default + searchBar.barTintColor = self.baseColor + searchBar.isTranslucent = false + searchBar.backgroundImage = UIImage() // Remove top and bottom shadow + searchBar.tintColor = self.tintColor - if let searchBarTextField = searchBar.vc_searchTextField { - searchBarTextField.textColor = searchBar.tintColor + if #available(iOS 13.0, *) { + searchBar.searchTextField.backgroundColor = self.searchBackgroundColor + searchBar.searchTextField.textColor = self.searchPlaceholderColor + } else { + if let searchBarTextField = searchBar.vc_searchTextField { + searchBarTextField.textColor = self.searchPlaceholderColor + } } } -// func applyStyle(onSearchBar searchBar: UISearchBar) { -// searchBar.searchBarStyle = .default -// searchBar.barTintColor = self.baseColor -// searchBar.isTranslucent = false -// searchBar.backgroundImage = UIImage() // Remove top and bottom shadow -// searchBar.tintColor = self.tintColor -// -// if #available(iOS 13.0, *) { -// searchBar.searchTextField.backgroundColor = self.searchBackgroundColor -// searchBar.searchTextField.textColor = self.searchPlaceholderColor -// } else { -// if let searchBarTextField = searchBar.vc_searchTextField { -// searchBarTextField.textColor = self.searchPlaceholderColor -// } -// } -// } func applyStyle(onTextField texField: UITextField) { texField.textColor = self.textPrimaryColor diff --git a/Tchap/Modules/Common/Style/Appearance.swift b/Tchap/Modules/Common/Style/Appearance.swift index 96d84db391..e4f3d490fc 100644 --- a/Tchap/Modules/Common/Style/Appearance.swift +++ b/Tchap/Modules/Common/Style/Appearance.swift @@ -26,11 +26,11 @@ struct Appearance { // UISearchBar textColor could not be set directly static func setupSearchBarAppearance() { - UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self, UINavigationBar.self]).defaultTextAttributes = [NSAttributedString.Key.foregroundColor: Variant1Style.shared.barActionColor] - - // Since iOS 11 UISearchController is set as navigationItem and displayed under UINavigationBar in UINavigationController - if #available(iOS 11.0, *) { - UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self, UINavigationController.self]).defaultTextAttributes = [NSAttributedString.Key.foregroundColor: Variant1Style.shared.barActionColor] - } +// UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self, UINavigationBar.self]).defaultTextAttributes = [NSAttributedString.Key.foregroundColor: Variant1Style.shared.barActionColor] +// +// // Since iOS 11 UISearchController is set as navigationItem and displayed under UINavigationBar in UINavigationController +// if #available(iOS 11.0, *) { +// UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self, UINavigationController.self]).defaultTextAttributes = [NSAttributedString.Key.foregroundColor: Variant1Style.shared.barActionColor] +// } } } diff --git a/Tchap/Modules/Home/HomeViewController.swift b/Tchap/Modules/Home/HomeViewController.swift index b1a2a1dbfa..c7482398f8 100644 --- a/Tchap/Modules/Home/HomeViewController.swift +++ b/Tchap/Modules/Home/HomeViewController.swift @@ -34,7 +34,6 @@ final class HomeViewController: UIViewController { // MARK: Private private var globalSearchBar: GlobalSearchBar! - private var currentStyle: Style! private var segmentedViewController: SegmentedViewController? private var segmentViewControllers: [UIViewController] = [] private var segmentViewControllersTitles: [String] = [] @@ -48,12 +47,13 @@ final class HomeViewController: UIViewController { // MARK: - Setup - class func instantiate(with viewControllers: [UIViewController], viewControllersTitles: [String], globalSearchBar: GlobalSearchBar, style: Style = Variant1Style.shared) -> HomeViewController { + class func instantiate(with viewControllers: [UIViewController], + viewControllersTitles: [String], + globalSearchBar: GlobalSearchBar) -> HomeViewController { let viewController = StoryboardScene.HomeViewController.initialScene.instantiate() viewController.segmentViewControllers = viewControllers viewController.segmentViewControllersTitles = viewControllersTitles viewController.globalSearchBar = globalSearchBar - viewController.currentStyle = style return viewController } @@ -62,6 +62,7 @@ final class HomeViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() + self.setupTheme() self.setupGlobalSearchBar() self.setupSegmentedViewController() self.setupPlusButton() @@ -74,7 +75,7 @@ final class HomeViewController: UIViewController { } override var preferredStatusBarStyle: UIStatusBarStyle { - return self.currentStyle.statusBarStyle + return ThemeService.shared().theme.statusBarStyle } func setExternalUseMode(_ isExternal: Bool) { @@ -144,15 +145,13 @@ final class HomeViewController: UIViewController { } } -// MARK: - Stylable -extension HomeViewController: Stylable { - func update(style: Style) { - self.currentStyle = style - - self.view.backgroundColor = style.backgroundColor +// MARK: - Theme +private extension HomeViewController { + func setupTheme() { + self.view.backgroundColor = ThemeService.shared().theme.backgroundColor if let navigationBar = self.navigationController?.navigationBar { - style.applyStyle(onNavigationBar: navigationBar) + ThemeService.shared().theme.applyStyle(onNavigationBar: navigationBar) } } } diff --git a/Tchap/Modules/Settings/PhoneCountry/CountryPickerViewController.h b/Tchap/Modules/Settings/PhoneCountry/CountryPickerViewController.h index 3a166a24a6..e2b0e1928a 100644 --- a/Tchap/Modules/Settings/PhoneCountry/CountryPickerViewController.h +++ b/Tchap/Modules/Settings/PhoneCountry/CountryPickerViewController.h @@ -23,9 +23,8 @@ /** Creates and returns a new `CountryPickerViewController` object. - @param style Used to setup view style parameters. @return An initialized `CountryPickerViewController` object if successful, `nil` otherwise. */ -+ (nonnull instancetype)instantiateWithStyle:(nonnull id