2021-08-02 04:31:24 +05:30
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
2021-10-22 04:59:10 +05:30
|
|
|
struct VerticalCells: View {
|
2021-08-02 04:31:24 +05:30
|
|
|
#if os(iOS)
|
|
|
|
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
|
|
|
#endif
|
|
|
|
|
2021-10-22 04:59:10 +05:30
|
|
|
var items = [ContentItem]()
|
2021-08-02 04:31:24 +05:30
|
|
|
|
|
|
|
var body: some View {
|
2021-09-30 22:23:26 +05:30
|
|
|
ScrollView(.vertical, showsIndicators: scrollViewShowsIndicators) {
|
2021-10-22 04:59:10 +05:30
|
|
|
LazyVGrid(columns: columns, alignment: .center) {
|
|
|
|
ForEach(items.sorted { $0 < $1 }) { item in
|
|
|
|
ContentItemView(item: item)
|
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-10-23 22:19:45 +05:30
|
|
|
.id(items.map(\.id).joined())
|
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
|
|
|
}
|
|
|
|
|
2021-10-22 04:59:10 +05:30
|
|
|
var columns: [GridItem] {
|
2021-08-03 02:40:22 +05:30
|
|
|
#if os(tvOS)
|
2021-10-22 04:59:10 +05:30
|
|
|
items.count < 3 ? Array(repeating: GridItem(.fixed(540)), count: [items.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-10-23 22:19:45 +05:30
|
|
|
struct VeticalCells_Previews: PreviewProvider {
|
2021-08-02 04:31:24 +05:30
|
|
|
static var previews: some View {
|
2021-10-22 04:59:10 +05:30
|
|
|
VerticalCells(items: ContentItem.array(of: Video.allFixtures))
|
2021-09-29 17:15:00 +05:30
|
|
|
.injectFixtureEnvironmentObjects()
|
2021-08-02 04:31:24 +05:30
|
|
|
}
|
|
|
|
}
|