yattee/Shared/Navigation/AppTabNavigation.swift

123 lines
4.3 KiB
Swift
Raw Normal View History

2021-07-11 20:52:49 +00:00
import Defaults
import SwiftUI
struct AppTabNavigation: View {
2021-09-25 08:18:22 +00:00
@EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<SearchModel> private var search
2021-09-25 12:17:58 +00:00
@EnvironmentObject<RecentsModel> private var recents
2021-09-19 11:06:54 +00:00
2021-07-11 20:52:49 +00:00
var body: some View {
2021-09-28 23:01:49 +00:00
TabView(selection: navigation.tabSelectionBinding) {
2021-07-11 20:52:49 +00:00
NavigationView {
2021-09-25 08:18:22 +00:00
LazyView(WatchNowView())
.toolbar { toolbarContent }
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-25 08:18:22 +00:00
LazyView(SubscriptionsView())
.toolbar { toolbarContent }
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 {
2021-09-25 08:18:22 +00:00
// LazyView(PopularView())
// .toolbar { toolbarContent }
2021-09-18 20:36:42 +00:00
// }
// .tabItem {
// Label("Popular", systemImage: "chart.bar")
// .accessibility(label: Text("Popular"))
// }
// .tag(TabSelection.popular)
2021-07-11 20:52:49 +00:00
NavigationView {
2021-09-25 08:18:22 +00:00
LazyView(TrendingView())
.toolbar { toolbarContent }
2021-07-11 20:52:49 +00:00
}
.tabItem {
Label("Trending", systemImage: "chart.line.uptrend.xyaxis")
.accessibility(label: Text("Trending"))
}
.tag(TabSelection.trending)
NavigationView {
2021-09-25 08:18:22 +00:00
LazyView(PlaylistsView())
.toolbar { toolbarContent }
2021-07-11 20:52:49 +00:00
}
.tabItem {
Label("Playlists", systemImage: "list.and.film")
.accessibility(label: Text("Playlists"))
}
.tag(TabSelection.playlists)
NavigationView {
2021-09-25 08:18:22 +00:00
LazyView(
SearchView()
.toolbar { toolbarContent }
.searchable(text: $search.queryText, placement: .navigationBarDrawer(displayMode: .always)) {
ForEach(search.querySuggestions.collection, id: \.self) { suggestion in
Text(suggestion)
.searchCompletion(suggestion)
}
2021-09-13 20:41:16 +00:00
}
2021-09-25 08:18:22 +00:00
.onChange(of: search.queryText) { query in
search.loadSuggestions(query)
2021-09-13 20:41:16 +00:00
}
2021-09-25 08:18:22 +00:00
.onSubmit(of: .search) {
search.changeQuery { query in
query.query = search.queryText
}
2021-09-13 20:41:16 +00:00
2021-09-25 12:17:58 +00:00
recents.addQuery(search.queryText)
2021-09-25 08:18:22 +00:00
}
)
2021-07-11 20:52:49 +00:00
}
.tabItem {
Label("Search", systemImage: "magnifyingglass")
.accessibility(label: Text("Search"))
}
.tag(TabSelection.search)
}
2021-09-19 12:42:47 +00:00
.environment(\.navigationStyle, .tab)
2021-09-25 08:18:22 +00:00
.sheet(isPresented: $navigation.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-25 08:18:22 +00:00
ChannelVideosView(channel: recents.presentedChannel!)
.environment(\.inNavigationView, true)
}
}
}
}
2021-09-25 08:18:22 +00:00
var toolbarContent: some ToolbarContent {
#if os(iOS)
Group {
ToolbarItemGroup(placement: .navigationBarLeading) {
Button(action: { navigation.presentingSettings = true }) {
Image(systemName: "gearshape.2")
}
}
ToolbarItemGroup(placement: .navigationBarTrailing) {
AccountsMenuView()
}
}
#endif
}
2021-07-11 20:52:49 +00:00
}