mirror of
https://github.com/yattee/yattee.git
synced 2026-10-24 05:32:53 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user