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

79 lines
2.1 KiB
Swift
Raw Normal View History

//
// ItemMediaView.swift
// Jel
//
// Created by zerocool on 12/23/23.
//
import SwiftUI
import JellyfinKit
import VisibilityTrackingScrollView
2024-01-08 03:47:46 +00:00
struct ItemMediaView<Content: View>: View {
@EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var authState: AuthStateController = AuthStateController.shared
@State var item: BaseItemDto
2024-01-08 03:47:46 +00:00
@ViewBuilder var playButton: () -> Content
2023-12-24 04:47:21 +00:00
@State var pageScrolled: Bool = false
var body: some View {
GeometryReader {geo in
2024-01-08 03:47:46 +00:00
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
pageScrolled = minY < 0
}
}
}
2024-01-08 03:47:46 +00:00
playButton()
VStack(alignment: .leading) {
Text(item.taglines?.count ?? 0 > 0 ? item.taglines?[0] ?? "" : "")
.font(.headline)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.bottom)
ForEach(item.overview?.components(separatedBy: "<br>") ?? [], id: \.self) {overview in
Text(overview)
}
2024-01-08 03:47:46 +00:00
ItemGenresView(item: item)
}
.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
}
}
2024-01-08 03:47:46 +00:00
.ignoresSafeArea()
}
.navigationBarTitleDisplayMode(.inline)
.navigationTitle(item.name ?? "Untitled")
.toolbarRole(.editor)
.toolbar {
ToolbarItem(placement: .principal) {
Text(pageScrolled ? item.name ?? "Untitled" : "")
.bold()
}
}
2023-12-25 01:01:52 +00:00
.scrollIndicators(.hidden)
2024-01-08 03:47:46 +00:00
}
}
2023-12-25 01:01:52 +00:00
//#Preview {
// ItemMovieView(item: BaseItemDto())
//}