jel/Jel/Views/Library/Item/ItemMediaView.swift

86 lines
2.4 KiB
Swift
Raw Normal View History

//
// ItemMediaView.swift
// Jel
//
// Created by zerocool on 12/23/23.
//
import SwiftUI
import JellyfinKit
struct ItemMediaView: View {
@EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var authState: AuthStateController = AuthStateController.shared
@State var item: BaseItemDto
@State var loading: Bool = true
2023-12-24 04:47:21 +00:00
@State var navigationTitle: String = ""
var body: some View {
GeometryReader {geo in
2023-12-25 01:01:52 +00:00
if loading {
ProgressView()
.progressViewStyle(.circular)
} else {
ScrollView {
ItemHeaderView(item: item)
.padding(.bottom)
.background {
GeometryReader {geo in
EmptyView()
.onChange(of: geo.frame(in: .global).minY) {
let minY = geo.frame(in: .global).minY
if minY < 0 {
navigationTitle = item.name ?? ""
} else {
navigationTitle = ""
}
}
}
2023-12-25 01:01:52 +00:00
}
VStack(alignment: .leading) {
Text(item.taglines?.count ?? 0 > 0 ? item.taglines?[0] ?? "" : "")
.font(.headline)
.frame(maxWidth: .infinity, alignment: .leading)
2023-12-25 06:02:38 +00:00
.padding(.bottom)
2023-12-25 01:01:52 +00:00
ForEach(item.overview?.components(separatedBy: "<br>") ?? [], id: \.self) {overview in
Text(overview)
}
}
.if(max(geo.safeAreaInsets.leading, geo.safeAreaInsets.trailing) > 0) {view in
view
.padding(max(geo.safeAreaInsets.leading, geo.safeAreaInsets.trailing))
}
.if(max(geo.safeAreaInsets.leading, geo.safeAreaInsets.trailing) <= 0) {view in
view
.padding()
}
2023-12-25 01:01:52 +00:00
}
.ignoresSafeArea()
}
}
2023-12-24 04:47:21 +00:00
.toolbarRole(.editor)
.navigationBarTitleDisplayMode(.inline)
2023-12-25 01:01:52 +00:00
.navigationTitle(navigationTitle)
.scrollIndicators(.hidden)
.onAppear {
Task {
do {
let request = Paths.getItem(userID: authState.userId ?? "", itemID: item.id ?? "")
2023-12-25 01:01:52 +00:00
let response = try await jellyfinClient.send(request)
item = response.value
loading = false
} catch {
}
}
}
}
}
2023-12-25 01:01:52 +00:00
//#Preview {
// ItemMovieView(item: BaseItemDto())
//}