summaryrefslogtreecommitdiff
path: root/Jel/Views/Library/Item/ItemMediaView.swift
blob: c7fe0cb3c5ebd1d04e937a1882373c8adbb52db7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
//  ItemMediaView.swift
//  Jel
//
//  Created by zerocool on 12/23/23.
//

import SwiftUI
import JellyfinKit
import VisibilityTrackingScrollView

struct ItemMediaView<Content: View>: View {
  @EnvironmentObject var jellyfinClient: JellyfinClientController
  @StateObject var authState: AuthStateController = AuthStateController.shared
  
  @State var item: BaseItemDto
  @ViewBuilder var playButton: () -> Content
  
  @State var pageScrolled: Bool = false
  
  var body: some View {
    GeometryReader {geo in
      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)
          
          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()
    }
    .navigationBarTitleDisplayMode(.inline)
    .navigationTitle(item.name ?? "Untitled")
    .toolbarRole(.editor)
    .toolbar {
      ToolbarItem(placement: .principal) {
        Text(pageScrolled ? item.name ?? "Untitled" : "")
          .bold()
      }
    }
    .scrollIndicators(.hidden)
    
  }
}

//#Preview {
//  ItemMovieView(item: BaseItemDto())
//}