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

View file

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

View file

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

View file

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