Skip to content

Commit

Permalink
Use trait collection to control theme changes (#2672)
Browse files Browse the repository at this point in the history
  • Loading branch information
dus7 authored Apr 5, 2024
1 parent e1105b7 commit 1504f88
Show file tree
Hide file tree
Showing 110 changed files with 762 additions and 949 deletions.
11 changes: 0 additions & 11 deletions Core/UIViewControllerExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,10 @@ extension UIViewController {
return []
}

func overrideUserInterfaceStyle() {
if ThemeManager.shared.currentTheme.currentImageSet == .dark {
overrideUserInterfaceStyle = .dark
} else {
overrideUserInterfaceStyle = .light
}
}

public func presentShareSheet(withItems activityItems: [Any], fromButtonItem buttonItem: UIBarButtonItem, completion: UIActivityViewController.CompletionWithItemsHandler? = nil) {
let activities = buildActivities()
let shareController = UIActivityViewController(activityItems: activityItems, applicationActivities: activities)
shareController.completionWithItemsHandler = completion
shareController.overrideUserInterfaceStyle()
present(controller: shareController, fromButtonItem: buttonItem)
}

Expand All @@ -56,8 +47,6 @@ extension UIViewController {
shareController.completionWithItemsHandler = completion
if let overrideInterfaceStyle {
shareController.overrideUserInterfaceStyle = overrideInterfaceStyle
} else {
shareController.overrideUserInterfaceStyle()
}
shareController.excludedActivityTypes = [.markupAsPDF]
present(controller: shareController, fromView: sourceView, atPoint: point)
Expand Down
16 changes: 4 additions & 12 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
4BFB911B29B7D9530014D4B7 /* AppTrackingProtectionStoringModelPerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BFB911A29B7D9530014D4B7 /* AppTrackingProtectionStoringModelPerformanceTests.swift */; };
6AC6DAB328804F97002723C0 /* BarsAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AC6DAB228804F97002723C0 /* BarsAnimator.swift */; };
6AC98419288055C1005FA9CA /* BarsAnimatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AC98418288055C1005FA9CA /* BarsAnimatorTests.swift */; };
6F655BE22BAB289E00AC3597 /* DefaultTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F655BE12BAB289E00AC3597 /* DefaultTheme.swift */; };
6FDA1FB32B59584400AC962A /* AddressDisplayHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FDA1FB22B59584400AC962A /* AddressDisplayHelper.swift */; };
83004E802193BB8200DA013C /* WKNavigationExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83004E7F2193BB8200DA013C /* WKNavigationExtension.swift */; };
83004E862193E5ED00DA013C /* TabViewControllerBrowsingMenuExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83004E852193E5ED00DA013C /* TabViewControllerBrowsingMenuExtension.swift */; };
Expand Down Expand Up @@ -344,7 +345,6 @@
850250B520D80419002199C7 /* AtbAndVariantCleanupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 850250B420D80419002199C7 /* AtbAndVariantCleanupTests.swift */; };
850365F323DE087800D0F787 /* UIImageViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 850365F223DE087800D0F787 /* UIImageViewExtension.swift */; };
85047B8A1F69692C002A95D8 /* contentblocker.js in Resources */ = {isa = PBXBuildFile; fileRef = 85047B891F69692C002A95D8 /* contentblocker.js */; };
85047C752A0D3C2900D2FF3F /* SyncSettingsViewController+Themable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85047C742A0D3C2900D2FF3F /* SyncSettingsViewController+Themable.swift */; };
85047C772A0D5D3D00D2FF3F /* SyncSettingsViewController+SyncDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85047C762A0D5D3D00D2FF3F /* SyncSettingsViewController+SyncDelegate.swift */; };
850559C923C61B5D0055C0D5 /* login-form-detection.js in Resources */ = {isa = PBXBuildFile; fileRef = 850559C823C61B5D0055C0D5 /* login-form-detection.js */; };
850559D023CF647C0055C0D5 /* PreserveLogins.swift in Sources */ = {isa = PBXBuildFile; fileRef = 850559CF23CF647C0055C0D5 /* PreserveLogins.swift */; };
Expand Down Expand Up @@ -632,8 +632,6 @@
98EF177D21837E35006750C1 /* new_tab_dark.json in Resources */ = {isa = PBXBuildFile; fileRef = 98EF177C21837E35006750C1 /* new_tab_dark.json */; };
98F0FC2021FF18E700CE77AB /* AutoClearSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98F0FC1F21FF18E700CE77AB /* AutoClearSettingsViewController.swift */; };
98F3A1D8217B37010011A0D4 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98F3A1D7217B37010011A0D4 /* Theme.swift */; };
98F3A1DA217B37200011A0D4 /* LightTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98F3A1D9217B37200011A0D4 /* LightTheme.swift */; };
98F3A1DC217B373E0011A0D4 /* DarkTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98F3A1DB217B373E0011A0D4 /* DarkTheme.swift */; };
98F6EA472863124100720957 /* ContentBlockerRulesLists.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98F6EA462863124100720957 /* ContentBlockerRulesLists.swift */; };
98F78B8E22419093007CACF4 /* ThemableNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98F78B8D22419093007CACF4 /* ThemableNavigationController.swift */; };
9F8FE9492BAE50E50071E372 /* Lottie in Frameworks */ = {isa = PBXBuildFile; productRef = 9F8FE9482BAE50E50071E372 /* Lottie */; };
Expand Down Expand Up @@ -1434,6 +1432,7 @@
4BFB911A29B7D9530014D4B7 /* AppTrackingProtectionStoringModelPerformanceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppTrackingProtectionStoringModelPerformanceTests.swift; sourceTree = "<group>"; };
6AC6DAB228804F97002723C0 /* BarsAnimator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarsAnimator.swift; sourceTree = "<group>"; };
6AC98418288055C1005FA9CA /* BarsAnimatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarsAnimatorTests.swift; sourceTree = "<group>"; };
6F655BE12BAB289E00AC3597 /* DefaultTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultTheme.swift; sourceTree = "<group>"; };
6FB030C7234331B400A10DB9 /* Configuration.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Configuration.xcconfig; path = Configuration/Configuration.xcconfig; sourceTree = "<group>"; };
6FDA1FB22B59584400AC962A /* AddressDisplayHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressDisplayHelper.swift; sourceTree = "<group>"; };
83004E7F2193BB8200DA013C /* WKNavigationExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKNavigationExtension.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1477,7 +1476,6 @@
850250B420D80419002199C7 /* AtbAndVariantCleanupTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AtbAndVariantCleanupTests.swift; sourceTree = "<group>"; };
850365F223DE087800D0F787 /* UIImageViewExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIImageViewExtension.swift; sourceTree = "<group>"; };
85047B891F69692C002A95D8 /* contentblocker.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = contentblocker.js; sourceTree = "<group>"; };
85047C742A0D3C2900D2FF3F /* SyncSettingsViewController+Themable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SyncSettingsViewController+Themable.swift"; sourceTree = "<group>"; };
85047C762A0D5D3D00D2FF3F /* SyncSettingsViewController+SyncDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SyncSettingsViewController+SyncDelegate.swift"; sourceTree = "<group>"; };
850559C823C61B5D0055C0D5 /* login-form-detection.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = "login-form-detection.js"; sourceTree = "<group>"; };
850559CF23CF647C0055C0D5 /* PreserveLogins.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreserveLogins.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2302,8 +2300,6 @@
98F02E87251EAC11002A6C60 /* lt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = lt; path = lt.lproj/InfoPlist.strings; sourceTree = "<group>"; };
98F0FC1F21FF18E700CE77AB /* AutoClearSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoClearSettingsViewController.swift; sourceTree = "<group>"; };
98F3A1D7217B37010011A0D4 /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = "<group>"; };
98F3A1D9217B37200011A0D4 /* LightTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LightTheme.swift; sourceTree = "<group>"; };
98F3A1DB217B373E0011A0D4 /* DarkTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DarkTheme.swift; sourceTree = "<group>"; };
98F6EA462863124100720957 /* ContentBlockerRulesLists.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentBlockerRulesLists.swift; sourceTree = "<group>"; };
98F78B8D22419093007CACF4 /* ThemableNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemableNavigationController.swift; sourceTree = "<group>"; };
AA3D854423D9942200788410 /* AppIconSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppIconSettingsViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4141,7 +4137,6 @@
children = (
85582DFF29D7409700E9AE35 /* SyncSettingsViewController+PDFRendering.swift */,
85F98F91296F32BD00742F4A /* SyncSettingsViewController.swift */,
85047C742A0D3C2900D2FF3F /* SyncSettingsViewController+Themable.swift */,
85047C762A0D5D3D00D2FF3F /* SyncSettingsViewController+SyncDelegate.swift */,
);
name = Controllers;
Expand Down Expand Up @@ -4313,9 +4308,8 @@
98F3A1D7217B37010011A0D4 /* Theme.swift */,
9874F9ED2187AFCE00CAF33D /* Themable.swift */,
98DA6EC92181E41F00E65433 /* ThemeManager.swift */,
98F3A1D9217B37200011A0D4 /* LightTheme.swift */,
98F3A1DB217B373E0011A0D4 /* DarkTheme.swift */,
8536A1FC2ACF114B003AC5BA /* Theme+DesignSystem.swift */,
6F655BE12BAB289E00AC3597 /* DefaultTheme.swift */,
);
name = Themes;
sourceTree = "<group>";
Expand Down Expand Up @@ -6631,7 +6625,6 @@
8546A54A2A672959003929BF /* MainViewController+Email.swift in Sources */,
F4F6DFB226E6AEC100ED7E12 /* AddOrEditBookmarkViewController.swift in Sources */,
EE458D0D2AB1DA4600FC651A /* EventMapping+NetworkProtectionError.swift in Sources */,
85047C752A0D3C2900D2FF3F /* SyncSettingsViewController+Themable.swift in Sources */,
F44D279F27F331BB0037F371 /* AutofillLoginPromptViewController.swift in Sources */,
C1BF0BA529B63D7200482B73 /* AutofillLoginPromptHelper.swift in Sources */,
D664C7C92B289AA200CBFA76 /* AsyncHeadlessWebView.swift in Sources */,
Expand Down Expand Up @@ -6765,7 +6758,6 @@
EEF0F8CC2ABC832300630031 /* NetworkProtectionDebugFeatures.swift in Sources */,
B60DFF072872B64B0061E7C2 /* JSAlertController.swift in Sources */,
981FED6E22025151008488D7 /* BlankSnapshotViewController.swift in Sources */,
98F3A1DC217B373E0011A0D4 /* DarkTheme.swift in Sources */,
D66F683D2BB333C100AE93E2 /* SubscriptionContainerView.swift in Sources */,
851B128822200575004781BC /* Onboarding.swift in Sources */,
3151F0EE2735800800226F58 /* VoiceSearchFeedbackView.swift in Sources */,
Expand Down Expand Up @@ -6899,6 +6891,7 @@
D6E0C1872B7A2D0700D5E1E9 /* DesktopDownloadViewButtonStyle.swift in Sources */,
854A012B2A54412600FCC628 /* ActivityViewController.swift in Sources */,
F1CA3C391F045885005FADB3 /* PrivacyUserDefaults.swift in Sources */,
6F655BE22BAB289E00AC3597 /* DefaultTheme.swift in Sources */,
BD862E072B30F5E30073E2EE /* VPNFeedbackSender.swift in Sources */,
AA4D6A6A23DB87B1007E8790 /* AppIconManager.swift in Sources */,
8563A03C1F9288D600F04442 /* BrowserChromeManager.swift in Sources */,
Expand Down Expand Up @@ -6998,7 +6991,6 @@
B623C1C22862CA9E0043013E /* DownloadSession.swift in Sources */,
0290471E29E708750008FE3C /* AppTPManageTrackersView.swift in Sources */,
F16390821E648B7A005B4550 /* HomeViewController.swift in Sources */,
98F3A1DA217B37200011A0D4 /* LightTheme.swift in Sources */,
985892522260B1B200EEB31B /* ProgressView.swift in Sources */,
85BA585A1F3506AE00C6E8CA /* AppSettings.swift in Sources */,
3151F0EA27357FBA00226F58 /* SpeechRecognizer.swift in Sources */,
Expand Down
13 changes: 2 additions & 11 deletions DuckDuckGo/AddOrEditBookmarkViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class AddOrEditBookmarkViewController: UIViewController {
updateTitle()
updateSaveButton()

applyTheme(ThemeManager.shared.currentTheme)
decorateNavigationBar()
decorateToolbar()

viewModelCancellable = viewModel.externalUpdates.sink { [weak self] _ in
self?.foldersViewController?.refresh()
Expand Down Expand Up @@ -190,13 +191,3 @@ extension AddOrEditBookmarkViewController: AddOrEditBookmarkViewControllerDelega
}

}

