Files
yattee/Shared/Videos/HorizontalCells.swift
Arkadiusz Fal 1fc609057e Fix horizontal content extending behind sidebar on iPad
Modified HorizontalCells to conditionally apply edgesIgnoringSafeArea based on navigation style. In sidebar mode (iPad), content now respects safe areas and won't overlap with the sidebar. In tab mode (iPhone), content maintains full-width scrolling behavior.
2025-11-15 12:04:01 +01:00

79 lines
2.3 KiB
Swift

import Defaults
import SwiftUI
struct HorizontalCells: View {
var items = [ContentItem]()
@Environment(\.loadMoreContentHandler) private var loadMoreContentHandler
@Environment(\.navigationStyle) private var navigationStyle
@Default(.channelOnThumbnail) private var channelOnThumbnail
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 20) {
ForEach(contentItems) { item in
ContentItemView(item: item)
.environment(\.horizontalCells, true)
.onAppear { loadMoreContentItemsIfNeeded(current: item) }
#if os(tvOS)
.frame(width: 580)
.padding(.trailing, 20)
.padding(.bottom, 40)
#else
.frame(width: 295)
#endif
}
}
#if os(tvOS)
.padding(.horizontal, 40)
.padding(.vertical, 30)
#else
.padding(.horizontal, 15)
.padding(.vertical, 10)
#endif
}
.frame(height: cellHeight)
.modifier(ConditionalEdgeIgnoringSafeArea(navigationStyle: navigationStyle))
.animation(nil, value: contentItems.count)
}
var contentItems: [ContentItem] {
items.isEmpty ? ContentItem.placeholders : items
}
func loadMoreContentItemsIfNeeded(current item: ContentItem) {
let thresholdIndex = items.index(items.endIndex, offsetBy: -5)
if items.firstIndex(where: { $0.id == item.id }) == thresholdIndex {
loadMoreContentHandler()
}
}
var cellHeight: Double {
#if os(tvOS)
600
#else
290 - (channelOnThumbnail ? 23 : 0)
#endif
}
}
struct ConditionalEdgeIgnoringSafeArea: ViewModifier {
let navigationStyle: NavigationStyle
func body(content: Content) -> some View {
if navigationStyle == .tab {
content.edgesIgnoringSafeArea(.horizontal)
} else {
content
}
}
}
struct HorizontalCells_Previews: PreviewProvider {
static var previews: some View {
HorizontalCells(items: ContentItem.array(of: Video.allFixtures))
.injectFixtureEnvironmentObjects()
}
}