Jump panel pages to the top and clear stale chapters when the video changes

Tapping a related video kept the panel scrolled where it was, so the new
title was out of view, and the chapters section kept showing the previous
video's chapters until the new ones resolved.

The scroll config now carries the video identity and the shared page
scroll view scrolls to the top (without animation, resetting the reported
offset) whenever it changes. PlayerState.setCurrentVideo clears chapters
on a video id change, alongside comments and storyboards.
This commit is contained in:
Arkadiusz Fal
2026-09-25 21:44:43 +02:00
parent f6ba35c1f5
commit 5af052b428
3 changed files with 25 additions and 0 deletions

View File

@@ -483,6 +483,9 @@ final class PlayerState {
commentsContinuation = nil
// Reset storyboards to prevent previous video's storyboards from appearing
storyboards = []
// Reset chapters so the panel doesn't show the previous video's
// chapters while the new one loads
chapters = []
}
currentVideo = video
currentStream = stream

View File

@@ -38,6 +38,11 @@ struct PanelScrollConfig {
/// Toggling this scrolls the page back to the top.
var scrollToTopTrigger: Bool = false
/// Identity of the content being shown (the video). When it changes the
/// page jumps back to the top without animation so the new title is
/// visible. Set by `PlayerPanelContentView`.
var contentID: AnyHashable?
/// Disables scrolling (while the portrait drag handle is active).
var isScrollDisabled: Bool = false
@@ -163,6 +168,14 @@ struct PanelPageScrollView<Content: View>: View {
proxy.scrollTo("panelPageTop", anchor: .top)
}
}
.onChange(of: config.contentID) { _, _ in
var transaction = Transaction()
transaction.disablesAnimations = true
withTransaction(transaction) {
proxy.scrollTo("panelPageTop", anchor: .top)
}
config.scrollOffsetChanged?(0)
}
}
}
}

View File

@@ -159,8 +159,17 @@ struct PlayerPanelContentView: View {
case .info:
InfoPanelPage(
context: context,
/// The host's scroll config keyed to the current video so pages jump to
/// the top when the video changes.
private var pageScrollConfig: PanelScrollConfig {
var config = scrollConfig
config.contentID = AnyHashable(context.video.id)
return config
}
settings: page.infoSettings,
scrollConfig: scrollConfig,
let scrollConfig = pageScrollConfig
inlineSections: inlineInfoSections
)
.id(PanelPageType.info)