Add playButton child view

This commit is contained in:
Shav Kinderlehrer 2024-01-07 22:47:46 -05:00
parent e807d06319
commit 1f25fa576d
3 changed files with 45 additions and 51 deletions

View File

@ -9,58 +9,55 @@ import SwiftUI
import JellyfinKit
import VisibilityTrackingScrollView
struct ItemMediaView: View {
struct ItemMediaView<Content: View>: View {
@EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var authState: AuthStateController = AuthStateController.shared
@State var item: BaseItemDto
@State var loading: Bool = true
@ViewBuilder var playButton: () -> Content
@State var pageScrolled: Bool = false
var body: some View {
GeometryReader {geo in
if loading {
ProgressView()
.progressViewStyle(.circular)
} else {
ScrollView() {
ItemHeaderView(item: item)
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
}
}
}
playButton()
VStack(alignment: .leading) {
Text(item.taglines?.count ?? 0 > 0 ? item.taglines?[0] ?? "" : "")
.font(.headline)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.bottom)
.background {
GeometryReader {geo in
EmptyView()
.onChange(of: geo.frame(in: .global).minY) {
let minY = geo.frame(in: .global).minY
pageScrolled = minY < 0
}
}
}
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)
}
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()
ForEach(item.overview?.components(separatedBy: "<br>") ?? [], id: \.self) {overview in
Text(overview)
}
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()
}
.ignoresSafeArea()
}
.ignoresSafeArea()
}
.navigationBarTitleDisplayMode(.inline)
.navigationTitle(item.name ?? "Untitled")
@ -72,17 +69,7 @@ struct ItemMediaView: View {
}
}
.scrollIndicators(.hidden)
.onAppear {
Task {
do {
let request = Paths.getItem(userID: authState.userId ?? "", itemID: item.id ?? "")
let response = try await jellyfinClient.send(request)
item = response.value
loading = false
} catch {
}
}
}
}
}

View File

@ -15,7 +15,9 @@ struct ItemView: View {
case .movie:
ItemMovieView(item: item)
default:
ItemMediaView(item: item)
ItemMediaView(item: item) {
EmptyView()
}
}
}
}

View File

@ -12,7 +12,12 @@ struct ItemMovieView: View {
@State var item: BaseItemDto
var body: some View {
VStack {
ItemMediaView(item: item)
ItemMediaView(item: item) {
Button("Play") {
}
.buttonStyle(.borderedProminent)
}
}
}
}