mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Fix scrolling view on resource change
This commit is contained in:
@@ -9,6 +9,8 @@ struct VideosCellsHorizontal: View {
|
||||
var videos = [Video]()
|
||||
|
||||
var body: some View {
|
||||
EmptyView().id("cellsTop")
|
||||
|
||||
ScrollViewReader { scrollView in
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
LazyHStack(spacing: 20) {
|
||||
@@ -32,19 +34,12 @@ struct VideosCellsHorizontal: View {
|
||||
.padding(.vertical, 20)
|
||||
#endif
|
||||
}
|
||||
.onAppear {
|
||||
if let video = videos.first {
|
||||
scrollView.scrollTo(video.id, anchor: .leading)
|
||||
}
|
||||
}
|
||||
.onChange(of: videos) { [videos] newVideos in
|
||||
#if !os(tvOS)
|
||||
guard !videos.isEmpty, let video = newVideos.first else {
|
||||
return
|
||||
}
|
||||
guard !videos.isEmpty else {
|
||||
return
|
||||
}
|
||||
|
||||
scrollView.scrollTo(video.id, anchor: .leading)
|
||||
#endif
|
||||
scrollView.scrollTo("cellsTop", anchor: .leading)
|
||||
}
|
||||
}
|
||||
#if os(tvOS)
|
||||
|
@@ -9,6 +9,8 @@ struct VideosCellsVertical: View {
|
||||
var videos = [Video]()
|
||||
|
||||
var body: some View {
|
||||
EmptyView().id("cellsTop")
|
||||
|
||||
ScrollViewReader { scrollView in
|
||||
ScrollView(.vertical, showsIndicators: scrollViewShowsIndicators) {
|
||||
LazyVGrid(columns: items, alignment: .center) {
|
||||
@@ -22,13 +24,11 @@ struct VideosCellsVertical: View {
|
||||
.padding()
|
||||
}
|
||||
.onChange(of: videos) { [videos] newVideos in
|
||||
#if !os(tvOS)
|
||||
guard !videos.isEmpty, let video = newVideos.first else {
|
||||
return
|
||||
}
|
||||
guard !videos.isEmpty else {
|
||||
return
|
||||
}
|
||||
|
||||
scrollView.scrollTo(video.id, anchor: .top)
|
||||
#endif
|
||||
scrollView.scrollTo("cellsTop", anchor: .top)
|
||||
}
|
||||
#if os(tvOS)
|
||||
.padding(.horizontal, 10)
|
||||
|
Reference in New Issue
Block a user