Switch from ExyteGrid to lazygrid

This commit is contained in:
Aiden Vigue 2021-05-23 23:38:57 -04:00
parent 352d47f387
commit 58b45cd2be
4 changed files with 82 additions and 82 deletions

View File

@ -109,7 +109,7 @@ struct ContinueWatchingView: View {
if(resumeItems.count != 0) { if(resumeItems.count != 0) {
VStack(alignment: .leading) { VStack(alignment: .leading) {
ScrollView(.horizontal, showsIndicators: false) { ScrollView(.horizontal, showsIndicators: false) {
HStack() { LazyHStack() {
if(isLoading == false) { if(isLoading == false) {
Spacer().frame(width:16) Spacer().frame(width:16)
ForEach(resumeItems, id: \.Id) { item in ForEach(resumeItems, id: \.Id) { item in

View File

@ -84,7 +84,7 @@ struct LatestMediaView: View {
var body: some View { var body: some View {
ScrollView(.horizontal, showsIndicators: false) { ScrollView(.horizontal, showsIndicators: false) {
HStack() { LazyHStack() {
Spacer().frame(width:18) Spacer().frame(width:18)
ForEach(resumeItems, id: \.Id) { item in ForEach(resumeItems, id: \.Id) { item in
NavigationLink(destination: ItemView(item: item)) { NavigationLink(destination: ItemView(item: item)) {

View File

@ -33,8 +33,6 @@ struct LibraryView: View {
@State private var url: String = ""; @State private var url: String = "";
@State private var closeSearch: Bool = false; @State private var closeSearch: Bool = false;
var gridItems: [GridItem] = [GridItem(.adaptive(minimum: 150, maximum: 400))]
init(prefill: String?, names: [String: String], libraries: [String]) { init(prefill: String?, names: [String: String], libraries: [String]) {
_prefill_id = State(wrappedValue: prefill ?? "") _prefill_id = State(wrappedValue: prefill ?? "")
_library_names = State(wrappedValue: names) _library_names = State(wrappedValue: names)
@ -166,91 +164,93 @@ struct LibraryView: View {
_tracks.wrappedValue = [] _tracks.wrappedValue = []
for _ in (0..<trkCnt) for _ in (0..<trkCnt)
{ {
_tracks.wrappedValue.append(GridTrack.fr(1)) _tracks.wrappedValue.append(GridItem.init(.flexible()))
} }
} }
@State private var tracks: [GridTrack] = [] @State private var tracks: [GridItem] = []
var body: some View { var body: some View {
if(prefill_id != "") { if(prefill_id != "") {
LoadingView(isShowing: $isLoading) { LoadingView(isShowing: $isLoading) {
GeometryReader { geometry in GeometryReader { geometry in
Grid(tracks: _tracks.wrappedValue, spacing: GridSpacing(horizontal: 0, vertical: 20)) { ScrollView(.vertical) {
ForEach(items, id: \.Id) { item in LazyVGrid(columns: tracks) {
NavigationLink(destination: ItemView(item: item )) { ForEach(items, id: \.Id) { item in
VStack(alignment: .leading) { NavigationLink(destination: ItemView(item: item )) {
if(item.Type == "Movie") { VStack(alignment: .leading) {
WebImage(url: URL(string: "\(globalData.server?.baseURI ?? "")/Items/\(item.Id)/Images/\(item.ImageType)?maxWidth=150&quality=90&tag=\(item.Image)")) if(item.Type == "Movie") {
.resizable() WebImage(url: URL(string: "\(globalData.server?.baseURI ?? "")/Items/\(item.Id)/Images/\(item.ImageType)?maxWidth=150&quality=90&tag=\(item.Image)"))
.placeholder { .resizable()
Image(uiImage: UIImage(blurHash: (item.BlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : item.BlurHash), size: CGSize(width: 32, height: 32))!) .placeholder {
.resizable() Image(uiImage: UIImage(blurHash: (item.BlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : item.BlurHash), size: CGSize(width: 6, height: 6))!)
.frame(width: 100, height: 150) .resizable()
.cornerRadius(10) .frame(width: 100, height: 150)
} .cornerRadius(10)
.frame(width:100, height: 150) }
.cornerRadius(10) .frame(width:100, height: 150)
.shadow(radius: 5) .cornerRadius(10)
} else { .shadow(radius: 5)
WebImage(url: URL(string: "\(globalData.server?.baseURI ?? "")/Items/\(item.Id)/Images/\(item.ImageType)?maxWidth=150&quality=90&tag=\(item.Image)")) } else {
.resizable() WebImage(url: URL(string: "\(globalData.server?.baseURI ?? "")/Items/\(item.Id)/Images/\(item.ImageType)?maxWidth=150&quality=90&tag=\(item.Image)"))
.placeholder { .resizable()
Image(uiImage: UIImage(blurHash: (item.BlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : item.BlurHash), size: CGSize(width: 32, height: 32))!) .placeholder {
.resizable() Image(uiImage: UIImage(blurHash: (item.BlurHash == "" ? "W$H.4}D%bdo#a#xbtpxVW?W?jXWsXVt7Rjf5axWqxbWXnhada{s-" : item.BlurHash), size: CGSize(width: 6, height: 6))!)
.frame(width: 100, height: 150) .resizable()
.cornerRadius(10) .frame(width: 100, height: 150)
} .cornerRadius(10)
.frame(width:100, height: 150) }
.cornerRadius(10).overlay( .frame(width:100, height: 150)
ZStack { .cornerRadius(10).overlay(
if(item.ItemBadge == 0) { ZStack {
Image(systemName: "checkmark") if(item.ItemBadge == 0) {
.font(.caption) Image(systemName: "checkmark")
.padding(3) .font(.caption)
.foregroundColor(.white) .padding(3)
} else { .foregroundColor(.white)
Text("\(String(item.ItemBadge ?? 0))") } else {
.font(.caption) Text("\(String(item.ItemBadge ?? 0))")
.padding(3) .font(.caption)
.foregroundColor(.white) .padding(3)
} .foregroundColor(.white)
}.background(Color.black) }
.opacity(0.8) }.background(Color.black)
.cornerRadius(10.0) .opacity(0.8)
.padding(3), alignment: .topTrailing .cornerRadius(10.0)
) .padding(3), alignment: .topTrailing
.shadow(radius: 5) )
} .shadow(radius: 5)
Text(item.Name) }
.font(.caption) Text(item.Name)
.fontWeight(.semibold) .font(.caption)
.foregroundColor(.primary) .fontWeight(.semibold)
.lineLimit(1) .foregroundColor(.primary)
Text(String(item.ProductionYear)) .lineLimit(1)
.foregroundColor(.secondary) Text(String(item.ProductionYear))
.font(.caption) .foregroundColor(.secondary)
.fontWeight(.medium) .font(.caption)
}.frame(width: 100) .fontWeight(.medium)
} }.frame(width: 100)
}
if(startIndex + endIndex < totalItems) {
HStack() {
Spacer()
Button() {
startIndex += endIndex;
loadItems()
} label: {
HStack() {
Text("Load more").font(.callout)
Image(systemName: "arrow.clockwise")
}
} }
Spacer() }
}.gridSpan(column: _tracks.wrappedValue.count) if(startIndex + endIndex < totalItems) {
HStack() {
Spacer()
Button() {
startIndex += endIndex;
loadItems()
} label: {
HStack() {
Text("Load more").font(.callout)
Image(systemName: "arrow.clockwise")
}
}
Spacer()
}
}
Spacer().frame(height: 2)
} }
Spacer().frame(height: 2).gridSpan(column: _tracks.wrappedValue.count) }
}.gridContentMode(.scroll)
.onChange(of: isPortrait) { _ in .onChange(of: isPortrait) { _ in
recalcTracks() recalcTracks()
} }

View File

@ -72,7 +72,7 @@ struct NextUpView: View {
if(resumeItems.count != 0) { if(resumeItems.count != 0) {
Text("Next Up").font(.title2).fontWeight(.bold).padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16)) Text("Next Up").font(.title2).fontWeight(.bold).padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16))
ScrollView(.horizontal, showsIndicators: false) { ScrollView(.horizontal, showsIndicators: false) {
HStack() { LazyHStack() {
if(isLoading == false) { if(isLoading == false) {
Spacer().frame(width:18) Spacer().frame(width:18)
ForEach(resumeItems, id: \.Id) { item in ForEach(resumeItems, id: \.Id) { item in
@ -108,8 +108,8 @@ struct NextUpView: View {
} }
Spacer().frame(width:18) Spacer().frame(width:18)
} }
} }.frame(height: 200)
}.padding(EdgeInsets(top: -2, leading: 0, bottom: 0, trailing: 0)) }.padding(EdgeInsets(top: -2, leading: 0, bottom: 0, trailing: 0)).frame(height: 200)
} }
}.onAppear(perform: onAppear).padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) }.onAppear(perform: onAppear).padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
} }