Search: Fix picker overlay and position

iOS 14 requires the scope bar modifier to be on the first subview of
the NavView. This is because a VStack wraps the content.

A bug was that the segmented picker was being overlaid due to the
scope bar modifier having an AppStorage call. The AppStorage call
updated the modifier which for some reason added another HostingView.

I am not sure why this happens, but avoid using AppStorage in the modifier
to make sure this doesn't happen again.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri 2023-02-28 19:42:20 -05:00
parent bcdacdae06
commit 0661ed66f3
4 changed files with 21 additions and 20 deletions

View file

@ -9,24 +9,25 @@ import SwiftUI
import Introspect
struct CustomScopeBarModifier<V: View>: ViewModifier {
@AppStorage("Behavior.AutocorrectSearch") var autocorrectSearch = true
let hostingContent: V
@State private var hostingController: UIHostingController<V>?
init(hostingContent: V) {
self.hostingContent = hostingContent
// Don't use AppStorage since it causes a view update
var autocorrectSearch: Bool {
UserDefaults.standard.bool(forKey: "Behavior.AutocorrectSearch")
}
func body(content: Content) -> some View {
if #available(iOS 15, *) {
content
.backport.introspectSearchController { searchController in
searchController.searchBar.autocorrectionType = autocorrectSearch ? .default : .no
searchController.searchBar.autocapitalizationType = autocorrectSearch ? .sentences : .none
// MARK: One-time setup
guard hostingController == nil else { return }
searchController.hidesNavigationBarDuringPresentation = true
searchController.searchBar.autocorrectionType = autocorrectSearch ? .default : .no
searchController.searchBar.autocapitalizationType = autocorrectSearch ? .sentences : .none
searchController.searchBar.showsScopeBar = true
searchController.searchBar.scopeButtonTitles = [""]
(searchController.searchBar.value(forKey: "_scopeBar") as? UIView)?.isHidden = true

View file

@ -110,11 +110,11 @@ struct ContentView: View {
}
}
.navigationSearchBarHiddenWhenScrolling(false)
}
.customScopeBar {
SearchFilterHeaderView()
.environmentObject(scrapingModel)
.environmentObject(debridManager)
.customScopeBar {
SearchFilterHeaderView()
.environmentObject(scrapingModel)
.environmentObject(debridManager)
}
}
.backport.onAppear {
searchBarText = getSearchBarText()

View file

@ -76,6 +76,11 @@ struct LibraryView: View {
}
}
.navigationSearchBarHiddenWhenScrolling(false)
.customScopeBar {
LibraryPickerView()
.environmentObject(debridManager)
.environmentObject(navModel)
}
.environment(\.editMode, $editMode)
}
.overlay {
@ -94,11 +99,6 @@ struct LibraryView: View {
}
}
}
.customScopeBar {
LibraryPickerView()
.environmentObject(debridManager)
.environmentObject(navModel)
}
.onChange(of: navModel.libraryPickerSelection) { _ in
editMode = .inactive
}

View file

@ -66,6 +66,10 @@ struct PluginsView: View {
}
}
.navigationSearchBarHiddenWhenScrolling(false)
.customScopeBar {
PluginPickerView()
.environmentObject(navModel)
}
}
.overlay {
if checkedForPlugins {
@ -83,10 +87,6 @@ struct PluginsView: View {
ProgressView()
}
}
.customScopeBar {
PluginPickerView()
.environmentObject(navModel)
}
}
}