2021-07-12 02:22:49 +05:30
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct TVNavigationView: View {
|
|
|
|
@EnvironmentObject<NavigationState> private var navigationState
|
2021-08-24 03:01:51 +05:30
|
|
|
@EnvironmentObject<PlaybackState> private var playbackState
|
2021-09-14 02:11:16 +05:30
|
|
|
@EnvironmentObject<SearchState> private var searchState
|
2021-07-12 02:22:49 +05:30
|
|
|
|
|
|
|
@State private var showingOptions = false
|
|
|
|
|
2021-08-02 02:55:50 +05:30
|
|
|
@Default(.showingAddToPlaylist) var showingAddToPlaylist
|
|
|
|
|
2021-07-12 02:22:49 +05:30
|
|
|
var body: some View {
|
2021-08-03 04:43:42 +05:30
|
|
|
TabView(selection: $navigationState.tabSelection) {
|
|
|
|
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-14 02:11:16 +05:30
|
|
|
.searchable(text: $searchState.query.query) {
|
|
|
|
ForEach(searchState.querySuggestions.collection, id: \.self) { suggestion in
|
|
|
|
Text(suggestion)
|
|
|
|
.searchCompletion(suggestion)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.onChange(of: searchState.query.query) { query in
|
|
|
|
searchState.loadQuerySuggestions(query)
|
|
|
|
}
|
2021-08-03 04:43:42 +05:30
|
|
|
.tabItem { Image(systemName: "magnifyingglass") }
|
|
|
|
.tag(TabSelection.search)
|
|
|
|
}
|
|
|
|
.fullScreenCover(isPresented: $showingOptions) { OptionsView() }
|
|
|
|
.fullScreenCover(isPresented: $showingAddToPlaylist) { AddToPlaylistView() }
|
|
|
|
.fullScreenCover(isPresented: $navigationState.showingVideoDetails) {
|
|
|
|
if let video = navigationState.video {
|
|
|
|
VideoDetailsView(video)
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
2021-08-03 04:43:42 +05:30
|
|
|
}
|
|
|
|
.fullScreenCover(isPresented: $navigationState.showingVideo) {
|
|
|
|
if let video = navigationState.video {
|
|
|
|
VideoPlayerView(video)
|
2021-08-24 03:01:51 +05:30
|
|
|
.environmentObject(playbackState)
|
2021-08-02 02:55:50 +05:30
|
|
|
}
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
2021-09-01 02:47:50 +05:30
|
|
|
.fullScreenCover(isPresented: $navigationState.isChannelOpen, onDismiss: {
|
|
|
|
navigationState.closeChannel(presentedChannel)
|
|
|
|
}) {
|
|
|
|
if presentedChannel != nil {
|
|
|
|
ChannelVideosView(presentedChannel)
|
|
|
|
.background(.thickMaterial)
|
|
|
|
}
|
|
|
|
}
|
2021-08-03 04:43:42 +05:30
|
|
|
.onPlayPauseCommand { showingOptions.toggle() }
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
2021-09-01 02:47:50 +05:30
|
|
|
|
|
|
|
fileprivate var presentedChannel: Channel! {
|
|
|
|
navigationState.openChannels.first
|
|
|
|
}
|
2021-07-12 02:22:49 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
struct TVNavigationView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
TVNavigationView()
|
|
|
|
}
|
|
|
|
}
|