// // Swiftfin is subject to the terms of the Mozilla Public // License, v2.0. If a copy of the MPL was not distributed with this // file, you can obtain one at https://mozilla.org/MPL/2.0/. // // Copyright (c) 2026 Jellyfin & Jellyfin Contributors // // Adapted for Tunavelo from Swiftfin 8a515c580e8b96eaeffcecdfeb14a1c97ef9264e Swiftfin tvOS/Components/CinematicItemSelector.swift // // Our changes (MPL-2.0 section 3.3): `JellyfinAPI` posters are a generic `Item` with an image address; `FadeContentTransitionView` and // `ImageView` are NukeUI's `LazyImage` with an opacity transition; `CinematicContentGroupContainer` is a plain `VStack`; `mask(gradient:)` // is a `LinearGradient` mask; the poster row is dropped (Home B shows one large poster, no carousel); the parent frame is a parameter. // #if os(tvOS) import DesignSystem import NukeUI import SwiftUI /// Apple TV: the selected item's picture fades in behind the content above it, which is shown for the item the focus is on. Home B /// gives it one item, so the poster is the item and the focus stays on its Play button. struct CinematicItemSelector: View { @FocusState private var isSectionFocused @State private var selectedItem: Item? private let items: [Item] private let height: CGFloat private let imageURL: (Item) -> URL? private let topContent: (Item) -> TopContent init( items: [Item], height: CGFloat, imageURL: @escaping (Item) -> URL?, @ViewBuilder topContent: @escaping (Item) -> TopContent ) { self.items = items self.height = height self.imageURL = imageURL self.topContent = topContent } private var resolvedItem: Item? { selectedItem ?? items.first } var body: some View { VStack(alignment: .leading, spacing: Theme.Spacing.s) { if let resolvedItem { topContent(resolvedItem) .id(resolvedItem.hashValue) .transition(.opacity) } } .frame(maxWidth: .infinity, minHeight: height, alignment: .bottomLeading) .background(alignment: .top) { LazyImage(url: resolvedItem.flatMap(imageURL)) { state in if let image = state.image { image.resizable().aspectRatio(contentMode: .fill) } } .id(resolvedItem?.hashValue) .transition(.opacity) .overlay { LinearGradient( stops: [.init(color: Theme.black.color.opacity(0), location: 0.5), .init(color: Theme.black.color.opacity(0.4), location: 0.6), .init(color: Theme.black.color, location: 1)], startPoint: .top, endPoint: .bottom ) } .frame(height: height) .clipped() } .animation(.easeInOut(duration: 0.3), value: resolvedItem?.hashValue) .onChange(of: isSectionFocused) { if isSectionFocused, selectedItem == nil { selectedItem = items.first } } .focusSection() .focused($isSectionFocused) } } #endif