2021-08-01 23:01:24 +00:00
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
2021-10-21 23:29:10 +00:00
|
|
|
struct VerticalCells: View {
|
2021-08-01 23:01:24 +00:00
|
|
|
#if os(iOS)
|
|
|
|
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
|
|
|
#endif
|
|
|
|
|
2021-10-21 23:29:10 +00:00
|
|
|
var items = [ContentItem]()
|
2021-08-01 23:01:24 +00:00
|
|
|
|
|
|
|
var body: some View {
|
2021-09-30 16:53:26 +00:00
|
|
|
ScrollView(.vertical, showsIndicators: scrollViewShowsIndicators) {
|
2021-10-21 23:29:10 +00:00
|
|
|
LazyVGrid(columns: columns, alignment: .center) {
|
|
|
|
ForEach(items.sorted { $0 < $1 }) { item in
|
|
|
|
ContentItemView(item: item)
|
2021-09-29 23:29:18 +00:00
|
|
|
}
|
2021-08-01 23:01:24 +00:00
|
|
|
}
|
2021-09-30 16:53:26 +00:00
|
|
|
.padding()
|
2021-08-01 23:01:24 +00:00
|
|
|
}
|
2021-09-30 16:53:26 +00:00
|
|
|
.id(UUID())
|
2021-08-02 21:10:22 +00:00
|
|
|
.edgesIgnoringSafeArea(.horizontal)
|
2021-09-26 22:28:42 +00:00
|
|
|
#if os(macOS)
|
|
|
|
.background()
|
|
|
|
.frame(minWidth: 360)
|
|
|
|
#endif
|
2021-08-01 23:01:24 +00:00
|
|
|
}
|
|
|
|
|
2021-10-21 23:29:10 +00:00
|
|
|
var columns: [GridItem] {
|
2021-08-02 21:10:22 +00:00
|
|
|
#if os(tvOS)
|
2021-10-21 23:29:10 +00:00
|
|
|
items.count < 3 ? Array(repeating: GridItem(.fixed(540)), count: [items.count, 1].max()!) : adaptiveItem
|
2021-08-02 21:10:22 +00:00
|
|
|
#else
|
|
|
|
adaptiveItem
|
|
|
|
#endif
|
2021-08-01 23:01:24 +00:00
|
|
|
}
|
|
|
|
|
2021-08-02 21:10:22 +00:00
|
|
|
var adaptiveItem: [GridItem] {
|
|
|
|
[GridItem(.adaptive(minimum: adaptiveGridItemMinimumSize))]
|
2021-08-01 23:01:24 +00:00
|
|
|
}
|
|
|
|
|
2021-09-18 20:36:42 +00:00
|
|
|
var adaptiveGridItemMinimumSize: Double {
|
2021-08-01 23:01:24 +00:00
|
|
|
#if os(iOS)
|
2021-08-16 13:39:31 +00:00
|
|
|
return verticalSizeClass == .regular ? 320 : 800
|
2021-08-01 23:01:24 +00:00
|
|
|
#elseif os(tvOS)
|
2021-08-02 21:10:22 +00:00
|
|
|
return 540
|
2021-08-01 23:01:24 +00:00
|
|
|
#else
|
2021-08-16 13:39:31 +00:00
|
|
|
return 320
|
2021-08-01 23:01:24 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
var scrollViewShowsIndicators: Bool {
|
|
|
|
#if !os(tvOS)
|
|
|
|
true
|
|
|
|
#else
|
|
|
|
false
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-26 22:28:42 +00:00
|
|
|
struct VideoCellsVertical_Previews: PreviewProvider {
|
2021-08-01 23:01:24 +00:00
|
|
|
static var previews: some View {
|
2021-10-21 23:29:10 +00:00
|
|
|
VerticalCells(items: ContentItem.array(of: Video.allFixtures))
|
2021-09-29 11:45:00 +00:00
|
|
|
.injectFixtureEnvironmentObjects()
|
2021-08-01 23:01:24 +00:00
|
|
|
}
|
|
|
|
}
|