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,21 +9,17 @@ 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 {
ProgressView()
.progressViewStyle(.circular)
} else {
ScrollView() { ScrollView() {
ItemHeaderView(item: item) ItemHeaderView(item: item)
.padding(.bottom) .padding(.bottom)
@ -38,6 +34,8 @@ struct ItemMediaView: View {
} }
} }
playButton()
VStack(alignment: .leading) { VStack(alignment: .leading) {
Text(item.taglines?.count ?? 0 > 0 ? item.taglines?[0] ?? "" : "") Text(item.taglines?.count ?? 0 > 0 ? item.taglines?[0] ?? "" : "")
.font(.headline) .font(.headline)
@ -61,7 +59,6 @@ struct ItemMediaView: View {
} }
.ignoresSafeArea() .ignoresSafeArea()
} }
}
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.navigationTitle(item.name ?? "Untitled") .navigationTitle(item.name ?? "Untitled")
.toolbarRole(.editor) .toolbarRole(.editor)
@ -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)
}
} }
} }
} }