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 JellyfinKit
import VisibilityTrackingScrollView import VisibilityTrackingScrollView
struct ItemMediaView: View { struct ItemMediaView<Content: View>: View {
@EnvironmentObject var jellyfinClient: JellyfinClientController @EnvironmentObject var jellyfinClient: JellyfinClientController
@StateObject var authState: AuthStateController = AuthStateController.shared @StateObject var authState: AuthStateController = AuthStateController.shared
@State var item: BaseItemDto @State var item: BaseItemDto
@State var loading: Bool = true @ViewBuilder var playButton: () -> Content
@State var pageScrolled: Bool = false @State var pageScrolled: Bool = false
var body: some View { var body: some View {
GeometryReader {geo in GeometryReader {geo in
if loading { ScrollView() {
ProgressView() ItemHeaderView(item: item)
.progressViewStyle(.circular) .padding(.bottom)
} else { .background {
ScrollView() { GeometryReader {geo in
ItemHeaderView(item: item) 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) .padding(.bottom)
.background {
GeometryReader {geo in
EmptyView()
.onChange(of: geo.frame(in: .global).minY) {
let minY = geo.frame(in: .global).minY
pageScrolled = minY < 0 ForEach(item.overview?.components(separatedBy: "<br>") ?? [], id: \.self) {overview in
} Text(overview)
}
}
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()
} }
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) .navigationBarTitleDisplayMode(.inline)
.navigationTitle(item.name ?? "Untitled") .navigationTitle(item.name ?? "Untitled")
@ -72,17 +69,7 @@ struct ItemMediaView: View {
} }
} }
.scrollIndicators(.hidden) .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: case .movie:
ItemMovieView(item: item) ItemMovieView(item: item)
default: default:
ItemMediaView(item: item) ItemMediaView(item: item) {
EmptyView()
}
} }
} }
} }

View File

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