Redraw cells on change of videos

This commit is contained in:
Arkadiusz Fal 2021-09-30 18:53:26 +02:00
parent 3a37ea656a
commit d6b3c6637d
3 changed files with 34 additions and 54 deletions

View File

@ -7,7 +7,7 @@
<key>Pearvidious (iOS).xcscheme_^#shared#^_</key> <key>Pearvidious (iOS).xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>2</integer> <integer>1</integer>
</dict> </dict>
<key>Pearvidious (macOS).xcscheme_^#shared#^_</key> <key>Pearvidious (macOS).xcscheme_^#shared#^_</key>
<dict> <dict>
@ -17,7 +17,7 @@
<key>Pearvidious (tvOS).xcscheme_^#shared#^_</key> <key>Pearvidious (tvOS).xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>1</integer> <integer>2</integer>
</dict> </dict>
<key>Periphery (iOS).xcscheme_^#shared#^_</key> <key>Periphery (iOS).xcscheme_^#shared#^_</key>
<dict> <dict>

View File

@ -9,39 +9,29 @@ struct VideosCellsHorizontal: View {
var videos = [Video]() var videos = [Video]()
var body: some View { var body: some View {
EmptyView().id("cellsTop") ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 20) {
ScrollViewReader { scrollView in ForEach(videos) { video in
ScrollView(.horizontal, showsIndicators: false) { VideoView(video: video)
LazyHStack(spacing: 20) { .environment(\.horizontalCells, true)
ForEach(videos) { video in #if os(tvOS)
VideoView(video: video) .frame(width: 580)
.environment(\.horizontalCells, true) .padding(.trailing, 20)
#if os(tvOS) .padding(.bottom, 40)
.frame(width: 580) #else
.padding(.trailing, 20) .frame(width: 300)
.padding(.bottom, 40) #endif
#else
.frame(width: 300)
#endif
}
} }
#if os(tvOS)
.padding(.horizontal, 40)
.padding(.vertical, 30)
#else
.padding(.horizontal, 15)
.padding(.vertical, 20)
#endif
}
.onChange(of: videos) { [videos] newVideos in
guard !videos.isEmpty else {
return
}
scrollView.scrollTo("cellsTop", anchor: .leading)
} }
#if os(tvOS)
.padding(.horizontal, 40)
.padding(.vertical, 30)
#else
.padding(.horizontal, 15)
.padding(.vertical, 20)
#endif
} }
.id(UUID())
#if os(tvOS) #if os(tvOS)
.frame(height: 560) .frame(height: 560)
#else #else

View File

@ -9,31 +9,21 @@ struct VideosCellsVertical: View {
var videos = [Video]() var videos = [Video]()
var body: some View { var body: some View {
EmptyView().id("cellsTop") ScrollView(.vertical, showsIndicators: scrollViewShowsIndicators) {
LazyVGrid(columns: items, alignment: .center) {
ScrollViewReader { scrollView in ForEach(videos) { video in
ScrollView(.vertical, showsIndicators: scrollViewShowsIndicators) { VideoView(video: video)
LazyVGrid(columns: items, alignment: .center) { #if os(tvOS)
ForEach(videos) { video in .padding(.horizontal)
VideoView(video: video) #endif
#if os(tvOS)
.padding(.horizontal)
#endif
}
} }
.padding()
} }
.onChange(of: videos) { [videos] newVideos in .padding()
guard !videos.isEmpty else {
return
}
scrollView.scrollTo("cellsTop", anchor: .top)
}
#if os(tvOS)
.padding(.horizontal, 10)
#endif
} }
.id(UUID())
#if os(tvOS)
.padding(.horizontal, 10)
#endif
.edgesIgnoringSafeArea(.horizontal) .edgesIgnoringSafeArea(.horizontal)
#if os(macOS) #if os(macOS)
.background() .background()