extension AddOrEditBookmarkViewController: Themable {

func decorate(with theme: Theme) {
decorateNavigationBar(with: theme)
decorateToolbar(with: theme)

overrideSystemTheme(with: theme)
}
}
15 changes: 11 additions & 4 deletions DuckDuckGo/AppIconSettingsCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,27 @@ class AppIconSettingsCell: UICollectionViewCell {
super.init(coder: coder)
isAccessibilityElement = true
accessibilityTraits.insert(.button)
decorate()
}

override var isSelected: Bool {
didSet {
layer.borderWidth = isSelected ? 2.0 : 0.0
}
}

}

extension AppIconSettingsCell: Themable {

func decorate(with theme: Theme) {
extension AppIconSettingsCell {
private func decorate() {
let theme = ThemeManager.shared.currentTheme
layer.borderColor = theme.iconCellBorderColor.cgColor
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
decorate()
}
}
}
8 changes: 4 additions & 4 deletions DuckDuckGo/AppIconSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AppIconSettingsViewController: UICollectionViewController {
super.viewDidLoad()

collectionView.dataSource = dataSource
applyTheme(ThemeManager.shared.currentTheme)
decorate()
}

private func initSelection() {
Expand Down Expand Up @@ -66,7 +66,6 @@ class AppIconDataSource: NSObject, UICollectionViewDataSource {
as? AppIconSettingsCell else {
fatalError("Expected IconSettingsCell")
}
cell.decorate(with: ThemeManager.shared.currentTheme)

let appIcon = appIcons[indexPath.row]
cell.appIcon = appIcon
Expand Down Expand Up @@ -95,9 +94,10 @@ class AppIconWorker {

}

extension AppIconSettingsViewController: Themable {
extension AppIconSettingsViewController {

func decorate(with theme: Theme) {
private func decorate() {
let theme = ThemeManager.shared.currentTheme
collectionView.backgroundColor = theme.backgroundColor
collectionView.reloadData()
initSelection()
Expand Down
12 changes: 0 additions & 12 deletions DuckDuckGo/Assets.xcassets/ErrorInfoDark.imageset/Contents.json

This file was deleted.

15 changes: 0 additions & 15 deletions DuckDuckGo/Assets.xcassets/ErrorInfoLight.imageset/Contents.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"images" : [
{
"filename" : "errorImgLight.pdf",
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "errorImgDark.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
17 changes: 0 additions & 17 deletions DuckDuckGo/Assets.xcassets/LogoDarkText.imageset/Contents.json

This file was deleted.

17 changes: 0 additions & 17 deletions DuckDuckGo/Assets.xcassets/LogoLightText.imageset/Contents.json

This file was deleted.

38 changes: 38 additions & 0 deletions DuckDuckGo/Assets.xcassets/LogoText.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"images" : [
{
"filename" : "light_portrait_logo.pdf",
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "dark_portrait_logo.pdf",
"idiom" : "universal"
},
{
"filename" : "updatedLogoGrayText2.pdf",
"height-class" : "compact",
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "updatedLogoWhiteText2.pdf",
"height-class" : "compact",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
{
"filename" : "tabsToggleGrid-Light.pdf",
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "tabsToggleGrid-Dark.pdf",
"idiom" : "universal"
}
],
"info" : {
Expand Down

This file was deleted.

Loading

0 comments on commit 1504f88

Please sign in to comment.