From 0661ed66f334c6008d468fd27f87f2a2f87d7f5d Mon Sep 17 00:00:00 2001 From: kingbri Date: Tue, 28 Feb 2023 19:42:20 -0500 Subject: [PATCH] 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 --- .../CommonViews/Modifiers/CustomScopeBar.swift | 13 +++++++------ Ferrite/Views/ContentView.swift | 10 +++++----- Ferrite/Views/LibraryView.swift | 10 +++++----- Ferrite/Views/PluginsView.swift | 8 ++++---- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Ferrite/Views/CommonViews/Modifiers/CustomScopeBar.swift b/Ferrite/Views/CommonViews/Modifiers/CustomScopeBar.swift index 98626bf..1cb11b1 100644 --- a/Ferrite/Views/CommonViews/Modifiers/CustomScopeBar.swift +++ b/Ferrite/Views/CommonViews/Modifiers/CustomScopeBar.swift @@ -9,24 +9,25 @@ import SwiftUI import Introspect struct CustomScopeBarModifier: ViewModifier { - @AppStorage("Behavior.AutocorrectSearch") var autocorrectSearch = true - let hostingContent: V @State private var hostingController: UIHostingController? - 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 diff --git a/Ferrite/Views/ContentView.swift b/Ferrite/Views/ContentView.swift index 7089b7b..36db8af 100644 --- a/Ferrite/Views/ContentView.swift +++ b/Ferrite/Views/ContentView.swift @@ -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() diff --git a/Ferrite/Views/LibraryView.swift b/Ferrite/Views/LibraryView.swift index 89dfdd9..6629c4b 100644 --- a/Ferrite/Views/LibraryView.swift +++ b/Ferrite/Views/LibraryView.swift @@ -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 } diff --git a/Ferrite/Views/PluginsView.swift b/Ferrite/Views/PluginsView.swift index 07a71aa..3f4b179 100644 --- a/Ferrite/Views/PluginsView.swift +++ b/Ferrite/Views/PluginsView.swift @@ -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) - } } }