yattee/Shared/Navigation/AppTabNavigation.swift

101 lines
3.4 KiB
Swift
Raw Normal View History

2021-07-11 20:52:49 +00:00
import Defaults
import SwiftUI
struct AppTabNavigation: View {
@EnvironmentObject<NavigationState> private var navigationState
2021-09-13 20:41:16 +00:00
@EnvironmentObject<SearchState> private var searchState
2021-09-19 11:06:54 +00:00
@EnvironmentObject<Recents> private var recents
2021-09-13 20:41:16 +00:00
@State private var searchQuery = ""
2021-07-11 20:52:49 +00:00
var body: some View {
TabView(selection: $navigationState.tabSelection) {
2021-07-11 20:52:49 +00:00
NavigationView {
2021-09-18 20:36:42 +00:00
WatchNowView()
2021-07-11 20:52:49 +00:00
}
.tabItem {
2021-09-18 20:36:42 +00:00
Label("Watch Now", systemImage: "play.circle")
2021-07-11 20:52:49 +00:00
.accessibility(label: Text("Subscriptions"))
}
2021-09-18 20:36:42 +00:00
.tag(TabSelection.watchNow)
2021-07-11 20:52:49 +00:00
NavigationView {
2021-09-18 20:36:42 +00:00
SubscriptionsView()
2021-07-11 20:52:49 +00:00
}
.tabItem {
2021-09-18 20:36:42 +00:00
Label("Subscriptions", systemImage: "star.circle.fill")
.accessibility(label: Text("Subscriptions"))
2021-07-11 20:52:49 +00:00
}
2021-09-18 20:36:42 +00:00
.tag(TabSelection.subscriptions)
// TODO: reenable with settings
// ============================
// NavigationView {
// PopularView()
// }
// .tabItem {
// Label("Popular", systemImage: "chart.bar")
// .accessibility(label: Text("Popular"))
// }
// .tag(TabSelection.popular)
2021-07-11 20:52:49 +00:00
NavigationView {
TrendingView()
}
.tabItem {
Label("Trending", systemImage: "chart.line.uptrend.xyaxis")
.accessibility(label: Text("Trending"))
}
.tag(TabSelection.trending)
NavigationView {
PlaylistsView()
}
.tabItem {
Label("Playlists", systemImage: "list.and.film")
.accessibility(label: Text("Playlists"))
}
.tag(TabSelection.playlists)
NavigationView {
SearchView()
2021-09-13 20:41:16 +00:00
.searchable(text: $searchQuery, placement: .navigationBarDrawer(displayMode: .always)) {
ForEach(searchState.querySuggestions.collection, id: \.self) { suggestion in
Text(suggestion)
.searchCompletion(suggestion)
}
}
.onChange(of: searchQuery) { query in
searchState.loadQuerySuggestions(query)
}
.onSubmit(of: .search) {
searchState.changeQuery { query in
query.query = self.searchQuery
}
navigationState.tabSelection = .search
}
2021-07-11 20:52:49 +00:00
}
.tabItem {
Label("Search", systemImage: "magnifyingglass")
.accessibility(label: Text("Search"))
}
.tag(TabSelection.search)
}
.sheet(isPresented: $navigationState.isChannelOpen, onDismiss: {
2021-09-19 11:06:54 +00:00
if let channel = recents.presentedChannel {
let recent = RecentItem(from: channel)
recents.close(recent)
}
}) {
2021-09-19 11:06:54 +00:00
if recents.presentedChannel != nil {
NavigationView {
2021-09-19 11:06:54 +00:00
ChannelVideosView(recents.presentedChannel!)
.environment(\.inNavigationView, true)
}
}
}
}
2021-07-11 20:52:49 +00:00
}