1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 06:10:32 +05:30
yattee/Shared/Videos/VideosCellsVertical.swift

71 lines
1.7 KiB
Swift
Raw Normal View History

2021-08-02 04:31:24 +05:30
import Defaults
import SwiftUI
2021-09-19 02:06:42 +05:30
struct VideosCellsVertical: View {
2021-08-02 04:31:24 +05:30
#if os(iOS)
@Environment(\.verticalSizeClass) private var verticalSizeClass
#endif
var videos = [Video]()
var body: some View {
2021-09-30 22:23:26 +05:30
ScrollView(.vertical, showsIndicators: scrollViewShowsIndicators) {
LazyVGrid(columns: items, alignment: .center) {
ForEach(videos) { video in
VideoView(video: video)
#if os(tvOS)
.padding(.horizontal)
#endif
2021-09-30 04:59:18 +05:30
}
2021-08-02 04:31:24 +05:30
}
2021-09-30 22:23:26 +05:30
.padding()
2021-08-02 04:31:24 +05:30
}
2021-09-30 22:23:26 +05:30
.id(UUID())
#if os(tvOS)
.padding(.horizontal, 10)
#endif
2021-08-03 02:40:22 +05:30
.edgesIgnoringSafeArea(.horizontal)
2021-09-27 03:58:42 +05:30
#if os(macOS)
.background()
.frame(minWidth: 360)
#endif
2021-08-02 04:31:24 +05:30
}
var items: [GridItem] {
2021-08-03 02:40:22 +05:30
#if os(tvOS)
videos.count < 3 ? Array(repeating: GridItem(.fixed(540)), count: [videos.count, 1].max()!) : adaptiveItem
2021-08-03 02:40:22 +05:30
#else
adaptiveItem
#endif
2021-08-02 04:31:24 +05:30
}
2021-08-03 02:40:22 +05:30
var adaptiveItem: [GridItem] {
[GridItem(.adaptive(minimum: adaptiveGridItemMinimumSize))]
2021-08-02 04:31:24 +05:30
}
2021-09-19 02:06:42 +05:30
var adaptiveGridItemMinimumSize: Double {
2021-08-02 04:31:24 +05:30
#if os(iOS)
2021-08-16 19:09:31 +05:30
return verticalSizeClass == .regular ? 320 : 800
2021-08-02 04:31:24 +05:30
#elseif os(tvOS)
2021-08-03 02:40:22 +05:30
return 540
2021-08-02 04:31:24 +05:30
#else
2021-08-16 19:09:31 +05:30
return 320
2021-08-02 04:31:24 +05:30
#endif
}
var scrollViewShowsIndicators: Bool {
#if !os(tvOS)
true
#else
false
#endif
}
}
2021-09-27 03:58:42 +05:30
struct VideoCellsVertical_Previews: PreviewProvider {
2021-08-02 04:31:24 +05:30
static var previews: some View {
2021-09-27 03:58:42 +05:30
VideosCellsVertical(videos: Video.allFixtures)
2021-09-29 17:15:00 +05:30
.injectFixtureEnvironmentObjects()
2021-08-02 04:31:24 +05:30
}
}