1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30
yattee/Shared/Videos/VideosCellsHorizontal.swift

61 lines
1.7 KiB
Swift
Raw Normal View History

2021-09-19 02:06:42 +05:30
import Defaults
import SwiftUI
struct VideosCellsHorizontal: View {
#if os(iOS)
@Environment(\.verticalSizeClass) private var verticalSizeClass
#endif
var videos = [Video]()
var body: some View {
2021-09-30 04:59:18 +05:30
EmptyView().id("cellsTop")
2021-09-19 02:06:42 +05:30
ScrollViewReader { scrollView in
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 20) {
ForEach(videos) { video in
2021-09-27 03:58:42 +05:30
VideoView(video: video)
2021-09-19 02:06:42 +05:30
.environment(\.horizontalCells, true)
#if os(tvOS)
.frame(width: 580)
.padding(.trailing, 20)
.padding(.bottom, 40)
#else
2021-09-25 13:48:22 +05:30
.frame(width: 300)
2021-09-19 02:06:42 +05:30
#endif
}
}
#if os(tvOS)
.padding(.horizontal, 40)
.padding(.vertical, 30)
#else
.padding(.horizontal, 15)
.padding(.vertical, 20)
#endif
}
.onChange(of: videos) { [videos] newVideos in
2021-09-30 04:59:18 +05:30
guard !videos.isEmpty else {
return
}
2021-09-19 02:06:42 +05:30
2021-09-30 04:59:18 +05:30
scrollView.scrollTo("cellsTop", anchor: .leading)
2021-09-19 02:06:42 +05:30
}
}
#if os(tvOS)
.frame(height: 560)
#else
2021-09-25 13:48:22 +05:30
.frame(height: 280)
2021-09-19 02:06:42 +05:30
#endif
.edgesIgnoringSafeArea(.horizontal)
}
}
struct VideoCellsHorizontal_Previews: PreviewProvider {
static var previews: some View {
VideosCellsHorizontal(videos: Video.allFixtures)
2021-09-29 17:15:00 +05:30
.injectFixtureEnvironmentObjects()
2021-09-19 02:06:42 +05:30
}
}