From 9104602893d48e9767c0bd515cf3d260b3374f9a Mon Sep 17 00:00:00 2001 From: CMK Date: Wed, 29 Sep 2021 18:42:28 +0800 Subject: [PATCH] chore: update sidebar color and Detail placeholder background color --- Mastodon.xcodeproj/project.pbxproj | 4 +++ .../Scene/Root/RootSplitViewController.swift | 2 +- .../SecondaryPlaceholderViewController.swift | 36 +++++++++++++++++++ .../Root/Sidebar/SidebarViewController.swift | 12 +++++-- .../ThemeService+Appearance.swift | 3 ++ 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 Mastodon/Scene/Root/Sidebar/SecondaryPlaceholderViewController.swift diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index 13755e8b8..cbb28acec 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -575,6 +575,7 @@ DBF156DF2701B17600EC00B7 /* SidebarAddAccountCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF156DE2701B17600EC00B7 /* SidebarAddAccountCollectionViewCell.swift */; }; DBF156E22702DA6900EC00B7 /* UIStatusBarManager+HandleTapAction.m in Sources */ = {isa = PBXBuildFile; fileRef = DBF156E12702DA6900EC00B7 /* UIStatusBarManager+HandleTapAction.m */; }; DBF156E42702DB3F00EC00B7 /* HandleTapAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF156E32702DB3F00EC00B7 /* HandleTapAction.swift */; }; + DBF1572F27046F1A00EC00B7 /* SecondaryPlaceholderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF1572E27046F1A00EC00B7 /* SecondaryPlaceholderViewController.swift */; }; DBF1D24E269DAF5D00C1C08A /* SearchDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF1D24D269DAF5D00C1C08A /* SearchDetailViewController.swift */; }; DBF1D251269DB01200C1C08A /* SearchHistoryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF1D250269DB01200C1C08A /* SearchHistoryViewController.swift */; }; DBF1D257269DBAC600C1C08A /* SearchDetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBF1D256269DBAC600C1C08A /* SearchDetailViewModel.swift */; }; @@ -1360,6 +1361,7 @@ DBF156E02702DA6800EC00B7 /* Mastodon-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Mastodon-Bridging-Header.h"; sourceTree = ""; }; DBF156E12702DA6900EC00B7 /* UIStatusBarManager+HandleTapAction.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIStatusBarManager+HandleTapAction.m"; sourceTree = ""; }; DBF156E32702DB3F00EC00B7 /* HandleTapAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandleTapAction.swift; sourceTree = ""; }; + DBF1572E27046F1A00EC00B7 /* SecondaryPlaceholderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondaryPlaceholderViewController.swift; sourceTree = ""; }; DBF1D24D269DAF5D00C1C08A /* SearchDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchDetailViewController.swift; sourceTree = ""; }; DBF1D250269DB01200C1C08A /* SearchHistoryViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchHistoryViewController.swift; sourceTree = ""; }; DBF1D256269DBAC600C1C08A /* SearchDetailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchDetailViewModel.swift; sourceTree = ""; }; @@ -2554,6 +2556,7 @@ DB0EF72C26FDB1D600347686 /* View */, DB852D1826FAEB6B00FC9D81 /* SidebarViewController.swift */, DB852D1E26FB037800FC9D81 /* SidebarViewModel.swift */, + DBF1572E27046F1A00EC00B7 /* SecondaryPlaceholderViewController.swift */, ); path = Sidebar; sourceTree = ""; @@ -3972,6 +3975,7 @@ DB36679F268ABAF20027D07F /* ComposeStatusAttachmentSection.swift in Sources */, 2DA7D04425CA52B200804E11 /* TimelineLoaderTableViewCell.swift in Sources */, DB87D44B2609C11900D12C0D /* PollOptionView.swift in Sources */, + DBF1572F27046F1A00EC00B7 /* SecondaryPlaceholderViewController.swift in Sources */, DB03F7F32689AEA3007B274C /* ComposeRepliedToStatusContentTableViewCell.swift in Sources */, 2D4AD8A826316D3500613EFC /* SelectedAccountItem.swift in Sources */, DBE3CDFB261C6CA500430CC6 /* FavoriteViewModel.swift in Sources */, diff --git a/Mastodon/Scene/Root/RootSplitViewController.swift b/Mastodon/Scene/Root/RootSplitViewController.swift index e7a632cb8..2e8beef9e 100644 --- a/Mastodon/Scene/Root/RootSplitViewController.swift +++ b/Mastodon/Scene/Root/RootSplitViewController.swift @@ -63,7 +63,7 @@ final class RootSplitViewController: UISplitViewController, NeedsDependency { setViewController(sidebarViewController, for: .primary) setViewController(supplementaryViewControllers[0], for: .supplementary) - setViewController(UIViewController(), for: .secondary) + setViewController(SecondaryPlaceholderViewController(), for: .secondary) setViewController(mainTabBarController, for: .compact) } diff --git a/Mastodon/Scene/Root/Sidebar/SecondaryPlaceholderViewController.swift b/Mastodon/Scene/Root/Sidebar/SecondaryPlaceholderViewController.swift new file mode 100644 index 000000000..a381844df --- /dev/null +++ b/Mastodon/Scene/Root/Sidebar/SecondaryPlaceholderViewController.swift @@ -0,0 +1,36 @@ +// +// SecondaryPlaceholderViewController.swift +// Mastodon +// +// Created by Cirno MainasuK on 2021-9-29. +// + +import UIKit +import Combine + +final class SecondaryPlaceholderViewController: UIViewController { + var disposeBag = Set() +} + +extension SecondaryPlaceholderViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + setupBackground(theme: ThemeService.shared.currentTheme.value) + ThemeService.shared.currentTheme + .receive(on: DispatchQueue.main) + .sink { [weak self] theme in + guard let self = self else { return } + self.setupBackground(theme: theme) + } + .store(in: &disposeBag) + } + +} + +extension SecondaryPlaceholderViewController { + private func setupBackground(theme: Theme) { + view.backgroundColor = theme.secondarySystemBackgroundColor + } +} diff --git a/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift b/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift index e1ae87646..69d9f55c8 100644 --- a/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift +++ b/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift @@ -35,6 +35,7 @@ final class SidebarViewController: UIViewController, NeedsDependency { static func createLayout() -> UICollectionViewLayout { let layout = UICollectionViewCompositionalLayout() { (sectionIndex, layoutEnvironment) -> NSCollectionLayoutSection? in var configuration = UICollectionLayoutListConfiguration(appearance: .sidebar) + configuration.backgroundColor = .clear if sectionIndex == SidebarViewModel.Section.tab.rawValue { // with indentation configuration.headerMode = .none @@ -103,16 +104,23 @@ extension SidebarViewController { } private func setupBackground(theme: Theme) { + let color: UIColor = theme.sidebarBackgroundColor let barAppearance = UINavigationBarAppearance() barAppearance.configureWithOpaqueBackground() - barAppearance.backgroundColor = theme.sidebarBackgroundColor + barAppearance.backgroundColor = color barAppearance.shadowColor = .clear barAppearance.shadowImage = UIImage() // remove separator line navigationItem.standardAppearance = barAppearance navigationItem.compactAppearance = barAppearance navigationItem.scrollEdgeAppearance = barAppearance + if #available(iOS 15.0, *) { + navigationItem.compactScrollEdgeAppearance = barAppearance + } else { + // Fallback on earlier versions + } - view.backgroundColor = theme.sidebarBackgroundColor + view.backgroundColor = color + collectionView.backgroundColor = color } } diff --git a/Mastodon/Service/ThemeService/ThemeService+Appearance.swift b/Mastodon/Service/ThemeService/ThemeService+Appearance.swift index 182fe870a..8130942aa 100644 --- a/Mastodon/Service/ThemeService/ThemeService+Appearance.swift +++ b/Mastodon/Service/ThemeService/ThemeService+Appearance.swift @@ -24,6 +24,9 @@ extension ThemeService { UINavigationBar.appearance().standardAppearance = appearance UINavigationBar.appearance().compactAppearance = appearance UINavigationBar.appearance().scrollEdgeAppearance = appearance + if #available(iOS 15.0, *) { + UINavigationBar.appearance().compactScrollEdgeAppearance = appearance + } // set tab bar appearance let tabBarAppearance = UITabBarAppearance()