Make info panel chapter and related sections collapsible

Section headers in the inline info panel now toggle their content with a
rotating chevron. Collapsed state resets when the video changes. Also let
the collapsed description text take full width.
This commit is contained in:
Arkadiusz Fal
2026-09-24 19:00:27 +02:00
parent ed2884d7ec
commit 7f672d2c57

View File

@@ -31,6 +31,8 @@ struct InfoPanelPage: View {
@State private var showFormattedDate = false @State private var showFormattedDate = false
@State private var showOriginalTitle = false @State private var showOriginalTitle = false
@State private var isDescriptionExpanded = false @State private var isDescriptionExpanded = false
@State private var isChaptersCollapsed = false
@State private var isRelatedCollapsed = false
private var appEnvironment: AppEnvironment? { context.appEnvironment } private var appEnvironment: AppEnvironment? { context.appEnvironment }
private var video: Video { context.video } private var video: Video { context.video }
@@ -76,6 +78,8 @@ struct InfoPanelPage: View {
.onChange(of: video.id) { _, _ in .onChange(of: video.id) { _, _ in
showOriginalTitle = false showOriginalTitle = false
isDescriptionExpanded = false isDescriptionExpanded = false
isChaptersCollapsed = false
isRelatedCollapsed = false
} }
.task(id: context.video.id) { .task(id: context.video.id) {
if inlineSections { if inlineSections {
@@ -180,6 +184,7 @@ struct InfoPanelPage: View {
.foregroundStyle(.secondary) .foregroundStyle(.secondary)
.tint(context.accentColor) .tint(context.accentColor)
.lineLimit(isDescriptionExpanded ? nil : 3) .lineLimit(isDescriptionExpanded ? nil : 3)
.frame(maxWidth: .infinity, alignment: .leading)
.handleTimestampLinks(using: playerService) .handleTimestampLinks(using: playerService)
// Collapsed: let the container tap win over link taps // Collapsed: let the container tap win over link taps
.allowsHitTesting(isDescriptionExpanded) .allowsHitTesting(isDescriptionExpanded)
@@ -233,14 +238,31 @@ struct InfoPanelPage: View {
private var storyboard: Storyboard? { playerState?.preferredStoryboard } private var storyboard: Storyboard? { playerState?.preferredStoryboard }
private var relatedVideos: [Video] { video.relatedVideos ?? [] } private var relatedVideos: [Video] { video.relatedVideos ?? [] }
/// Section header that toggles the section's collapsed state on tap.
@ViewBuilder @ViewBuilder
private func sectionHeader(_ title: String) -> some View { private func sectionHeader(_ title: String, isCollapsed: Binding<Bool>) -> some View {
Text(title) Button {
.font(.headline) withAnimation(.easeInOut(duration: 0.2)) {
isCollapsed.wrappedValue.toggle()
}
} label: {
HStack(spacing: 6) {
Text(title)
.font(.headline)
Image(systemName: "chevron.down")
.font(.caption.weight(.semibold))
.foregroundStyle(.secondary)
.rotationEffect(.degrees(isCollapsed.wrappedValue ? -90 : 0))
Spacer(minLength: 0)
}
.padding(.horizontal) .padding(.horizontal)
.padding(.top, 4) .padding(.top, 4)
.padding(.bottom, 8) .padding(.bottom, 8)
.frame(maxWidth: .infinity, alignment: .leading) .contentShape(Rectangle())
}
.buttonStyle(.plain)
} }
@ViewBuilder @ViewBuilder
@@ -250,24 +272,26 @@ struct InfoPanelPage: View {
.padding(.horizontal) .padding(.horizontal)
.padding(.bottom, 8) .padding(.bottom, 8)
sectionHeader(String(localized: "player.chapters")) sectionHeader(String(localized: "player.chapters"), isCollapsed: $isChaptersCollapsed)
LazyVStack(spacing: 0) { if !isChaptersCollapsed {
ForEach(chapters) { chapter in LazyVStack(spacing: 0) {
ChapterRow( ForEach(chapters) { chapter in
chapter: chapter, ChapterRow(
isActive: isChapterActive(chapter), chapter: chapter,
storyboard: storyboard, isActive: isChapterActive(chapter),
showThumbnail: true, storyboard: storyboard,
onTap: { showThumbnail: true,
Task { onTap: {
await playerService?.seek(to: chapter.startTime) Task {
await playerService?.seek(to: chapter.startTime)
}
} }
} )
) }
} }
.padding(.horizontal)
} }
.padding(.horizontal)
} }
} }
@@ -278,31 +302,33 @@ struct InfoPanelPage: View {
.padding(.horizontal) .padding(.horizontal)
.padding(.vertical, 8) .padding(.vertical, 8)
sectionHeader(String(localized: "videoInfo.section.relatedVideos")) sectionHeader(String(localized: "videoInfo.section.relatedVideos"), isCollapsed: $isRelatedCollapsed)
LazyVStack(spacing: 12) { if !isRelatedCollapsed {
ForEach(Array(relatedVideos.enumerated()), id: \.element.id) { index, relatedVideo in LazyVStack(spacing: 12) {
VideoRowView( ForEach(Array(relatedVideos.enumerated()), id: \.element.id) { index, relatedVideo in
video: relatedVideo, VideoRowView(
style: .regular, video: relatedVideo,
showThumbnail: true style: .regular,
) showThumbnail: true
.tappableVideo( )
relatedVideo, .tappableVideo(
queueSource: .manual, relatedVideo,
sourceLabel: String(localized: "videoInfo.section.relatedVideos"), queueSource: .manual,
videoList: relatedVideos, sourceLabel: String(localized: "videoInfo.section.relatedVideos"),
videoIndex: index, videoList: relatedVideos,
loadMoreVideos: nil videoIndex: index,
) loadMoreVideos: nil
)
if index < relatedVideos.count - 1 { if index < relatedVideos.count - 1 {
Divider() Divider()
.padding(.leading, VideoRowStyle.regular.thumbnailWidth + 12) .padding(.leading, VideoRowStyle.regular.thumbnailWidth + 12)
}
} }
} }
.padding(.horizontal)
} }
.padding(.horizontal)
} }
} }