yattee/Shared/Videos/VideosCellsHorizontal.swift

67 lines
2.0 KiB
Swift
Raw Normal View History

2021-09-18 20:36:42 +00:00
import Defaults
import SwiftUI
struct VideosCellsHorizontal: View {
#if os(iOS)
@Environment(\.verticalSizeClass) private var verticalSizeClass
#endif
var videos = [Video]()
var body: some View {
ScrollViewReader { scrollView in
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 20) {
ForEach(videos) { video in
2021-09-26 22:28:42 +00:00
VideoView(video: video)
2021-09-18 20:36:42 +00:00
.environment(\.horizontalCells, true)
#if os(tvOS)
.frame(width: 580)
.padding(.trailing, 20)
.padding(.bottom, 40)
#else
2021-09-25 08:18:22 +00:00
.frame(width: 300)
2021-09-18 20:36:42 +00:00
#endif
}
}
#if os(tvOS)
.padding(.horizontal, 40)
.padding(.vertical, 30)
#else
.padding(.horizontal, 15)
.padding(.vertical, 20)
#endif
}
2021-09-25 08:18:22 +00:00
.onAppear {
if let video = videos.first {
scrollView.scrollTo(video.id, anchor: .leading)
}
}
2021-09-18 20:36:42 +00:00
.onChange(of: videos) { [videos] newVideos in
#if !os(tvOS)
guard !videos.isEmpty, let video = newVideos.first else {
return
}
scrollView.scrollTo(video.id, anchor: .leading)
#endif
}
}
#if os(tvOS)
.frame(height: 560)
#else
2021-09-25 08:18:22 +00:00
.frame(height: 280)
2021-09-18 20:36:42 +00:00
#endif
.edgesIgnoringSafeArea(.horizontal)
}
}
struct VideoCellsHorizontal_Previews: PreviewProvider {
static var previews: some View {
VideosCellsHorizontal(videos: Video.allFixtures)
2021-09-25 08:18:22 +00:00
.environmentObject(NavigationModel())
.environmentObject(SubscriptionsModel())
2021-09-18 20:36:42 +00:00
}
}