yattee/tvOS/TVNavigationView.swift

73 lines
2.5 KiB
Swift
Raw Normal View History

2021-07-11 20:52:49 +00:00
import Defaults
import SwiftUI
struct TVNavigationView: View {
@EnvironmentObject<NavigationState> private var navigationState
2021-08-23 21:31:51 +00:00
@EnvironmentObject<PlaybackState> private var playbackState
2021-09-19 11:06:54 +00:00
@EnvironmentObject<Recents> private var recents
2021-09-13 20:41:16 +00:00
@EnvironmentObject<SearchState> private var searchState
2021-07-11 20:52:49 +00:00
@State private var showingOptions = false
@Default(.showingAddToPlaylist) var showingAddToPlaylist
2021-07-11 20:52:49 +00:00
var body: some View {
2021-08-02 23:13:42 +00:00
TabView(selection: $navigationState.tabSelection) {
2021-09-18 20:36:42 +00:00
WatchNowView()
.tabItem { Text("Watch Now") }
.tag(TabSelection.watchNow)
2021-08-02 23:13:42 +00:00
SubscriptionsView()
.tabItem { Text("Subscriptions") }
.tag(TabSelection.subscriptions)
PopularView()
.tabItem { Text("Popular") }
.tag(TabSelection.popular)
TrendingView()
.tabItem { Text("Trending") }
.tag(TabSelection.trending)
PlaylistsView()
.tabItem { Text("Playlists") }
.tag(TabSelection.playlists)
SearchView()
2021-09-19 12:42:47 +00:00
.searchable(text: $searchState.queryText) {
2021-09-13 20:41:16 +00:00
ForEach(searchState.querySuggestions.collection, id: \.self) { suggestion in
Text(suggestion)
.searchCompletion(suggestion)
}
}
2021-09-19 12:42:47 +00:00
.onChange(of: searchState.queryText) { newQuery in
searchState.loadQuerySuggestions(newQuery)
searchState.changeQuery { query in query.query = newQuery }
2021-09-13 20:41:16 +00:00
}
2021-08-02 23:13:42 +00:00
.tabItem { Image(systemName: "magnifyingglass") }
.tag(TabSelection.search)
}
.fullScreenCover(isPresented: $showingOptions) { OptionsView() }
.fullScreenCover(isPresented: $showingAddToPlaylist) { AddToPlaylistView() }
.fullScreenCover(isPresented: $navigationState.showingVideo) {
if let video = navigationState.video {
VideoPlayerView(video)
2021-08-23 21:31:51 +00:00
.environmentObject(playbackState)
}
2021-07-11 20:52:49 +00:00
}
2021-09-19 11:06:54 +00:00
.fullScreenCover(isPresented: $navigationState.isChannelOpen) {
if let channel = recents.presentedChannel {
ChannelVideosView(channel)
.background(.thickMaterial)
}
}
2021-08-02 23:13:42 +00:00
.onPlayPauseCommand { showingOptions.toggle() }
2021-07-11 20:52:49 +00:00
}
}
struct TVNavigationView_Previews: PreviewProvider {
static var previews: some View {
TVNavigationView()
}
}