Changes BrowseViewController’s search bar style to .automatic

More space efficient, and avoids UI bug where inline search bar could appear messed up after pushing view controller onto navigation stack.
This commit is contained in:
Riley Testut
2023-12-08 18:37:38 -06:00
committed by Magesh K
parent 3391058475
commit bea54fa748

View File

@@ -37,9 +37,7 @@ class BrowseViewController: UICollectionViewController, PeekPopPreviewing
private lazy var placeholderView = RSTPlaceholderView(frame: .zero)
private let prototypeCell = AppCardCollectionViewCell(frame: .zero)
private var sortButton: UIBarButtonItem?
private var categoriesMenu: UIMenu?
private var preferredAppSorting: AppSorting = UserDefaults.shared.preferredAppSorting
@@ -85,7 +83,6 @@ class BrowseViewController: UICollectionViewController, PeekPopPreviewing
self.collectionView.backgroundColor = .altBackground
self.collectionView.alwaysBounceVertical = true
self.dataSource.searchController.delegate = self
self.dataSource.searchController.searchableKeyPaths = [#keyPath(StoreApp.name),
#keyPath(StoreApp.subtitle),
#keyPath(StoreApp.developerName),
@@ -119,8 +116,6 @@ class BrowseViewController: UICollectionViewController, PeekPopPreviewing
])
self.navigationItem.titleMenuProvider = { _ in categoriesMenu }
self.categoriesMenu = categoriesMenu
}
self.titleSourceIconView = AppIconImageView(style: .circular)
@@ -138,7 +133,7 @@ class BrowseViewController: UICollectionViewController, PeekPopPreviewing
if #available(iOS 16, *)
{
self.navigationItem.preferredSearchBarPlacement = .inline
self.navigationItem.preferredSearchBarPlacement = .automatic
}
if #available(iOS 15, *)
@@ -530,7 +525,7 @@ private extension BrowseViewController
let sortButton = UIBarButtonItem(title: NSLocalizedString("Sort by…", comment: ""), image: sortIcon, primaryAction: nil, menu: sortMenu)
self.sortButton = sortButton
self.navigationItem.rightBarButtonItems = [sortButton, .flexibleSpace()] // flexibleSpace() required to prevent showing full search bar inline.
self.navigationItem.rightBarButtonItems = [sortButton]
}
}
@@ -678,30 +673,6 @@ extension BrowseViewController: UIViewControllerPreviewingDelegate
}
}
extension BrowseViewController: UISearchControllerDelegate
{
func willPresentSearchController(_ searchController: UISearchController)
{
// Hide titleView + menu to ensure search bar is as large as possible.
self.navigationItem.titleView = nil
if #available(iOS 16, *)
{
self.navigationItem.titleMenuProvider = nil
}
}
func willDismissSearchController(_ searchController: UISearchController)
{
self.navigationItem.titleView = self.titleStackView
if let categoriesMenu, #available(iOS 16, *)
{
self.navigationItem.titleMenuProvider = { _ in categoriesMenu }
}
}
}
@available(iOS 17, *)
#Preview(traits: .portrait) {
DatabaseManager.shared.startForPreview()