Add settings to tvOS tab menu (fix #119)

This commit is contained in:
Arkadiusz Fal 2022-06-26 15:17:18 +02:00
parent d330771fef
commit d670a76635
3 changed files with 135 additions and 113 deletions

View File

@ -13,6 +13,9 @@ final class NavigationModel: ObservableObject {
case recentlyOpened(String)
case nowPlaying
case search
#if os(tvOS)
case settings
#endif
var stringValue: String {
switch self {
@ -34,6 +37,10 @@ final class NavigationModel: ObservableObject {
return "recentlyOpened"
case .search:
return "search"
#if os(tvOS)
case .settings: // swiftlint:disable:this switch_case_alignment
return "settings"
#endif
default:
return ""
}

View File

@ -79,90 +79,99 @@ struct SettingsView: View {
.padding(20)
.frame(width: 480, height: windowHeight)
#else
NavigationView {
List {
#if os(tvOS)
AccountSelectionView()
#endif
Section(header: Text("Instances")) {
ForEach(instances) { instance in
AccountsNavigationLink(instance: instance)
}
addInstanceButton
Group {
#if os(tvOS)
settingsList
#else
NavigationView {
settingsList
}
#if os(tvOS)
Divider()
#endif
Section {
#if os(tvOS)
NavigationLink {
EditFavorites()
} label: {
Label("Favorites", systemImage: "heart.fill")
}
#endif
NavigationLink {
BrowsingSettings()
} label: {
Label("Browsing", systemImage: "list.and.film")
}
NavigationLink {
PlayerSettings()
} label: {
Label("Player", systemImage: "play.rectangle")
}
NavigationLink {
HistorySettings()
} label: {
Label("History", systemImage: "clock.arrow.circlepath")
}
NavigationLink {
SponsorBlockSettings()
} label: {
Label("SponsorBlock", systemImage: "dollarsign.circle")
}
}
Section(footer: versionString) {
NavigationLink {
Help()
} label: {
Label("Help", systemImage: "questionmark.circle")
}
}
}
.navigationTitle("Settings")
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
#if !os(tvOS)
Button("Done") {
presentationMode.wrappedValue.dismiss()
}
.keyboardShortcut(.cancelAction)
#endif
}
}
.frame(maxWidth: 1000)
#if os(iOS)
.listStyle(.insetGrouped)
#endif
}
.sheet(isPresented: $presentingInstanceForm) {
InstanceForm(savedInstanceID: $savedFormInstanceID)
}
#if os(tvOS)
.background(Color.background(scheme: colorScheme))
#endif
#endif
}
#if !os(macOS)
var settingsList: some View {
List {
#if os(tvOS)
AccountSelectionView()
#endif
Section(header: Text("Instances")) {
ForEach(instances) { instance in
AccountsNavigationLink(instance: instance)
}
addInstanceButton
}
#if os(tvOS)
Divider()
#endif
Section {
#if os(tvOS)
NavigationLink {
EditFavorites()
} label: {
Label("Favorites", systemImage: "heart.fill")
}
#endif
NavigationLink {
BrowsingSettings()
} label: {
Label("Browsing", systemImage: "list.and.film")
}
NavigationLink {
PlayerSettings()
} label: {
Label("Player", systemImage: "play.rectangle")
}
NavigationLink {
HistorySettings()
} label: {
Label("History", systemImage: "clock.arrow.circlepath")
}
NavigationLink {
SponsorBlockSettings()
} label: {
Label("SponsorBlock", systemImage: "dollarsign.circle")
}
}
Section(footer: versionString) {
NavigationLink {
Help()
} label: {
Label("Help", systemImage: "questionmark.circle")
}
}
}
.navigationTitle("Settings")
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
#if !os(tvOS)
Button("Done") {
presentationMode.wrappedValue.dismiss()
}
.keyboardShortcut(.cancelAction)
#endif
}
}
.frame(maxWidth: 1000)
#if os(iOS)
.listStyle(.insetGrouped)
#endif
}
#endif
#if os(macOS)
private var windowHeight: Double {
switch selection {

View File

@ -10,44 +10,51 @@ struct TVNavigationView: View {
@Default(.visibleSections) private var visibleSections
var body: some View {
TabView(selection: navigation.tabSelectionBinding) {
if visibleSections.contains(.favorites) {
FavoritesView()
.tabItem { Text("Favorites") }
.tag(TabSelection.favorites)
NavigationView {
TabView(selection: navigation.tabSelectionBinding) {
if visibleSections.contains(.favorites) {
FavoritesView()
.tabItem { Text("Favorites") }
.tag(TabSelection.favorites)
}
if visibleSections.contains(.subscriptions), accounts.app.supportsSubscriptions, accounts.api.signedIn {
SubscriptionsView()
.tabItem { Text("Subscriptions") }
.tag(TabSelection.subscriptions)
}
if visibleSections.contains(.popular), accounts.app.supportsPopular {
PopularView()
.tabItem { Text("Popular") }
.tag(TabSelection.popular)
}
if visibleSections.contains(.trending) {
TrendingView()
.tabItem { Text("Trending") }
.tag(TabSelection.trending)
}
if visibleSections.contains(.playlists), accounts.app.supportsUserPlaylists {
PlaylistsView()
.tabItem { Text("Playlists") }
.tag(TabSelection.playlists)
}
NowPlayingView()
.tabItem { Text("Now Playing") }
.tag(TabSelection.nowPlaying)
SearchView()
.tabItem { Image(systemName: "magnifyingglass") }
.tag(TabSelection.search)
SettingsView()
.navigationBarHidden(true)
.tabItem { Image(systemName: "gear") }
.tag(TabSelection.settings)
}
if visibleSections.contains(.subscriptions), accounts.app.supportsSubscriptions, accounts.api.signedIn {
SubscriptionsView()
.tabItem { Text("Subscriptions") }
.tag(TabSelection.subscriptions)
}
if visibleSections.contains(.popular), accounts.app.supportsPopular {
PopularView()
.tabItem { Text("Popular") }
.tag(TabSelection.popular)
}
if visibleSections.contains(.trending) {
TrendingView()
.tabItem { Text("Trending") }
.tag(TabSelection.trending)
}
if visibleSections.contains(.playlists), accounts.app.supportsUserPlaylists {
PlaylistsView()
.tabItem { Text("Playlists") }
.tag(TabSelection.playlists)
}
NowPlayingView()
.tabItem { Text("Now Playing") }
.tag(TabSelection.nowPlaying)
SearchView()
.tabItem { Image(systemName: "magnifyingglass") }
.tag(TabSelection.search)
}
.fullScreenCover(isPresented: $navigation.presentingSettings) { SettingsView() }
.fullScreenCover(isPresented: $navigation.presentingAddToPlaylist) {
@ -68,7 +75,6 @@ struct TVNavigationView: View {
ChannelPlaylistView(playlist: playlist)
}
}
.onPlayPauseCommand { navigation.presentingSettings.toggle() }
}
}