Merge pull request #565 from kylebshr/kb/search-appearance

Update navigation bar appearance in SearchViewController
This commit is contained in:
Marcus Kida 2022-11-15 08:23:50 +01:00 committed by GitHub
commit a31fc611b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 10 deletions

View File

@ -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<AnyCancellable>()
var viewModel: SearchViewModel!
// use AutoLayout could set search bar margin automatically to
// layout alongside with split mode button (on iPad)
let titleViewContainer = UIView()
@ -73,19 +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()
// collectionView.translatesAutoresizingMaskIntoConstraints = false
// view.addSubview(collectionView)
// NSLayoutConstraint.activate([
@ -101,7 +101,7 @@ extension SearchViewController {
// )
guard let discoveryViewController = self.discoveryViewController else { return }
addChild(discoveryViewController)
discoveryViewController.view.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(discoveryViewController.view)
@ -111,15 +111,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
@ -127,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() {