From 975b8fe5c32a81c9b8f66e73822d703d214ad0d6 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Mon, 24 Jan 2022 22:22:47 +0100 Subject: [PATCH] Fix displaying settings/account buttons when only search is visible (fix #56) --- Shared/Navigation/AppTabNavigation.swift | 7 +++++- Shared/Search/SearchView.swift | 31 +++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Shared/Navigation/AppTabNavigation.swift b/Shared/Navigation/AppTabNavigation.swift index 160353e5..a3470416 100644 --- a/Shared/Navigation/AppTabNavigation.swift +++ b/Shared/Navigation/AppTabNavigation.swift @@ -35,7 +35,7 @@ struct AppTabNavigation: View { trendingNavigationView } - if visibleSections.contains(.playlists), accounts.app.supportsUserPlaylists { + if playlistsVisible { playlistsNavigationView } @@ -118,6 +118,11 @@ struct AppTabNavigation: View { accounts.app.supportsSubscriptions && !(accounts.current?.anonymous ?? true) } + private var playlistsVisible: Bool { + visibleSections.contains(.playlists) && + accounts.app.supportsUserPlaylists && !(accounts.current?.anonymous ?? true) + } + private var popularNavigationView: some View { NavigationView { LazyView(PopularView()) diff --git a/Shared/Search/SearchView.swift b/Shared/Search/SearchView.swift index 6c5e0eaf..c5ee48e4 100644 --- a/Shared/Search/SearchView.swift +++ b/Shared/Search/SearchView.swift @@ -177,11 +177,40 @@ struct SearchView: View { .navigationTitle("Search") #endif #if os(iOS) - .navigationBarHidden(!Defaults[.visibleSections].isEmpty || navigationStyle == .sidebar) + .navigationBarHidden(navigationBarHidden) .navigationBarTitleDisplayMode(.inline) #endif } + private var navigationBarHidden: Bool { + if navigationStyle == .sidebar { + return true + } + + let preferred = Defaults[.visibleSections] + var visibleSections = [VisibleSection]() + + if accounts.app.supportsPopular && preferred.contains(.popular) { + visibleSections.append(.popular) + } + + if accounts.app.supportsSubscriptions && accounts.signedIn && preferred.contains(.subscriptions) { + visibleSections.append(.subscriptions) + } + + if accounts.app.supportsUserPlaylists && preferred.contains(.playlists) { + visibleSections.append(.playlists) + } + + [VisibleSection.favorites, .trending].forEach { section in + if preferred.contains(section) { + visibleSections.append(section) + } + } + + return !visibleSections.isEmpty + } + private var results: some View { VStack { if showRecentQueries {