yattee/Shared/Navigation/AppTabNavigation.swift

153 lines
5.5 KiB
Swift
Raw Normal View History

2021-07-11 20:52:49 +00:00
import Defaults
import SwiftUI
struct AppTabNavigation: View {
2021-10-22 23:04:03 +00:00
@EnvironmentObject<AccountsModel> private var accounts
2021-09-25 08:18:22 +00:00
@EnvironmentObject<NavigationModel> private var navigation
2021-10-22 23:04:03 +00:00
@EnvironmentObject<PlayerModel> private var player
2021-09-25 12:17:58 +00:00
@EnvironmentObject<RecentsModel> private var recents
2021-10-22 23:04:03 +00:00
@EnvironmentObject<SearchModel> private var search
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
2021-10-22 23:04:03 +00:00
if accounts.app.supportsSubscriptions {
NavigationView {
LazyView(SubscriptionsView())
.toolbar { toolbarContent }
}
.tabItem {
Label("Subscriptions", systemImage: "star.circle.fill")
.accessibility(label: Text("Subscriptions"))
}
.tag(TabSelection.subscriptions)
2021-07-11 20:52:49 +00:00
}
2021-09-18 20:36:42 +00:00
2021-10-22 23:04:03 +00:00
// TODO: reenable with settings
if accounts.app.supportsPopular && false {
NavigationView {
LazyView(PopularView())
.toolbar { toolbarContent }
}
.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)
2021-10-22 23:04:03 +00:00
if accounts.app.supportsUserPlaylists {
NavigationView {
LazyView(PlaylistsView())
.toolbar { toolbarContent }
}
.tabItem {
Label("Playlists", systemImage: "list.and.film")
.accessibility(label: Text("Playlists"))
}
.tag(TabSelection.playlists)
2021-07-11 20:52:49 +00:00
}
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-10-22 23:04:03 +00:00
.sheet(isPresented: $navigation.presentingChannel, onDismiss: {
if let channel = recents.presentedChannel {
recents.close(RecentItem(from: channel))
}
}) {
2021-09-19 11:06:54 +00:00
if let channel = recents.presentedChannel {
2021-10-22 23:04:03 +00:00
NavigationView {
ChannelVideosView(channel: channel)
2021-10-28 17:14:55 +00:00
.environment(\.inChannelView, true)
2021-10-22 23:04:03 +00:00
.environment(\.inNavigationView, true)
.background(playerNavigationLink)
}
}
}
.sheet(isPresented: $navigation.presentingPlaylist, onDismiss: {
if let playlist = recents.presentedPlaylist {
recents.close(RecentItem(from: playlist))
2021-09-19 11:06:54 +00:00
}
}) {
2021-10-22 23:04:03 +00:00
if let playlist = recents.presentedPlaylist {
NavigationView {
2021-10-22 23:04:03 +00:00
ChannelPlaylistView(playlist: playlist)
.environment(\.inNavigationView, true)
2021-10-22 23:04:03 +00:00
.background(playerNavigationLink)
}
}
}
}
2021-09-25 08:18:22 +00:00
2021-10-22 23:04:03 +00:00
private var playerNavigationLink: some View {
NavigationLink(isActive: $player.playerNavigationLinkActive, destination: {
VideoPlayerView()
.environment(\.inNavigationView, true)
}) {
EmptyView()
}
}
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
}