jellyflood/Swiftfin tvOS/Components/PortraitItemsRowView.swift

71 lines
2.0 KiB
Swift

//
// 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) 2022 Jellyfin & Jellyfin Contributors
//
import JellyfinAPI
import SwiftUI
struct PortraitItemsRowView: View {
@EnvironmentObject
var itemRouter: ItemCoordinator.Router
let rowTitle: String
let items: [BaseItemDto]
let showItemTitles: Bool
let selectedAction: (BaseItemDto) -> Void
init(
rowTitle: String,
items: [BaseItemDto],
showItemTitles: Bool = true,
selectedAction: @escaping (BaseItemDto) -> Void
) {
self.rowTitle = rowTitle
self.items = items
self.showItemTitles = showItemTitles
self.selectedAction = selectedAction
}
var body: some View {
VStack(alignment: .leading) {
Text(rowTitle)
.font(.title3)
.padding(.horizontal, 50)
ScrollView(.horizontal) {
HStack(alignment: .top) {
ForEach(items, id: \.self) { item in
VStack(spacing: 15) {
Button {
selectedAction(item)
} label: {
ImageView(item.portraitHeaderViewURL(maxWidth: 257))
.frame(width: 257, height: 380)
}
.frame(height: 380)
.buttonStyle(PlainButtonStyle())
if showItemTitles {
Text(item.title)
.lineLimit(2)
.frame(width: 257)
}
}
}
}
.padding(.horizontal, 50)
.padding(.vertical)
}
.edgesIgnoringSafeArea(.horizontal)
}
.focusSection()
}
}