From dc3014095c4404ec412f3a640207da7ae3a077fd Mon Sep 17 00:00:00 2001 From: kingbri Date: Wed, 12 Apr 2023 23:25:17 -0400 Subject: [PATCH] Search/Lists: Fix UI issues and appearance The search bar sometimes had the scope bar added twice if a toolbar was present (probably caused a refresh of the navigationTitle). Rather than figuring out a hacky swiftUI solution to solve this, add a check to enforce only one HostingViewController in the scope bar. Also migrate the inlinedList modifier to use safeAreaInsets from native SwiftUI. Keep the introspected modifier for negative values. Signed-off-by: kingbri --- .../Views/ComponentViews/Library/BookmarksView.swift | 5 ++++- .../Plugin/Buttons/PluginCatalogButtonView.swift | 4 +++- .../ComponentViews/Plugin/PluginAggregateView.swift | 1 - Ferrite/Views/ContentView.swift | 5 ++++- .../Views/RepresentableViews/ExpandedSearchable.swift | 10 +++++++--- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Ferrite/Views/ComponentViews/Library/BookmarksView.swift b/Ferrite/Views/ComponentViews/Library/BookmarksView.swift index f765ec3..60bd3cf 100644 --- a/Ferrite/Views/ComponentViews/Library/BookmarksView.swift +++ b/Ferrite/Views/ComponentViews/Library/BookmarksView.swift @@ -51,7 +51,10 @@ struct BookmarksView: View { fetchPredicate() } .listStyle(.insetGrouped) - .inlinedList(inset: 15) + .safeAreaInset(edge: .top, spacing: 0) { + Spacer() + .frame(height: 15) + } .task { if debridManager.enabledDebrids.count > 0 { let magnets = bookmarks.compactMap { diff --git a/Ferrite/Views/ComponentViews/Plugin/Buttons/PluginCatalogButtonView.swift b/Ferrite/Views/ComponentViews/Plugin/Buttons/PluginCatalogButtonView.swift index 9f9be28..4305798 100644 --- a/Ferrite/Views/ComponentViews/Plugin/Buttons/PluginCatalogButtonView.swift +++ b/Ferrite/Views/ComponentViews/Plugin/Buttons/PluginCatalogButtonView.swift @@ -8,6 +8,8 @@ import SwiftUI struct PluginCatalogButtonView: View { + @Environment(\.colorScheme) var colorScheme + @EnvironmentObject var pluginManager: PluginManager let availablePlugin: PJ @@ -58,7 +60,7 @@ struct PluginCatalogButtonView: View { ) .padding(.horizontal, 7) .padding(.vertical, 5) - .background(Color(uiColor: .tertiarySystemBackground)) + .background(colorScheme == .light ? Color(uiColor: .secondarySystemBackground) : Color(uiColor: .tertiarySystemBackground)) .clipShape(RoundedRectangle(cornerRadius: 10)) } .buttonStyle(.borderless) diff --git a/Ferrite/Views/ComponentViews/Plugin/PluginAggregateView.swift b/Ferrite/Views/ComponentViews/Plugin/PluginAggregateView.swift index 71f6d97..3dd06ad 100644 --- a/Ferrite/Views/ComponentViews/Plugin/PluginAggregateView.swift +++ b/Ferrite/Views/ComponentViews/Plugin/PluginAggregateView.swift @@ -71,7 +71,6 @@ struct PluginAggregateView: View { } } } - .inlinedList(inset: 0) .listStyle(.insetGrouped) .onAppear { fetchPredicate() diff --git a/Ferrite/Views/ContentView.swift b/Ferrite/Views/ContentView.swift index 5826aff..5f2a4cd 100644 --- a/Ferrite/Views/ContentView.swift +++ b/Ferrite/Views/ContentView.swift @@ -32,7 +32,10 @@ struct ContentView: View { SearchResultsView(searchText: $searchText) } .listStyle(.insetGrouped) - .inlinedList(inset: 20) + .safeAreaInset(edge: .top, spacing: 0) { + Spacer() + .frame(height: 20) + } .navigationTitle("Search") .overlay { if diff --git a/Ferrite/Views/RepresentableViews/ExpandedSearchable.swift b/Ferrite/Views/RepresentableViews/ExpandedSearchable.swift index 2570c58..e361f07 100644 --- a/Ferrite/Views/RepresentableViews/ExpandedSearchable.swift +++ b/Ferrite/Views/RepresentableViews/ExpandedSearchable.swift @@ -167,13 +167,17 @@ struct SearchBar: UIViewControllerRepresentable { searchController.searchBar.scopeButtonTitles = [""] (searchController.searchBar.value(forKey: "_scopeBar") as? UIView)?.isHidden = true + guard + let containerView = searchController.searchBar.value(forKey: "_scopeBarContainerView") as? UIView, + !containerView.subviews.contains(where: { String(describing: $0.classForCoder).contains("UIHostingView") }) + else { + return + } + let hostingController = UIHostingController(rootView: content) hostingController.view.translatesAutoresizingMaskIntoConstraints = false hostingController.view.backgroundColor = .clear - guard let containerView = searchController.searchBar.value(forKey: "_scopeBarContainerView") as? UIView else { - return - } containerView.addSubview(hostingController.view) NSLayoutConstraint.activate([