2021-09-19 02:06:42 +05:30
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
2021-10-22 04:59:10 +05:30
|
|
|
struct HorizontalCells: View {
|
|
|
|
var items = [ContentItem]()
|
2021-09-19 02:06:42 +05:30
|
|
|
|
2022-01-05 04:48:01 +05:30
|
|
|
@Environment(\.loadMoreContentHandler) private var loadMoreContentHandler
|
|
|
|
|
2021-11-08 03:57:09 +05:30
|
|
|
@Default(.channelOnThumbnail) private var channelOnThumbnail
|
|
|
|
|
2021-09-19 02:06:42 +05:30
|
|
|
var body: some View {
|
2021-09-30 22:23:26 +05:30
|
|
|
ScrollView(.horizontal, showsIndicators: false) {
|
|
|
|
LazyHStack(spacing: 20) {
|
2022-03-27 16:19:57 +05:30
|
|
|
ForEach(contentItems) { item in
|
2021-10-22 04:59:10 +05:30
|
|
|
ContentItemView(item: item)
|
2021-09-30 22:23:26 +05:30
|
|
|
.environment(\.horizontalCells, true)
|
2022-01-05 04:48:01 +05:30
|
|
|
.onAppear { loadMoreContentItemsIfNeeded(current: item) }
|
2021-09-30 22:23:26 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.frame(width: 580)
|
|
|
|
.padding(.trailing, 20)
|
|
|
|
.padding(.bottom, 40)
|
|
|
|
#else
|
2021-11-06 02:23:43 +05:30
|
|
|
.frame(width: 295)
|
2021-09-30 22:23:26 +05:30
|
|
|
#endif
|
2021-09-30 04:59:18 +05:30
|
|
|
}
|
2021-09-19 02:06:42 +05:30
|
|
|
}
|
2021-09-30 22:23:26 +05:30
|
|
|
#if os(tvOS)
|
2021-11-08 21:59:35 +05:30
|
|
|
.padding(.horizontal, 40)
|
|
|
|
.padding(.vertical, 30)
|
2021-09-30 22:23:26 +05:30
|
|
|
#else
|
2021-11-08 21:59:35 +05:30
|
|
|
.padding(.horizontal, 15)
|
|
|
|
.padding(.vertical, 10)
|
2021-09-30 22:23:26 +05:30
|
|
|
#endif
|
2021-09-19 02:06:42 +05:30
|
|
|
}
|
2021-11-08 03:57:09 +05:30
|
|
|
.frame(height: cellHeight)
|
|
|
|
.edgesIgnoringSafeArea(.horizontal)
|
|
|
|
}
|
|
|
|
|
2022-03-27 16:19:57 +05:30
|
|
|
var contentItems: [ContentItem] {
|
2022-12-14 21:50:24 +05:30
|
|
|
items.isEmpty ? ContentItem.placeholders : items
|
2022-03-27 16:19:57 +05:30
|
|
|
}
|
|
|
|
|
2022-01-05 04:48:01 +05:30
|
|
|
func loadMoreContentItemsIfNeeded(current item: ContentItem) {
|
|
|
|
let thresholdIndex = items.index(items.endIndex, offsetBy: -5)
|
|
|
|
if items.firstIndex(where: { $0.id == item.id }) == thresholdIndex {
|
|
|
|
loadMoreContentHandler()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-08 03:57:09 +05:30
|
|
|
var cellHeight: Double {
|
2021-09-19 02:06:42 +05:30
|
|
|
#if os(tvOS)
|
2022-12-16 04:29:35 +05:30
|
|
|
600
|
2021-09-19 02:06:42 +05:30
|
|
|
#else
|
2021-11-08 03:57:09 +05:30
|
|
|
290 - (channelOnThumbnail ? 23 : 0)
|
2021-09-19 02:06:42 +05:30
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-22 04:59:10 +05:30
|
|
|
struct HorizontalCells_Previews: PreviewProvider {
|
2021-09-19 02:06:42 +05:30
|
|
|
static var previews: some View {
|
2021-10-22 04:59:10 +05:30
|
|
|
HorizontalCells(items: ContentItem.array(of: Video.allFixtures))
|
2021-09-29 17:15:00 +05:30
|
|
|
.injectFixtureEnvironmentObjects()
|
2021-09-19 02:06:42 +05:30
|
|
|
}
|
|
|
|
}
|