Add playButton child view
This commit is contained in:
parent
e807d06319
commit
1f25fa576d
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,9 @@ struct ItemView: View {
|
||||
case .movie:
|
||||
ItemMovieView(item: item)
|
||||
default:
|
||||
ItemMediaView(item: item)
|
||||
ItemMediaView(item: item) {
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user