Improve cell height calculation

This commit is contained in:
Arkadiusz Fal 2021-11-07 23:27:09 +01:00
parent 08d2165bf3
commit 76939e8a19
2 changed files with 15 additions and 9 deletions

View File

@ -4,6 +4,8 @@ import SwiftUI
struct HorizontalCells: View { struct HorizontalCells: View {
var items = [ContentItem]() var items = [ContentItem]()
@Default(.channelOnThumbnail) private var channelOnThumbnail
var body: some View { var body: some View {
ScrollView(.horizontal, showsIndicators: false) { ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 20) { LazyHStack(spacing: 20) {
@ -27,14 +29,17 @@ struct HorizontalCells: View {
.padding(.vertical, 10) .padding(.vertical, 10)
#endif #endif
} }
#if os(tvOS) .frame(height: cellHeight)
.frame(height: 560)
#else
.frame(height: 290)
#endif
.edgesIgnoringSafeArea(.horizontal) .edgesIgnoringSafeArea(.horizontal)
} }
var cellHeight: Double {
#if os(tvOS)
560
#else
290 - (channelOnThumbnail ? 23 : 0)
#endif
}
} }
struct HorizontalCells_Previews: PreviewProvider { struct HorizontalCells_Previews: PreviewProvider {

View File

@ -168,13 +168,14 @@ struct VideoCell: View {
.padding(.bottom, 6) .padding(.bottom, 6)
} }
} }
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
} }
#if os(tvOS) #if os(tvOS)
.frame(minHeight: channelOnThumbnail ? 80 : 120, alignment: .top) .frame(minHeight: channelOnThumbnail ? 80 : 120, alignment: .top)
#elseif os(macOS) #elseif os(macOS)
.frame(minHeight: 60, alignment: .top) .frame(minHeight: 35, alignment: .top)
#else #else
.frame(minHeight: 80, alignment: .top) .frame(minHeight: 50, alignment: .top)
#endif #endif
.padding(.bottom, 4) .padding(.bottom, 4)
@ -315,7 +316,7 @@ struct VideoCell_Preview: PreviewProvider {
VideoCell(video: Video.fixture) VideoCell(video: Video.fixture)
} }
#if os(macOS) #if os(macOS)
.frame(maxWidth: 600, maxHeight: 400) .frame(maxWidth: 300, maxHeight: 250)
#elseif os(iOS) #elseif os(iOS)
.frame(maxWidth: 300, maxHeight: 200) .frame(maxWidth: 300, maxHeight: 200)
#endif #endif