From cb8722c24480bb81e0d130c7cba7f10f3c208523 Mon Sep 17 00:00:00 2001 From: Natalia Harateh Date: Fri, 23 Aug 2019 15:13:24 -0400 Subject: [PATCH 01/12] pass theme as an object --- WMF Framework/Theme.swift | 4 ++++ Wikipedia/Code/ReadingThemesControlsViewController.swift | 4 +--- Wikipedia/Code/WMFAppViewController.m | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/WMF Framework/Theme.swift b/WMF Framework/Theme.swift index 92900bfe53e..1e181980693 100644 --- a/WMF Framework/Theme.swift +++ b/WMF Framework/Theme.swift @@ -454,3 +454,7 @@ public protocol Themeable : class { @objc(applyTheme:) func apply(theme: Theme) //this might be better as a var theme: Theme { get set } - common VC superclasses could check for viewIfLoaded and call an update method in the setter. This would elminate the need for the viewIfLoaded logic in every applyTheme: } + +@objc public extension Theme { + @objc static let didChangeNotification = NSNotification.Name(rawValue: "WMFThemeDidChangeNotification") +} diff --git a/Wikipedia/Code/ReadingThemesControlsViewController.swift b/Wikipedia/Code/ReadingThemesControlsViewController.swift index eec02955370..d3b1ba84f99 100644 --- a/Wikipedia/Code/ReadingThemesControlsViewController.swift +++ b/Wikipedia/Code/ReadingThemesControlsViewController.swift @@ -10,7 +10,6 @@ protocol WMFReadingThemesControlsViewControllerDelegate: class { class ReadingThemesControlsViewController: UIViewController { @objc static let WMFUserDidSelectThemeNotification = "WMFUserDidSelectThemeNotification" - @objc static let WMFUserDidSelectThemeNotificationThemeKey = "theme" @objc static let nibName = "ReadingThemesControlsViewController" var theme = Theme.standard @@ -195,8 +194,7 @@ class ReadingThemesControlsViewController: UIViewController { } func userDidSelect(theme: Theme) { - let userInfo = ["theme": theme] - NotificationCenter.default.post(name: Notification.Name(ReadingThemesControlsViewController.WMFUserDidSelectThemeNotification), object: nil, userInfo: userInfo) + NotificationCenter.default.post(name: Theme.didChangeNotification, object: theme) } @IBAction func sepiaThemeButtonPressed(_ sender: Any) { diff --git a/Wikipedia/Code/WMFAppViewController.m b/Wikipedia/Code/WMFAppViewController.m index f630ac3f493..a6c88e39015 100644 --- a/Wikipedia/Code/WMFAppViewController.m +++ b/Wikipedia/Code/WMFAppViewController.m @@ -154,7 +154,7 @@ - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheme:) - name:WMFReadingThemesControlsViewController.WMFUserDidSelectThemeNotification + name:WMFTheme.didChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(articleFontSizeWasUpdated:) @@ -1858,7 +1858,7 @@ - (void)applyTheme:(WMFTheme *)theme { } - (void)changeTheme:(NSNotification *)note { - WMFTheme *theme = (WMFTheme *)note.userInfo[WMFReadingThemesControlsViewController.WMFUserDidSelectThemeNotificationThemeKey]; + WMFTheme *theme = (WMFTheme *)note.object; if (self.theme != theme) { [self applyTheme:theme]; From 23a6f05db4ec3c08b770f3764180f01865d5b273 Mon Sep 17 00:00:00 2001 From: Natalia Harateh Date: Fri, 23 Aug 2019 15:13:42 -0400 Subject: [PATCH 02/12] add extensions to adjust theme --- WMF Framework/Theme.swift | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/WMF Framework/Theme.swift b/WMF Framework/Theme.swift index 1e181980693..faf6d4ef967 100644 --- a/WMF Framework/Theme.swift +++ b/WMF Framework/Theme.swift @@ -458,3 +458,39 @@ public protocol Themeable : class { @objc public extension Theme { @objc static let didChangeNotification = NSNotification.Name(rawValue: "WMFThemeDidChangeNotification") } + +private extension Themeable where Self: UITraitEnvironment { + @available(iOS 12.0, *) + func adjustTheme(_ previousTraitCollection: UITraitCollection?) { + let newUserInterfaceStyle = traitCollection.userInterfaceStyle + guard previousTraitCollection?.userInterfaceStyle != newUserInterfaceStyle else { + return + } + let newTheme: Theme = newUserInterfaceStyle == .dark ? .black : .standard + NotificationCenter.default.post(name: Theme.didChangeNotification, object: newTheme) + } +} + +@objc public extension UIViewController { + func adjustTheme(_ previousTraitCollection: UITraitCollection?) { + guard + #available(iOS 12.0, *), + let self = self as? (Themeable & UITraitEnvironment) + else { + return + } + self.adjustTheme(previousTraitCollection) + } +} + +@objc public extension UIView { + func adjustTheme(_ previousTraitCollection: UITraitCollection?) { + guard + #available(iOS 12.0, *), + let self = self as? (Themeable & UITraitEnvironment) + else { + return + } + self.adjustTheme(previousTraitCollection) + } +} From 5989ff156f4409fa67a5cdf6fe74c600f0e92374 Mon Sep 17 00:00:00 2001 From: Natalia Harateh Date: Fri, 23 Aug 2019 15:14:20 -0400 Subject: [PATCH 03/12] call adjustTheme in VCs --- Wikipedia/Code/CreateReadingListViewController.swift | 5 +++++ .../Code/ReadingListDetailUnderBarViewController.swift | 1 + Wikipedia/Code/SavedProgressViewController.swift | 5 +++++ Wikipedia/Code/SearchBarExtendedViewController.swift | 1 + Wikipedia/Code/ShareViewController.swift | 5 +++++ Wikipedia/Code/ViewController.swift | 5 +++++ Wikipedia/Code/WMFAppViewController.m | 7 +++++++ 7 files changed, 29 insertions(+) diff --git a/Wikipedia/Code/CreateReadingListViewController.swift b/Wikipedia/Code/CreateReadingListViewController.swift index 156d100ea0c..5219baa3a0f 100644 --- a/Wikipedia/Code/CreateReadingListViewController.swift +++ b/Wikipedia/Code/CreateReadingListViewController.swift @@ -36,6 +36,11 @@ class CreateReadingListViewController: WMFScrollViewController, UITextFieldDeleg createReadingListButton.isEnabled = false } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } override func viewWillDisappear(_ animated: Bool) { view.endEditing(false) diff --git a/Wikipedia/Code/ReadingListDetailUnderBarViewController.swift b/Wikipedia/Code/ReadingListDetailUnderBarViewController.swift index c1638a15028..1427e62e551 100644 --- a/Wikipedia/Code/ReadingListDetailUnderBarViewController.swift +++ b/Wikipedia/Code/ReadingListDetailUnderBarViewController.swift @@ -44,6 +44,7 @@ class ReadingListDetailUnderBarViewController: UIViewController { override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) articleCountLabel.font = UIFont.wmf_font(.semiboldFootnote, compatibleWithTraitCollection: traitCollection) titleTextField.font = UIFont.wmf_font(.boldTitle1, compatibleWithTraitCollection: traitCollection) descriptionTextField.font = UIFont.wmf_font(.footnote, compatibleWithTraitCollection: traitCollection) diff --git a/Wikipedia/Code/SavedProgressViewController.swift b/Wikipedia/Code/SavedProgressViewController.swift index d581c3bc9c0..030dd76a6b9 100644 --- a/Wikipedia/Code/SavedProgressViewController.swift +++ b/Wikipedia/Code/SavedProgressViewController.swift @@ -67,6 +67,11 @@ class SavedProgressViewController: UIViewController, Themeable { self?.view.isHidden = isHidden }) } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } func apply(theme: Theme) { self.theme = theme diff --git a/Wikipedia/Code/SearchBarExtendedViewController.swift b/Wikipedia/Code/SearchBarExtendedViewController.swift index 555eb853023..e0da1ce6231 100644 --- a/Wikipedia/Code/SearchBarExtendedViewController.swift +++ b/Wikipedia/Code/SearchBarExtendedViewController.swift @@ -61,6 +61,7 @@ class SearchBarExtendedViewController: UIViewController { override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) if let textStyle = dataSource?.textStyle(for: button) { button.titleLabel?.font = UIFont.wmf_font(textStyle, compatibleWithTraitCollection: traitCollection) } diff --git a/Wikipedia/Code/ShareViewController.swift b/Wikipedia/Code/ShareViewController.swift index 4f58dec8c0d..5bf8d8019fe 100644 --- a/Wikipedia/Code/ShareViewController.swift +++ b/Wikipedia/Code/ShareViewController.swift @@ -120,6 +120,11 @@ class ShareViewController: UIViewController, Themeable { }) } + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } + @IBAction func cancel(_ sender: Any) { dismiss(animated: true, completion: nil) } diff --git a/Wikipedia/Code/ViewController.swift b/Wikipedia/Code/ViewController.swift index a0ab026779d..7cabf1c17ab 100644 --- a/Wikipedia/Code/ViewController.swift +++ b/Wikipedia/Code/ViewController.swift @@ -218,6 +218,11 @@ class ViewController: PreviewingViewController, Themeable, NavigationBarHiderDel super.viewDidLayoutSubviews() updateScrollViewInsets() } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } // MARK - Scroll View Insets diff --git a/Wikipedia/Code/WMFAppViewController.m b/Wikipedia/Code/WMFAppViewController.m index a6c88e39015..a04350c97b7 100644 --- a/Wikipedia/Code/WMFAppViewController.m +++ b/Wikipedia/Code/WMFAppViewController.m @@ -233,6 +233,13 @@ - (void)viewDidLoad { self.editHintController = [[WMFEditHintController alloc] init]; self.talkPageReplyHintController = [[WMFTalkPageReplyHintController alloc] init]; self.talkPageTopicHintController = [[WMFTalkPageTopicHintController alloc] init]; + + [self adjustTheme:nil]; +} + +- (void)traitCollectionDidChange:(nullable UITraitCollection *)previousTraitCollection { + [super traitCollectionDidChange:previousTraitCollection]; + [self adjustTheme:previousTraitCollection]; } - (UIStatusBarStyle)preferredStatusBarStyle { From f71c5e0e01b40ce4496f474199d7e5519512a9df Mon Sep 17 00:00:00 2001 From: Natalia Harateh Date: Fri, 23 Aug 2019 18:46:20 -0400 Subject: [PATCH 04/12] guard against updating theme if it's not different --- WMF Framework/Theme.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WMF Framework/Theme.swift b/WMF Framework/Theme.swift index faf6d4ef967..8db3055b066 100644 --- a/WMF Framework/Theme.swift +++ b/WMF Framework/Theme.swift @@ -467,6 +467,9 @@ private extension Themeable where Self: UITraitEnvironment { return } let newTheme: Theme = newUserInterfaceStyle == .dark ? .black : .standard + guard newTheme != UserDefaults.wmf.wmf_appTheme else { + return + } NotificationCenter.default.post(name: Theme.didChangeNotification, object: newTheme) } } From ce5fcb1e9def906164d6641cf266e71f34084275 Mon Sep 17 00:00:00 2001 From: Natalia Harateh Date: Fri, 23 Aug 2019 18:46:54 -0400 Subject: [PATCH 05/12] remove custom setters, apply colors in applyTheme --- Wikipedia/Code/WMFSettingsTableViewCell.m | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Wikipedia/Code/WMFSettingsTableViewCell.m b/Wikipedia/Code/WMFSettingsTableViewCell.m index 0a06d3df40a..65be70c6f9b 100644 --- a/Wikipedia/Code/WMFSettingsTableViewCell.m +++ b/Wikipedia/Code/WMFSettingsTableViewCell.m @@ -127,16 +127,6 @@ - (void)didToggleDisclosureSwitch:(UISwitch *)sender { [self.delegate settingsTableViewCell:self didToggleDisclosureSwitch:sender]; } -- (void)setIconColor:(UIColor *)iconColor { - _iconColor = iconColor; - self.titleIcon.tintColor = iconColor; -} - -- (void)setIconBackgroundColor:(UIColor *)iconBackgroundColor { - _iconBackgroundColor = iconBackgroundColor; - self.titleIcon.backgroundColor = iconBackgroundColor; -} - - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; //HAX: reset the titleIcon's background color so it remains during the selection cell selection animation. @@ -198,7 +188,9 @@ - (void)applyTheme:(WMFTheme *)theme { self.subtitleLabel.textColor = theme.colors.secondaryText; self.disclosureLabel.textColor = theme.colors.secondaryText; self.iconBackgroundColor = theme.colors.iconBackground == NULL ? self.iconBackgroundColor : theme.colors.iconBackground; + self.titleIcon.backgroundColor = self.iconBackgroundColor; self.iconColor = theme.colors.icon == NULL ? self.iconColor : theme.colors.icon; + self.titleIcon.tintColor = self.iconColor; self.disclosureIcon.tintColor = theme.colors.secondaryText; self.disclosureSwitch.backgroundColor = theme.colors.paperBackground; self.labelBackgroundColor = [UIColor clearColor]; From 9e59b85ba9ac7c504469b89369366e6695081dad Mon Sep 17 00:00:00 2001 From: Natalia Harateh Date: Fri, 23 Aug 2019 18:50:06 -0400 Subject: [PATCH 06/12] call adjustTheme --- WMF Framework/BatchEditToolbarViewController.swift | 5 +++++ WMF Framework/WMFCaptchaViewController.swift | 5 +++++ Wikipedia/Code/AboutViewController.m | 7 +++++++ Wikipedia/Code/BaseExploreFeedSettingsViewController.swift | 6 ++++++ Wikipedia/Code/CreateReadingListViewController.swift | 7 +------ .../Code/DescriptionWelcomeContainerViewController.swift | 5 +++++ .../Code/DescriptionWelcomeContentsViewController.swift | 5 +++++ .../Code/DescriptionWelcomeInitialViewController.swift | 5 +++++ Wikipedia/Code/DescriptionWelcomePageViewController.swift | 1 + Wikipedia/Code/DescriptionWelcomePanelViewController.swift | 5 +++++ Wikipedia/Code/LibrariesUsed.swift | 5 +++++ Wikipedia/Code/NewsViewController.swift | 1 + Wikipedia/Code/SearchSettingsViewController.swift | 1 + .../Code/StorageAndSyncingSettingsViewController.swift | 1 + Wikipedia/Code/SubSettingsViewController.swift | 5 +++++ Wikipedia/Code/TalkPageContainerViewController.swift | 3 +++ Wikipedia/Code/TalkPageReplyListViewController.swift | 1 + Wikipedia/Code/TalkPageTopicListViewController.swift | 1 + Wikipedia/Code/TextSizeChangeExampleViewController.swift | 5 +++++ Wikipedia/Code/WMFScrollViewController.swift | 5 +++++ Wikipedia/Code/WMFViewController.m | 5 +++++ 21 files changed, 78 insertions(+), 6 deletions(-) diff --git a/WMF Framework/BatchEditToolbarViewController.swift b/WMF Framework/BatchEditToolbarViewController.swift index 3a6ad08f5e7..81b5ab43810 100644 --- a/WMF Framework/BatchEditToolbarViewController.swift +++ b/WMF Framework/BatchEditToolbarViewController.swift @@ -33,6 +33,11 @@ public final class BatchEditToolbarViewController: UIViewController { } apply(theme: theme) } + + override public func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } } extension BatchEditToolbarViewController: Themeable { diff --git a/WMF Framework/WMFCaptchaViewController.swift b/WMF Framework/WMFCaptchaViewController.swift index caf3f8db4d0..8ff65e18b02 100644 --- a/WMF Framework/WMFCaptchaViewController.swift +++ b/WMF Framework/WMFCaptchaViewController.swift @@ -162,6 +162,11 @@ class WMFCaptchaViewController: UIViewController, UITextFieldDelegate, Themeable apply(theme: theme) } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } @objc func requestAnAccountTapped(_ recognizer: UITapGestureRecognizer) { wmf_openExternalUrl(URL.init(string: "https://en.wikipedia.org/wiki/Wikipedia:Request_an_account")) diff --git a/Wikipedia/Code/AboutViewController.m b/Wikipedia/Code/AboutViewController.m index 62c81876a27..6997b3e452e 100644 --- a/Wikipedia/Code/AboutViewController.m +++ b/Wikipedia/Code/AboutViewController.m @@ -147,6 +147,11 @@ - (void)viewDidLoad { [self updateNavigationBar]; } +- (void)traitCollectionDidChange:(nullable UITraitCollection *)previousTraitCollection { + [super traitCollectionDidChange:previousTraitCollection]; + [self adjustTheme:previousTraitCollection]; +} + - (void)closeButtonPressed { [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; @@ -348,6 +353,8 @@ - (void)applyTheme:(WMFTheme *)theme { return; } self.view.backgroundColor = theme.colors.paperBackground; + [self.webView wmf_setTextFontColor:self.theme]; + [self.webView wmf_setLogoStyleWithTheme:self.theme]; } @end diff --git a/Wikipedia/Code/BaseExploreFeedSettingsViewController.swift b/Wikipedia/Code/BaseExploreFeedSettingsViewController.swift index 5c3e8fb79ca..774cc8cfff3 100644 --- a/Wikipedia/Code/BaseExploreFeedSettingsViewController.swift +++ b/Wikipedia/Code/BaseExploreFeedSettingsViewController.swift @@ -166,6 +166,11 @@ class BaseExploreFeedSettingsViewController: SubSettingsViewController { NotificationCenter.default.addObserver(self, selector: #selector(newExploreFeedPreferencesWereRejected(_:)), name: NSNotification.Name.WMFNewExploreFeedPreferencesWereRejected, object: nil) } + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } + var preferredLanguages: [MWKLanguageLink] { return MWKLanguageLinkController.sharedInstance().preferredLanguages } @@ -252,6 +257,7 @@ class BaseExploreFeedSettingsViewController: SubSettingsViewController { return } tableView.backgroundColor = theme.colors.baseBackground + tableView.reloadData() } } diff --git a/Wikipedia/Code/CreateReadingListViewController.swift b/Wikipedia/Code/CreateReadingListViewController.swift index 5219baa3a0f..84fc9984463 100644 --- a/Wikipedia/Code/CreateReadingListViewController.swift +++ b/Wikipedia/Code/CreateReadingListViewController.swift @@ -37,11 +37,6 @@ class CreateReadingListViewController: WMFScrollViewController, UITextFieldDeleg createReadingListButton.isEnabled = false } - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - adjustTheme(previousTraitCollection) - } - override func viewWillDisappear(_ animated: Bool) { view.endEditing(false) } @@ -143,7 +138,7 @@ extension CreateReadingListViewController: Themeable { view.backgroundColor = theme.colors.paperBackground view.tintColor = theme.colors.link - + readingListNameTextField.apply(theme: theme) descriptionTextField.apply(theme: theme) diff --git a/Wikipedia/Code/DescriptionWelcomeContainerViewController.swift b/Wikipedia/Code/DescriptionWelcomeContainerViewController.swift index d8e2d52201a..fc2f8732d92 100644 --- a/Wikipedia/Code/DescriptionWelcomeContainerViewController.swift +++ b/Wikipedia/Code/DescriptionWelcomeContainerViewController.swift @@ -31,6 +31,11 @@ class DescriptionWelcomeContainerViewController: UIViewController, Themeable { hasAlreadyFadedInAndUp = true } } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } private func shouldFadeInAndUp() -> Bool { switch pageType { diff --git a/Wikipedia/Code/DescriptionWelcomeContentsViewController.swift b/Wikipedia/Code/DescriptionWelcomeContentsViewController.swift index f5048d01807..f5f393bb868 100644 --- a/Wikipedia/Code/DescriptionWelcomeContentsViewController.swift +++ b/Wikipedia/Code/DescriptionWelcomeContentsViewController.swift @@ -19,6 +19,11 @@ class DescriptionWelcomeContentsViewController: UIViewController, Themeable { apply(theme: theme) view.wmf_configureSubviewsForDynamicType() } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } private func updateUIStrings(){ switch pageType { diff --git a/Wikipedia/Code/DescriptionWelcomeInitialViewController.swift b/Wikipedia/Code/DescriptionWelcomeInitialViewController.swift index 2eaa54eebaf..61348711287 100644 --- a/Wikipedia/Code/DescriptionWelcomeInitialViewController.swift +++ b/Wikipedia/Code/DescriptionWelcomeInitialViewController.swift @@ -26,6 +26,11 @@ class DescriptionWelcomeInitialViewController: UIViewController, Themeable { super.viewDidLoad() apply(theme: theme) } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } override var prefersStatusBarHidden: Bool { return false diff --git a/Wikipedia/Code/DescriptionWelcomePageViewController.swift b/Wikipedia/Code/DescriptionWelcomePageViewController.swift index 48066e14cd3..39657e50285 100644 --- a/Wikipedia/Code/DescriptionWelcomePageViewController.swift +++ b/Wikipedia/Code/DescriptionWelcomePageViewController.swift @@ -127,6 +127,7 @@ class DescriptionWelcomePageViewController: UIPageViewController, UIPageViewCont override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) skipButton.titleLabel?.font = UIFont.wmf_font(.semiboldFootnote, compatibleWithTraitCollection: traitCollection) nextButton.titleLabel?.font = UIFont.wmf_font(.semiboldFootnote, compatibleWithTraitCollection: traitCollection) } diff --git a/Wikipedia/Code/DescriptionWelcomePanelViewController.swift b/Wikipedia/Code/DescriptionWelcomePanelViewController.swift index 73a7f9eee09..e0a262e5f6d 100644 --- a/Wikipedia/Code/DescriptionWelcomePanelViewController.swift +++ b/Wikipedia/Code/DescriptionWelcomePanelViewController.swift @@ -35,6 +35,11 @@ class DescriptionWelcomePanelViewController: UIViewController, Themeable { view.wmf_configureSubviewsForDynamicType() } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } private func embedContainerControllerView() { let containerController = DescriptionWelcomeContentsViewController.wmf_viewControllerFromDescriptionWelcomeStoryboard() diff --git a/Wikipedia/Code/LibrariesUsed.swift b/Wikipedia/Code/LibrariesUsed.swift index eaf1bb6c19f..228e1ff5ab2 100644 --- a/Wikipedia/Code/LibrariesUsed.swift +++ b/Wikipedia/Code/LibrariesUsed.swift @@ -72,6 +72,11 @@ class LibrariesUsedViewController: UIViewController, UITableViewDelegate, UITabl } libraries = librariesUsed(from: plistPath) } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } private func librariesUsed(from plistPath: String) -> [LibraryUsed] { guard diff --git a/Wikipedia/Code/NewsViewController.swift b/Wikipedia/Code/NewsViewController.swift index 408430ead05..57b7756aa33 100644 --- a/Wikipedia/Code/NewsViewController.swift +++ b/Wikipedia/Code/NewsViewController.swift @@ -75,6 +75,7 @@ class NewsViewController: ColumnarCollectionViewController, DetailPresentingFrom } view.backgroundColor = theme.colors.paperBackground collectionView.backgroundColor = theme.colors.paperBackground + collectionView.reloadData() } // MARK: - UIViewControllerPreviewingDelegate diff --git a/Wikipedia/Code/SearchSettingsViewController.swift b/Wikipedia/Code/SearchSettingsViewController.swift index 0fad26610aa..76b565567b1 100644 --- a/Wikipedia/Code/SearchSettingsViewController.swift +++ b/Wikipedia/Code/SearchSettingsViewController.swift @@ -48,6 +48,7 @@ final class SearchSettingsViewController: SubSettingsViewController { } view.backgroundColor = theme.colors.baseBackground tableView.backgroundColor = theme.colors.baseBackground + tableView.reloadData() } } diff --git a/Wikipedia/Code/StorageAndSyncingSettingsViewController.swift b/Wikipedia/Code/StorageAndSyncingSettingsViewController.swift index cf203868115..bed955957a2 100644 --- a/Wikipedia/Code/StorageAndSyncingSettingsViewController.swift +++ b/Wikipedia/Code/StorageAndSyncingSettingsViewController.swift @@ -174,6 +174,7 @@ class StorageAndSyncingSettingsViewController: SubSettingsViewController { } tableView.backgroundColor = theme.colors.baseBackground eraseSavedArticlesView?.apply(theme: theme) + tableView.reloadData() } } diff --git a/Wikipedia/Code/SubSettingsViewController.swift b/Wikipedia/Code/SubSettingsViewController.swift index 5cdf19de940..defd1878178 100644 --- a/Wikipedia/Code/SubSettingsViewController.swift +++ b/Wikipedia/Code/SubSettingsViewController.swift @@ -8,6 +8,11 @@ class SubSettingsViewController: ViewController { super.viewDidLoad() } + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } + override var nibName: String? { return "SubSettingsViewController" } diff --git a/Wikipedia/Code/TalkPageContainerViewController.swift b/Wikipedia/Code/TalkPageContainerViewController.swift index 4e3811b3fd1..41273d840ff 100644 --- a/Wikipedia/Code/TalkPageContainerViewController.swift +++ b/Wikipedia/Code/TalkPageContainerViewController.swift @@ -226,6 +226,9 @@ class TalkPageContainerViewController: ViewController, HintPresenting { toolbar.barTintColor = theme.colors.chromeBackground shareIcon?.apply(theme: theme) languageIcon?.apply(theme: theme) + topicListViewController?.apply(theme: theme) + replyListViewController?.apply(theme: theme) + headerView?.apply(theme: theme) } func pushToReplyThread(topic: TalkPageTopic, animated: Bool = true) { diff --git a/Wikipedia/Code/TalkPageReplyListViewController.swift b/Wikipedia/Code/TalkPageReplyListViewController.swift index b79236481e3..f0bd9052ba4 100644 --- a/Wikipedia/Code/TalkPageReplyListViewController.swift +++ b/Wikipedia/Code/TalkPageReplyListViewController.swift @@ -271,6 +271,7 @@ class TalkPageReplyListViewController: ColumnarCollectionViewController { view.backgroundColor = theme.colors.paperBackground beKindInputAccessoryView.apply(theme: theme) + headerView?.apply(theme: theme) } } diff --git a/Wikipedia/Code/TalkPageTopicListViewController.swift b/Wikipedia/Code/TalkPageTopicListViewController.swift index 8b7a36258f7..6ef23b72c45 100644 --- a/Wikipedia/Code/TalkPageTopicListViewController.swift +++ b/Wikipedia/Code/TalkPageTopicListViewController.swift @@ -155,6 +155,7 @@ class TalkPageTopicListViewController: ColumnarCollectionViewController { } collectionView.backgroundColor = theme.colors.baseBackground + collectionView.reloadData() } } diff --git a/Wikipedia/Code/TextSizeChangeExampleViewController.swift b/Wikipedia/Code/TextSizeChangeExampleViewController.swift index 7bf9e6bc77a..24414430414 100644 --- a/Wikipedia/Code/TextSizeChangeExampleViewController.swift +++ b/Wikipedia/Code/TextSizeChangeExampleViewController.swift @@ -13,6 +13,11 @@ class TextSizeChangeExampleViewController: UIViewController { NotificationCenter.default.addObserver(self, selector: #selector(self.textSizeChanged(notification:)), name: NSNotification.Name(rawValue: FontSizeSliderViewController.WMFArticleFontSizeUpdatedNotification), object: nil) } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } deinit { NotificationCenter.default.removeObserver(self) diff --git a/Wikipedia/Code/WMFScrollViewController.swift b/Wikipedia/Code/WMFScrollViewController.swift index 2c963251c1b..9767d6acb6c 100644 --- a/Wikipedia/Code/WMFScrollViewController.swift +++ b/Wikipedia/Code/WMFScrollViewController.swift @@ -13,6 +13,11 @@ class WMFScrollViewController: UIViewController { wmf_endAdjustingScrollViewInsetsForKeyboard() super.viewWillDisappear(animated) } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + adjustTheme(previousTraitCollection) + } private var coverView: UIView? func setViewControllerUserInteraction(enabled: Bool) { diff --git a/Wikipedia/Code/WMFViewController.m b/Wikipedia/Code/WMFViewController.m index 2601ff0e22d..5c5f470cd93 100644 --- a/Wikipedia/Code/WMFViewController.m +++ b/Wikipedia/Code/WMFViewController.m @@ -97,6 +97,11 @@ - (void)viewDidLayoutSubviews { [self updateScrollViewInsets]; } +- (void)traitCollectionDidChange:(nullable UITraitCollection *)previousTraitCollection { + [super traitCollectionDidChange:previousTraitCollection]; + [self adjustTheme:previousTraitCollection]; +} + - (CGFloat)toolbarHeightForCurrentSafeAreaInsets { return self.view.safeAreaInsets.top == 0 ? WMFToolbarConstrainedHeight : WMFToolbarHeight; } From 937569cde258c9a43851b25de236ee6b63c4e9f3 Mon Sep 17 00:00:00 2001 From: Natalia Harateh Date: Fri, 23 Aug 2019 18:50:46 -0400 Subject: [PATCH 07/12] set displayType before call to super --- Wikipedia/Code/ExploreFeedSettingsViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Wikipedia/Code/ExploreFeedSettingsViewController.swift b/Wikipedia/Code/ExploreFeedSettingsViewController.swift index bcf8a76af2b..1a6b2534278 100644 --- a/Wikipedia/Code/ExploreFeedSettingsViewController.swift +++ b/Wikipedia/Code/ExploreFeedSettingsViewController.swift @@ -175,10 +175,10 @@ class ExploreFeedSettingsViewController: BaseExploreFeedSettingsViewController { } override func viewDidLoad() { - super.viewDidLoad() - title = CommonStrings.exploreFeedTitle assert(!preferredLanguages.isEmpty) displayType = preferredLanguages.count == 1 ? .singleLanguage : .multipleLanguages + super.viewDidLoad() + title = CommonStrings.exploreFeedTitle } @objc private func closeButtonPressed() { From f2b5ec07f90eaa806b977f93605f521956dfa123 Mon Sep 17 00:00:00 2001 From: Natalia Harateh Date: Fri, 23 Aug 2019 18:51:21 -0400 Subject: [PATCH 08/12] pass theme object instead of userInfo --- Wikipedia/Code/AppearanceSettingsViewController.swift | 3 +-- Wikipedia/Code/ReadingThemesControlsViewController.swift | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Wikipedia/Code/AppearanceSettingsViewController.swift b/Wikipedia/Code/AppearanceSettingsViewController.swift index 811f451f3f3..b3c58130c21 100644 --- a/Wikipedia/Code/AppearanceSettingsViewController.swift +++ b/Wikipedia/Code/AppearanceSettingsViewController.swift @@ -189,8 +189,7 @@ final class AppearanceSettingsViewController: SubSettingsViewController { } func userDidSelect(theme: Theme) { - let userInfo = ["theme": theme] - NotificationCenter.default.post(name: Notification.Name(ReadingThemesControlsViewController.WMFUserDidSelectThemeNotification), object: nil, userInfo: userInfo) + NotificationCenter.default.post(name: Theme.didChangeNotification, object: theme) } @objc public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { diff --git a/Wikipedia/Code/ReadingThemesControlsViewController.swift b/Wikipedia/Code/ReadingThemesControlsViewController.swift index d3b1ba84f99..592aa7312bd 100644 --- a/Wikipedia/Code/ReadingThemesControlsViewController.swift +++ b/Wikipedia/Code/ReadingThemesControlsViewController.swift @@ -9,7 +9,6 @@ protocol WMFReadingThemesControlsViewControllerDelegate: class { @objc(WMFReadingThemesControlsViewController) class ReadingThemesControlsViewController: UIViewController { - @objc static let WMFUserDidSelectThemeNotification = "WMFUserDidSelectThemeNotification" @objc static let nibName = "ReadingThemesControlsViewController" var theme = Theme.standard From b0d8718db0ece51affa6bf9eda50d9f33079eb36 Mon Sep 17 00:00:00 2001 From: Natalia Harateh Date: Fri, 23 Aug 2019 18:52:01 -0400 Subject: [PATCH 09/12] apply theme to cell immediately --- Wikipedia/Code/AccountViewController.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Wikipedia/Code/AccountViewController.swift b/Wikipedia/Code/AccountViewController.swift index f4ecfd39e87..c700c18f8b6 100644 --- a/Wikipedia/Code/AccountViewController.swift +++ b/Wikipedia/Code/AccountViewController.swift @@ -70,10 +70,14 @@ class AccountViewController: SubSettingsViewController { let item = sections[safeIndex: indexPath.section]?.items[safeIndex: indexPath.row] else { return UITableViewCell() } - + + cell.apply(theme) + + if theme.colors.icon == nil { + cell.iconColor = item.iconColor + cell.iconBackgroundColor = item.iconBackgroundColor + } cell.iconName = item.iconName - cell.iconColor = item.iconColor - cell.iconBackgroundColor = item.iconBackgroundColor cell.title = item.title switch item.type { @@ -92,8 +96,6 @@ class AccountViewController: SubSettingsViewController { cell.disclosureSwitch.addTarget(self, action: #selector(autoSignTalkPageDiscussions(_:)), for: .valueChanged) } - cell.apply(theme) - return cell } @@ -165,5 +167,6 @@ class AccountViewController: SubSettingsViewController { view.backgroundColor = theme.colors.paperBackground tableView.backgroundColor = theme.colors.baseBackground + tableView.reloadData() } } From 67acc5f49ba012c12a9be143a1757eee40ae46f5 Mon Sep 17 00:00:00 2001 From: Natalia Harateh Date: Fri, 23 Aug 2019 19:27:57 -0400 Subject: [PATCH 10/12] reload data & input views when applying theme --- .../InsertMediaAdvancedSettingsViewController.swift | 1 + .../InsertMediaImageSizeSettingsViewController.swift | 1 + .../InsertMediaImageTypeSettingsViewController.swift | 1 + Wikipedia/Code/DescriptionEditViewController.swift | 1 + .../Code/InsertMediaSearchResultsCollectionViewController.swift | 1 + Wikipedia/Code/InsertMediaSearchViewController.swift | 1 + Wikipedia/Code/InsertMediaSelectedImageView.swift | 1 + Wikipedia/Code/InsertMediaSelectedImageViewController.swift | 2 ++ Wikipedia/Code/InsertMediaSettingsViewController.swift | 2 ++ 9 files changed, 11 insertions(+) diff --git a/Wikipedia/Code/Advanced Settings/InsertMediaAdvancedSettingsViewController.swift b/Wikipedia/Code/Advanced Settings/InsertMediaAdvancedSettingsViewController.swift index 438e6c8b42d..97581b49303 100644 --- a/Wikipedia/Code/Advanced Settings/InsertMediaAdvancedSettingsViewController.swift +++ b/Wikipedia/Code/Advanced Settings/InsertMediaAdvancedSettingsViewController.swift @@ -104,6 +104,7 @@ final class InsertMediaAdvancedSettingsViewController: ViewController { view.backgroundColor = theme.colors.paperBackground tableView.backgroundColor = view.backgroundColor tableView.separatorColor = theme.colors.border + tableView.reloadData() } } diff --git a/Wikipedia/Code/Advanced Settings/InsertMediaImageSizeSettingsViewController.swift b/Wikipedia/Code/Advanced Settings/InsertMediaImageSizeSettingsViewController.swift index 834389c09c8..4b5fb5a663f 100644 --- a/Wikipedia/Code/Advanced Settings/InsertMediaImageSizeSettingsViewController.swift +++ b/Wikipedia/Code/Advanced Settings/InsertMediaImageSizeSettingsViewController.swift @@ -102,6 +102,7 @@ final class InsertMediaImageSizeSettingsViewController: ViewController { view.backgroundColor = theme.colors.paperBackground tableView.backgroundColor = view.backgroundColor tableView.separatorColor = theme.colors.border + tableView.reloadData() } } diff --git a/Wikipedia/Code/Advanced Settings/InsertMediaImageTypeSettingsViewController.swift b/Wikipedia/Code/Advanced Settings/InsertMediaImageTypeSettingsViewController.swift index fda5342e91b..c6f5fe6d86d 100644 --- a/Wikipedia/Code/Advanced Settings/InsertMediaImageTypeSettingsViewController.swift +++ b/Wikipedia/Code/Advanced Settings/InsertMediaImageTypeSettingsViewController.swift @@ -67,6 +67,7 @@ final class InsertMediaImageTypeSettingsViewController: ViewController { let selectedBackgroundView = UIView() selectedBackgroundView.backgroundColor = theme.colors.midBackground cell.selectedBackgroundView = selectedBackgroundView + tableView.reloadData() } // MARK: - Themeable diff --git a/Wikipedia/Code/DescriptionEditViewController.swift b/Wikipedia/Code/DescriptionEditViewController.swift index 172c8b5a21c..f4f260b5b49 100644 --- a/Wikipedia/Code/DescriptionEditViewController.swift +++ b/Wikipedia/Code/DescriptionEditViewController.swift @@ -265,6 +265,7 @@ import UIKit warningCharacterCountLabel.textColor = theme.colors.descriptionWarning publishDescriptionButton.apply(theme: theme) descriptionTextView.keyboardAppearance = theme.keyboardAppearance + descriptionTextView.reloadInputViews() } } diff --git a/Wikipedia/Code/InsertMediaSearchResultsCollectionViewController.swift b/Wikipedia/Code/InsertMediaSearchResultsCollectionViewController.swift index 305461cab35..80016b6fe44 100644 --- a/Wikipedia/Code/InsertMediaSearchResultsCollectionViewController.swift +++ b/Wikipedia/Code/InsertMediaSearchResultsCollectionViewController.swift @@ -141,6 +141,7 @@ class InsertMediaSearchResultsCollectionViewController: UICollectionViewControll } view.backgroundColor = theme.colors.paperBackground collectionView.backgroundColor = theme.colors.paperBackground + collectionView.reloadData() } // MARK: - Empty State diff --git a/Wikipedia/Code/InsertMediaSearchViewController.swift b/Wikipedia/Code/InsertMediaSearchViewController.swift index c3ffe2c7480..81d5a4aeefe 100644 --- a/Wikipedia/Code/InsertMediaSearchViewController.swift +++ b/Wikipedia/Code/InsertMediaSearchViewController.swift @@ -138,5 +138,6 @@ extension InsertMediaSearchViewController: Themeable { view.backgroundColor = theme.colors.paperBackground searchBar.apply(theme: theme) searchBar.tintColor = theme.colors.link + searchBar.reloadInputViews() } } diff --git a/Wikipedia/Code/InsertMediaSelectedImageView.swift b/Wikipedia/Code/InsertMediaSelectedImageView.swift index 03f3a61bf3a..94d96814de8 100644 --- a/Wikipedia/Code/InsertMediaSelectedImageView.swift +++ b/Wikipedia/Code/InsertMediaSelectedImageView.swift @@ -61,5 +61,6 @@ extension InsertMediaSelectedImageView: Themeable { backgroundColor = theme.colors.baseBackground imageInfoContainerView.backgroundColor = backgroundColor imageView.backgroundColor = .clear + imageInfoView.apply(theme: theme) } } diff --git a/Wikipedia/Code/InsertMediaSelectedImageViewController.swift b/Wikipedia/Code/InsertMediaSelectedImageViewController.swift index b413655ed02..e7ecc35eb28 100644 --- a/Wikipedia/Code/InsertMediaSelectedImageViewController.swift +++ b/Wikipedia/Code/InsertMediaSelectedImageViewController.swift @@ -92,5 +92,7 @@ extension InsertMediaSelectedImageViewController: Themeable { } view.backgroundColor = theme.colors.baseBackground activityIndicator.style = theme.isDark ? .white : .gray + wmf_applyTheme(toEmptyView: theme) + selectedView.apply(theme: theme) } } diff --git a/Wikipedia/Code/InsertMediaSettingsViewController.swift b/Wikipedia/Code/InsertMediaSettingsViewController.swift index a7cd95f8d55..bf82c488f5d 100644 --- a/Wikipedia/Code/InsertMediaSettingsViewController.swift +++ b/Wikipedia/Code/InsertMediaSettingsViewController.swift @@ -247,6 +247,8 @@ final class InsertMediaSettingsViewController: ViewController { tableView.backgroundColor = view.backgroundColor imageView.apply(theme: theme) buttonView.apply(theme: theme) + tableView.reloadData() + tableView.reloadInputViews() } } From 647f543043ba3bc2395db9eedfb5fd0e0bda9b32 Mon Sep 17 00:00:00 2001 From: Natalia Harateh Date: Fri, 23 Aug 2019 19:39:44 -0400 Subject: [PATCH 11/12] reload input views when applying theme to a text field --- WMF Framework/ThemeableTextField.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WMF Framework/ThemeableTextField.swift b/WMF Framework/ThemeableTextField.swift index 76ce7cb5969..da5089325d5 100644 --- a/WMF Framework/ThemeableTextField.swift +++ b/WMF Framework/ThemeableTextField.swift @@ -85,7 +85,7 @@ open class ThemeableTextField: UITextField, Themeable { layer.shadowOpacity = 0.0 layer.shadowRadius = 0.0 } - + reloadInputViews() } } From f2ec83846b77b953acc9385614ef3ce5f26806a1 Mon Sep 17 00:00:00 2001 From: Natalia Harateh Date: Fri, 23 Aug 2019 19:40:50 -0400 Subject: [PATCH 12/12] remove adjustTheme UIView extension --- WMF Framework/Theme.swift | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/WMF Framework/Theme.swift b/WMF Framework/Theme.swift index 8db3055b066..932e8d4991b 100644 --- a/WMF Framework/Theme.swift +++ b/WMF Framework/Theme.swift @@ -485,15 +485,3 @@ private extension Themeable where Self: UITraitEnvironment { self.adjustTheme(previousTraitCollection) } } - -@objc public extension UIView { - func adjustTheme(_ previousTraitCollection: UITraitCollection?) { - guard - #available(iOS 12.0, *), - let self = self as? (Themeable & UITraitEnvironment) - else { - return - } - self.adjustTheme(previousTraitCollection) - } -}