diff --git a/Model/NavigationModel.swift b/Model/NavigationModel.swift index 29ef2add..cd4a9ac6 100644 --- a/Model/NavigationModel.swift +++ b/Model/NavigationModel.swift @@ -78,6 +78,7 @@ final class NavigationModel: ObservableObject { return } + navigation.presentingPlaylist = false navigation.presentingChannel = false let recent = RecentItem(from: channel) @@ -115,6 +116,9 @@ final class NavigationModel: ObservableObject { navigationStyle: NavigationStyle, delay: Bool = false ) { + navigation.presentingChannel = false + navigation.presentingPlaylist = false + let recent = RecentItem(from: playlist) #if os(macOS) Windows.main.open() diff --git a/Shared/Navigation/AppTabNavigation.swift b/Shared/Navigation/AppTabNavigation.swift index 957f196d..1a444f60 100644 --- a/Shared/Navigation/AppTabNavigation.swift +++ b/Shared/Navigation/AppTabNavigation.swift @@ -43,24 +43,9 @@ struct AppTabNavigation: View { searchNavigationView } .id(accounts.current?.id ?? "") - .environment(\.navigationStyle, .tab) .overlay(channelView) - - .background( - EmptyView().sheet(isPresented: $navigation.presentingPlaylist) { - if let playlist = recents.presentedPlaylist { - NavigationView { - ChannelPlaylistView(playlist: playlist) - .environment(\.managedObjectContext, persistenceController.container.viewContext) - .environmentObject(accounts) - .environmentObject(navigation) - .environmentObject(player) - .environmentObject(subscriptions) - .environmentObject(thumbnailsModel) - } - } - } - ) + .overlay(playlistView) + .environment(\.navigationStyle, .tab) } private var favoritesNavigationView: some View { @@ -186,4 +171,14 @@ struct AppTabNavigation: View { .environmentObject(subscriptions) .environmentObject(thumbnailsModel) } + + private var playlistView: some View { + ChannelPlaylistView() + .environment(\.managedObjectContext, persistenceController.container.viewContext) + .environmentObject(accounts) + .environmentObject(navigation) + .environmentObject(player) + .environmentObject(subscriptions) + .environmentObject(thumbnailsModel) + } } diff --git a/Shared/Views/ChannelPlaylistView.swift b/Shared/Views/ChannelPlaylistView.swift index fecedbfb..68176da9 100644 --- a/Shared/Views/ChannelPlaylistView.swift +++ b/Shared/Views/ChannelPlaylistView.swift @@ -2,29 +2,71 @@ import Siesta import SwiftUI struct ChannelPlaylistView: View { - var playlist: ChannelPlaylist + #if os(iOS) + static let hiddenOffset = max(UIScreen.main.bounds.height, UIScreen.main.bounds.width) + 100 + #endif + + var playlist: ChannelPlaylist? @State private var presentingShareSheet = false @State private var shareURL: URL? + #if os(iOS) + @State private var viewVerticalOffset = Self.hiddenOffset + #endif + @StateObject private var store = Store() @Environment(\.colorScheme) private var colorScheme + @Environment(\.navigationStyle) private var navigationStyle @EnvironmentObject private var accounts + @EnvironmentObject private var navigation @EnvironmentObject private var player + @EnvironmentObject private var recents - var items: [ContentItem] { + private var items: [ContentItem] { ContentItem.array(of: store.item?.videos ?? []) } - var resource: Resource? { - accounts.api.channelPlaylist(playlist.id) + private var presentedPlaylist: ChannelPlaylist? { + recents.presentedPlaylist ?? playlist + } + + private var resource: Resource? { + guard let playlist = presentedPlaylist else { + return nil + } + + let resource = accounts.api.channelPlaylist(playlist.id) + resource?.addObserver(store) + + return resource } var body: some View { - BrowserPlayerControls { - content + if navigationStyle == .tab { + NavigationView { + BrowserPlayerControls { + content + } + } + #if os(iOS) + .onChange(of: navigation.presentingPlaylist) { newValue in + if newValue { + viewVerticalOffset = 0 + resource?.load() + } else { + viewVerticalOffset = Self.hiddenOffset + } + } + .offset(y: viewVerticalOffset) + .animation(.easeIn(duration: 0.2), value: viewVerticalOffset) + #endif + } else { + BrowserPlayerControls { + content + } } } @@ -58,7 +100,6 @@ struct ChannelPlaylistView: View { } #endif .onAppear { - resource?.addObserver(store) resource?.loadIfNeeded() } #if os(tvOS) @@ -66,23 +107,31 @@ struct ChannelPlaylistView: View { #else .toolbar { ToolbarItem(placement: .navigation) { - ShareButton( - contentItem: contentItem, - presentingShareSheet: $presentingShareSheet, - shareURL: $shareURL - ) + if navigationStyle == .tab { + Button("Done") { + navigation.presentingPlaylist = false + } + } } ToolbarItem(placement: playlistButtonsPlacement) { HStack { - FavoriteButton(item: FavoriteItem(section: .channelPlaylist(playlist.id, playlist.title))) + ShareButton( + contentItem: contentItem, + presentingShareSheet: $presentingShareSheet, + shareURL: $shareURL + ) + + if let playlist = presentedPlaylist { + FavoriteButton(item: FavoriteItem(section: .channelPlaylist(playlist.id, playlist.title))) + } playButton shuffleButton } } } - .navigationTitle(playlist.title) + .navigationTitle(presentedPlaylist?.title ?? "") #endif } diff --git a/Yattee.xcodeproj/project.pbxproj b/Yattee.xcodeproj/project.pbxproj index e795acdc..a208c4cb 100644 --- a/Yattee.xcodeproj/project.pbxproj +++ b/Yattee.xcodeproj/project.pbxproj @@ -1407,6 +1407,7 @@ 37152EE926EFEB95004FB96D /* LazyView.swift */, 37030FF627B0347C00ECDDAA /* MPVPlayerView.swift */, 37E70926271CDDAE00D34DDE /* OpenSettingsButton.swift */, + 37FEF11227EFD8580033912F /* PlaceholderCell.swift */, 3769C02D2779F18600DDB3EA /* PlaceholderProgressView.swift */, 37BA793A26DB8EE4002A0235 /* PlaylistVideosView.swift */, 37AAF27D26737323007FC770 /* PopularView.swift */, @@ -1415,7 +1416,6 @@ 37AAF29F26741C97007FC770 /* SubscriptionsView.swift */, 37B17D9F268A1F25006AEE9B /* VideoContextMenuView.swift */, 37E70922271CD43000D34DDE /* WelcomeScreen.swift */, - 37FEF11227EFD8580033912F /* PlaceholderCell.swift */, ); path = Views; sourceTree = "";