yattee/Shared/Navigation/AppTabNavigation.swift

207 lines
7.1 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-12-04 19:35:41 +00:00
@EnvironmentObject<CommentsModel> private var comments
@EnvironmentObject<InstancesModel> private var instances
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-12-04 19:35:41 +00:00
@EnvironmentObject<PlaylistsModel> private var playlists
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-12-04 19:35:41 +00:00
@EnvironmentObject<SubscriptionsModel> private var subscriptions
@EnvironmentObject<ThumbnailsModel> private var thumbnailsModel
2021-09-19 11:06:54 +00:00
@Default(.visibleSections) private var visibleSections
2021-11-07 20:51:22 +00:00
let persistenceController = PersistenceController.shared
2021-07-11 20:52:49 +00:00
var body: some View {
2021-09-28 23:01:49 +00:00
TabView(selection: navigation.tabSelectionBinding) {
if visibleSections.contains(.favorites) {
favoritesNavigationView
2021-07-11 20:52:49 +00:00
}
2021-11-07 20:51:22 +00:00
if subscriptionsVisible {
subscriptionsNavigationView
2021-07-11 20:52:49 +00:00
}
2021-09-18 20:36:42 +00:00
2021-12-02 20:35:42 +00:00
if visibleSections.contains(.popular), accounts.app.supportsPopular, visibleSections.count < 5 {
popularNavigationView
2021-07-11 20:52:49 +00:00
}
if visibleSections.contains(.trending) {
trendingNavigationView
2021-07-11 20:52:49 +00:00
}
if visibleSections.contains(.playlists), accounts.app.supportsUserPlaylists {
playlistsNavigationView
2021-07-11 20:52:49 +00:00
}
searchNavigationView
2021-07-11 20:52:49 +00:00
}
2021-11-30 22:58:46 +00:00
.id(accounts.current?.id ?? "")
2021-09-19 12:42:47 +00:00
.environment(\.navigationStyle, .tab)
2021-11-30 22:58:46 +00:00
.background(
EmptyView().sheet(isPresented: $navigation.presentingChannel) {
2021-11-30 22:58:46 +00:00
if let channel = recents.presentedChannel {
NavigationView {
ChannelVideosView(channel: channel)
.environment(\.managedObjectContext, persistenceController.container.viewContext)
2021-11-30 22:58:46 +00:00
.environment(\.inChannelView, true)
.environment(\.inNavigationView, true)
2021-12-17 19:58:24 +00:00
.environmentObject(accounts)
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(subscriptions)
.environmentObject(thumbnailsModel)
2021-11-30 22:58:46 +00:00
.background(playerNavigationLink)
}
2021-10-22 23:04:03 +00:00
}
}
2021-11-30 22:58:46 +00:00
)
.background(
EmptyView().sheet(isPresented: $navigation.presentingPlaylist) {
2021-11-30 22:58:46 +00:00
if let playlist = recents.presentedPlaylist {
NavigationView {
ChannelPlaylistView(playlist: playlist)
.environment(\.managedObjectContext, persistenceController.container.viewContext)
2021-11-30 22:58:46 +00:00
.environment(\.inNavigationView, true)
2021-12-17 19:58:24 +00:00
.environmentObject(accounts)
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(subscriptions)
2021-12-17 19:58:24 +00:00
.environmentObject(thumbnailsModel)
2021-11-30 22:58:46 +00:00
.background(playerNavigationLink)
}
}
}
2021-11-30 22:58:46 +00:00
)
2021-12-04 19:35:41 +00:00
.background(
EmptyView().fullScreenCover(isPresented: $player.presentingPlayer) {
videoPlayer
.environment(\.managedObjectContext, persistenceController.container.viewContext)
2021-12-17 19:58:24 +00:00
.environment(\.navigationStyle, .tab)
2021-12-04 19:35:41 +00:00
}
)
}
2021-09-25 08:18:22 +00:00
private var favoritesNavigationView: some View {
NavigationView {
LazyView(FavoritesView())
.toolbar { toolbarContent }
}
.tabItem {
Label("Favorites", systemImage: "heart")
.accessibility(label: Text("Favorites"))
}
.tag(TabSelection.favorites)
}
private var subscriptionsNavigationView: some View {
NavigationView {
LazyView(SubscriptionsView())
.toolbar { toolbarContent }
}
.tabItem {
Label("Subscriptions", systemImage: "star.circle.fill")
.accessibility(label: Text("Subscriptions"))
}
.tag(TabSelection.subscriptions)
}
2021-11-07 20:51:22 +00:00
private var subscriptionsVisible: Bool {
visibleSections.contains(.subscriptions) &&
accounts.app.supportsSubscriptions && !(accounts.current?.anonymous ?? true)
2021-11-07 20:51:22 +00:00
}
private var popularNavigationView: some View {
NavigationView {
LazyView(PopularView())
.toolbar { toolbarContent }
}
.tabItem {
2021-11-28 14:37:55 +00:00
Label("Popular", systemImage: "arrow.up.right.circle")
2021-11-07 20:51:22 +00:00
.accessibility(label: Text("Popular"))
}
.tag(TabSelection.popular)
}
private var trendingNavigationView: some View {
NavigationView {
LazyView(TrendingView())
.toolbar { toolbarContent }
}
.tabItem {
2021-11-28 14:37:55 +00:00
Label("Trending", systemImage: "chart.bar")
2021-11-07 20:51:22 +00:00
.accessibility(label: Text("Trending"))
}
.tag(TabSelection.trending)
}
private var playlistsNavigationView: some View {
NavigationView {
LazyView(PlaylistsView())
.toolbar { toolbarContent }
}
.tabItem {
Label("Playlists", systemImage: "list.and.film")
.accessibility(label: Text("Playlists"))
}
.tag(TabSelection.playlists)
}
private var searchNavigationView: some View {
NavigationView {
LazyView(SearchView())
.toolbar { toolbarContent }
}
.tabItem {
Label("Search", systemImage: "magnifyingglass")
.accessibility(label: Text("Search"))
}
.tag(TabSelection.search)
}
2021-10-22 23:04:03 +00:00
private var playerNavigationLink: some View {
NavigationLink(isActive: $player.playerNavigationLinkActive, destination: {
2021-12-17 19:58:24 +00:00
videoPlayer
2021-10-22 23:04:03 +00:00
.environment(\.inNavigationView, true)
}) {
EmptyView()
}
}
2021-12-04 19:35:41 +00:00
private var videoPlayer: some View {
VideoPlayerView()
.environmentObject(accounts)
.environmentObject(comments)
.environmentObject(instances)
.environmentObject(navigation)
.environmentObject(player)
.environmentObject(playlists)
.environmentObject(recents)
.environmentObject(subscriptions)
.environmentObject(thumbnailsModel)
}
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
}