Files
yattee/Shared/Videos/HorizontalCells.swift
Arkadiusz Fal a0a54bced9 Improve layout stability and disable unwanted animations
Added height reservation to FavoriteItemView to prevent layout shifts during content loading. Changed HomeView to use LazyVStack for better performance. Converted QueueView from LazyVStack to VStack. Disabled animations on content count changes across multiple views to prevent jarring layout transitions. Added width constraint to stream button in PlaybackSettings.
2025-11-14 20:02:07 +01:00

66 lines
2.0 KiB
Swift

import Defaults
import SwiftUI
struct HorizontalCells: View {
var items = [ContentItem]()
@Environment(\.loadMoreContentHandler) private var loadMoreContentHandler
@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)
.edgesIgnoringSafeArea(.horizontal)
.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 HorizontalCells_Previews: PreviewProvider {
static var previews: some View {
HorizontalCells(items: ContentItem.array(of: Video.allFixtures))
.injectFixtureEnvironmentObjects()
}
}