1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 22:30:32 +05:30
yattee/Shared/Navigation/AppTabNavigation.swift

200 lines
6.3 KiB
Swift
Raw Normal View History

2021-07-12 02:22:49 +05:30
import Defaults
import SwiftUI
struct AppTabNavigation: View {
@ObservedObject private var accounts = AccountsModel.shared
@ObservedObject private var navigation = NavigationModel.shared
private var player = PlayerModel.shared
@ObservedObject private var subscriptions = SubscriptionsModel.shared
2021-09-19 16:36:54 +05:30
2022-11-12 01:58:40 +05:30
@Default(.showHome) private var showHome
2022-11-13 04:31:04 +05:30
@Default(.showDocuments) private var showDocuments
2022-11-12 01:58:40 +05:30
@Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem
@Default(.visibleSections) private var visibleSections
2021-11-08 02:21:22 +05:30
let persistenceController = PersistenceController.shared
2021-07-12 02:22:49 +05:30
var body: some View {
2021-09-29 04:31:49 +05:30
TabView(selection: navigation.tabSelectionBinding) {
2022-11-12 01:58:40 +05:30
let tabs = Group {
if showHome {
homeNavigationView
}
2021-07-12 02:22:49 +05:30
2022-11-13 04:31:04 +05:30
if showDocuments {
documentsNavigationView
}
2022-11-12 01:58:40 +05:30
if !accounts.isEmpty {
if subscriptionsVisible {
subscriptionsNavigationView
}
2021-09-19 02:06:42 +05:30
2022-11-12 01:58:40 +05:30
if visibleSections.contains(.popular), accounts.app.supportsPopular, visibleSections.count < 5 {
popularNavigationView
}
2021-07-12 02:22:49 +05:30
2022-11-12 01:58:40 +05:30
if visibleSections.contains(.trending) {
trendingNavigationView
}
if playlistsVisible {
playlistsNavigationView
}
2021-07-12 02:22:49 +05:30
2022-11-12 01:58:40 +05:30
searchNavigationView
}
2021-07-12 02:22:49 +05:30
}
2022-11-12 01:58:40 +05:30
if #available(iOS 16, tvOS 16, *) {
tabs
.toolbar(accounts.isEmpty ? .hidden : .visible, for: .tabBar)
} else {
tabs
2022-11-12 01:04:20 +05:30
}
2021-07-12 02:22:49 +05:30
}
2022-11-12 01:58:40 +05:30
2021-12-01 04:28:46 +05:30
.id(accounts.current?.id ?? "")
2022-05-30 00:39:57 +05:30
.overlay(playlistView)
2022-05-30 01:42:59 +05:30
.overlay(channelView)
2022-05-30 00:39:57 +05:30
.environment(\.navigationStyle, .tab)
}
2021-09-25 13:48:22 +05:30
2022-11-09 19:04:04 +05:30
private var homeNavigationView: some View {
NavigationView {
2022-11-09 19:04:04 +05:30
LazyView(HomeView())
.toolbar { toolbarContent }
}
.tabItem {
2022-11-09 19:04:04 +05:30
Label("Home", systemImage: "house.fill")
.accessibility(label: Text("Home"))
}
2022-11-09 19:04:04 +05:30
.tag(TabSelection.home)
}
2022-11-13 04:31:04 +05:30
private var documentsNavigationView: some View {
NavigationView {
LazyView(DocumentsView())
.toolbar { toolbarContent }
}
.tabItem {
Label("Documents", systemImage: "folder")
.accessibility(label: Text("Documents"))
}
.tag(TabSelection.documents)
}
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-08 02:21:22 +05:30
private var subscriptionsVisible: Bool {
visibleSections.contains(.subscriptions) &&
accounts.app.supportsSubscriptions && !(accounts.current?.anonymous ?? true)
2021-11-08 02:21:22 +05:30
}
private var playlistsVisible: Bool {
visibleSections.contains(.playlists) &&
accounts.app.supportsUserPlaylists && !(accounts.current?.anonymous ?? true)
}
2021-11-08 02:21:22 +05:30
private var popularNavigationView: some View {
NavigationView {
LazyView(PopularView())
.toolbar { toolbarContent }
}
.tabItem {
2022-02-17 01:53:11 +05:30
Label("Popular", systemImage: "arrow.up.right.circle.fill")
2021-11-08 02:21:22 +05:30
.accessibility(label: Text("Popular"))
}
.tag(TabSelection.popular)
}
private var trendingNavigationView: some View {
NavigationView {
LazyView(TrendingView())
.toolbar { toolbarContent }
}
.tabItem {
2022-02-17 01:53:11 +05:30
Label("Trending", systemImage: "chart.bar.fill")
2021-11-08 02:21:22 +05:30
.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-09-25 13:48:22 +05:30
var toolbarContent: some ToolbarContent {
#if os(iOS)
Group {
ToolbarItemGroup(placement: .navigationBarLeading) {
Button(action: { navigation.presentingSettings = true }) {
Image(systemName: "gearshape.2")
}
}
ToolbarItemGroup(placement: .navigationBarTrailing) {
2022-11-12 01:58:40 +05:30
if showOpenActionsToolbarItem {
Button(action: { navigation.presentingOpenVideos = true }) {
Label("Open Videos", systemImage: "play.circle.fill")
}
2022-11-10 22:41:28 +05:30
}
2021-09-25 13:48:22 +05:30
AccountsMenuView()
}
}
#endif
}
2022-05-29 23:56:56 +05:30
2022-07-09 05:51:04 +05:30
@ViewBuilder private var channelView: some View {
if navigation.presentingChannel {
ChannelVideosView()
.environment(\.managedObjectContext, persistenceController.container.viewContext)
.environment(\.inChannelView, true)
.environment(\.navigationStyle, .tab)
.id("channelVideos")
2022-08-25 22:39:55 +05:30
.zIndex(player.presentingPlayer ? -1 : 2)
.transition(.move(edge: .bottom))
2022-07-09 05:51:04 +05:30
}
2022-05-29 23:56:56 +05:30
}
2022-05-30 00:39:57 +05:30
2022-07-09 05:51:04 +05:30
@ViewBuilder private var playlistView: some View {
if navigation.presentingPlaylist {
ChannelPlaylistView()
.environment(\.managedObjectContext, persistenceController.container.viewContext)
.id("channelPlaylist")
2022-08-25 22:39:55 +05:30
.zIndex(player.presentingPlayer ? -1 : 1)
.transition(.move(edge: .bottom))
2022-07-09 05:51:04 +05:30
}
2022-05-30 00:39:57 +05:30
}
2021-07-12 02:22:49 +05:30
}