Present shared sheets through one host per window

The add-to-playlist, download options and queue sheets were declared in
every view that could open them: the root view (twice, mirrored from
coordinator flags), the expanded player, its portrait and floating
panels, the player controls and the video info view.

AppSheet lists the shared sheets, and .appSheetHost() declares them
once. The app root and the expanded player each host them, and every
presented sheet hosts the next level. Views present through the
presentAppSheet environment action, which reaches the nearest host;
code without a view (and the expanded player itself, whose host sits
in its own body) uses PresentationRouter.request, taken by the
top-most host: the player while it is up, the root otherwise.

The mini player's queue and playlist sheets now go through the host,
replacing the isMiniPlayer*SheetPresented flags.
This commit is contained in:
Arkadiusz Fal
2026-10-03 23:45:08 +02:00
parent c0495f3174
commit 28a75792e8
13 changed files with 241 additions and 151 deletions

View File

@@ -19,6 +19,7 @@ enum VideoInfoInitMode: Sendable {
struct VideoInfoView: View {
@Environment(\.appEnvironment) private var appEnvironment
@Environment(\.presentAppSheet) private var presentAppSheet
@Environment(\.videoQueueContext) private var videoQueueContext
private let initMode: VideoInfoInitMode
@@ -45,7 +46,6 @@ struct VideoInfoView: View {
@State private var isBookmarked = false
@State private var showingErrorDetailsSheet = false
@State private var showingPlaylistSheet = false
@State private var showingCommentsSheet = false
@State private var showingRemoveBookmarkAlert = false
@State private var currentBookmark: Bookmark?
@@ -102,7 +102,6 @@ struct VideoInfoView: View {
// Download state
@State private var download: Download?
@State private var showingDownloadSheet = false
@State private var isEnqueuingDownload = false
@State private var showingRemoveDownloadConfirmation = false
@@ -394,8 +393,6 @@ struct VideoInfoView: View {
// Reset state when navigating to different video
showingCommentsSheet = false
showingPlaylistSheet = false
showingDownloadSheet = false
showingRemoveBookmarkAlert = false
bookmarkSaveTask?.cancel()
comments = []
@@ -441,11 +438,6 @@ struct VideoInfoView: View {
await loadVideoDetails()
}
}
.sheet(isPresented: $showingPlaylistSheet) {
if let video = displayedVideo {
PlaylistSelectorSheet(video: video)
}
}
#if !os(tvOS)
.sheet(isPresented: $showingErrorDetailsSheet) {
ErrorDetailsSheet(errorMessage: videoDetailsLoadError ?? initialVideoLoadError ?? "Unknown error")
@@ -469,11 +461,6 @@ struct VideoInfoView: View {
)
}
#if !os(tvOS)
.sheet(isPresented: $showingDownloadSheet) {
if let video = displayedVideo {
DownloadQualitySheet(video: video)
}
}
.onChange(of: downloadManager?.completedDownloads) { _, newValue in
// Update download state when completedDownloads changes
if let video = displayedVideo {
@@ -726,7 +713,7 @@ struct VideoInfoView: View {
.focused($isPlayFocused)
Button {
showingPlaylistSheet = true
presentAddToPlaylist()
} label: {
Label(String(localized: "video.context.addToPlaylist"), systemImage: "text.badge.plus")
.frame(maxWidth: .infinity, minHeight: 50)
@@ -1326,7 +1313,7 @@ struct VideoInfoView: View {
// Add to Playlist and Bookmark
HStack(spacing: 12) {
Button {
showingPlaylistSheet = true
presentAddToPlaylist()
} label: {
Label(String(localized: "video.context.addToPlaylist"), systemImage: "text.badge.plus")
.frame(maxWidth: .infinity)
@@ -1409,7 +1396,7 @@ struct VideoInfoView: View {
}
case .addToPlaylist:
Button {
showingPlaylistSheet = true
presentAddToPlaylist()
} label: {
Label(String(localized: "video.context.addToPlaylist"), systemImage: "text.badge.plus")
}
@@ -1565,7 +1552,7 @@ struct VideoInfoView: View {
/// Starts a download either automatically or by showing the quality sheet.
private func startDownload(for video: Video) {
guard let appEnvironment else {
showingDownloadSheet = true
presentAppSheet(.downloadOptions(video))
return
}
@@ -1627,7 +1614,7 @@ struct VideoInfoView: View {
}
}
} else {
showingDownloadSheet = true
presentAppSheet(.downloadOptions(video))
}
}
@@ -2264,6 +2251,11 @@ struct VideoInfoView: View {
// MARK: - Actions
private func presentAddToPlaylist() {
guard let video = displayedVideo else { return }
presentAppSheet(.addToPlaylist(video))
}
private func toggleBookmark() {
guard let dataManager, let video = displayedVideo else { return }