mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Fix scrolling view on resource change
This commit is contained in:
parent
e270b7b213
commit
3a37ea656a
@ -33,7 +33,7 @@
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "37D4B0D32671614900C925CA"
|
||||
BuildableName = "Tests iOS.xctest"
|
||||
BuildableName = "Tests (iOS).xctest"
|
||||
BlueprintName = "Tests (iOS)"
|
||||
ReferencedContainer = "container:Pearvidious.xcodeproj">
|
||||
</BuildableReference>
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user