From 407e0ae304e2c68c223781e5d8333a34e0263c3e Mon Sep 17 00:00:00 2001 From: Kyle Bashour Date: Fri, 11 Nov 2022 14:24:59 -0800 Subject: [PATCH 1/2] Update navigation bar appearance in SearchViewController --- .../Search/Search/SearchViewController.swift | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Mastodon/Scene/Search/Search/SearchViewController.swift b/Mastodon/Scene/Search/Search/SearchViewController.swift index 7efef2c00..3b9496dab 100644 --- a/Mastodon/Scene/Search/Search/SearchViewController.swift +++ b/Mastodon/Scene/Search/Search/SearchViewController.swift @@ -23,15 +23,15 @@ final class HeightFixedSearchBar: UISearchBar { final class SearchViewController: UIViewController, NeedsDependency { let logger = Logger(subsystem: "SearchViewController", category: "ViewController") - + weak var context: AppContext! { willSet { precondition(!isViewLoaded) } } weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } } var searchTransitionController = SearchTransitionController() - + var disposeBag = Set() var viewModel: SearchViewModel! - + // use AutoLayout could set search bar margin automatically to // layout alongside with split mode button (on iPad) let titleViewContainer = UIView() @@ -85,6 +85,7 @@ extension SearchViewController { title = L10n.Scene.Search.title setupSearchBar() + setupNavigationBarAppearance() // collectionView.translatesAutoresizingMaskIntoConstraints = false // view.addSubview(collectionView) @@ -101,7 +102,7 @@ extension SearchViewController { // ) guard let discoveryViewController = self.discoveryViewController else { return } - + addChild(discoveryViewController) discoveryViewController.view.translatesAutoresizingMaskIntoConstraints = false view.addSubview(discoveryViewController.view) @@ -111,15 +112,16 @@ extension SearchViewController { discoveryViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), discoveryViewController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor), ]) - + // discoveryViewController.view.isHidden = true + } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) viewModel.viewDidAppeared.send() - + // note: // need set alpha because (maybe) SDK forget set alpha back titleViewContainer.alpha = 1 @@ -164,6 +166,20 @@ extension SearchViewController { .store(in: &disposeBag) } + private func setupNavigationBarAppearance() { + let appearance = UINavigationBarAppearance() + appearance.configureWithOpaqueBackground() + appearance.shadowColor = nil + + navigationItem.standardAppearance = appearance + navigationItem.scrollEdgeAppearance = appearance + navigationItem.compactAppearance = appearance + + if #available(iOS 15, *) { + navigationItem.compactScrollEdgeAppearance = appearance + } + } + } // MARK: - UISearchBarDelegate From a5d61072c0182fd06c175c854c6d45ffa9bf8b3e Mon Sep 17 00:00:00 2001 From: Kyle Bashour Date: Fri, 11 Nov 2022 15:07:31 -0800 Subject: [PATCH 2/2] Fix background in dark mode --- .../Search/Search/SearchViewController.swift | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/Mastodon/Scene/Search/Search/SearchViewController.swift b/Mastodon/Scene/Search/Search/SearchViewController.swift index 3b9496dab..581fa08b3 100644 --- a/Mastodon/Scene/Search/Search/SearchViewController.swift +++ b/Mastodon/Scene/Search/Search/SearchViewController.swift @@ -73,20 +73,19 @@ extension SearchViewController { override func viewDidLoad() { super.viewDidLoad() - setupBackgroundColor(theme: ThemeService.shared.currentTheme.value) + setupAppearance(theme: ThemeService.shared.currentTheme.value) ThemeService.shared.currentTheme .receive(on: DispatchQueue.main) .sink { [weak self] theme in guard let self = self else { return } - self.setupBackgroundColor(theme: theme) + self.setupAppearance(theme: theme) } .store(in: &disposeBag) title = L10n.Scene.Search.title setupSearchBar() - setupNavigationBarAppearance() - + // collectionView.translatesAutoresizingMaskIntoConstraints = false // view.addSubview(collectionView) // NSLayoutConstraint.activate([ @@ -129,8 +128,22 @@ extension SearchViewController { } extension SearchViewController { - private func setupBackgroundColor(theme: Theme) { + private func setupAppearance(theme: Theme) { view.backgroundColor = theme.systemGroupedBackgroundColor + + // Match the DiscoveryViewController tab color and remove the double separator. + let navigationBarAppearance = UINavigationBarAppearance() + navigationBarAppearance.configureWithOpaqueBackground() + navigationBarAppearance.backgroundColor = theme.systemBackgroundColor + navigationBarAppearance.shadowColor = nil + + navigationItem.standardAppearance = navigationBarAppearance + navigationItem.scrollEdgeAppearance = navigationBarAppearance + navigationItem.compactAppearance = navigationBarAppearance + + if #available(iOS 15, *) { + navigationItem.compactScrollEdgeAppearance = navigationBarAppearance + } } private func setupSearchBar() { @@ -166,20 +179,6 @@ extension SearchViewController { .store(in: &disposeBag) } - private func setupNavigationBarAppearance() { - let appearance = UINavigationBarAppearance() - appearance.configureWithOpaqueBackground() - appearance.shadowColor = nil - - navigationItem.standardAppearance = appearance - navigationItem.scrollEdgeAppearance = appearance - navigationItem.compactAppearance = appearance - - if #available(iOS 15, *) { - navigationItem.compactScrollEdgeAppearance = appearance - } - } - } // MARK: - UISearchBarDelegate