Changed console library game view to lazy gridview

This commit is contained in:
2021-05-25 15:50:04 +02:00
parent 1befc62135
commit 4cf7e520a1
3 changed files with 38 additions and 12 deletions

View File

@@ -32,6 +32,7 @@ class ICloudManager {
static public func fileExists(at path : String?) -> Bool {
guard let path = path else { return false }
if path == "" { return false }
if let url = documents_folder?.appendingPathComponent(path) {
return FileManager.default.fileExists(atPath: url.path)

View File

@@ -95,6 +95,12 @@ struct ConsoleLibraryView : View {
self.accessoryFetchRequest = FetchRequest<Accessory>(entity: Accessory.entity(), sortDescriptors: [NSSortDescriptor(key: "name", ascending: true)], predicate: NSPredicate(format: "console == %@", console))
}
let columns : [GridItem] = [
GridItem(.adaptive(minimum: 100))
]
let defaultImage = UIImage()
var body: some View {
VStack {
HStack {
@@ -107,19 +113,38 @@ struct ConsoleLibraryView : View {
Spacer()
}
if self.isVideogamesSelected {
List(games.filter({$0.inWishlist == self.showWishlist})) { game in
NavigationLink(destination: GameDetailView(game: game)) {
HStack {
Text("\(game.name ?? "n/a")")
ScrollView {
LazyVGrid(columns: columns, spacing: 20) {
ForEach(games.filter({$0.inWishlist == self.showWishlist})) { game in
NavigationLink(destination: GameDetailView(game: game)) {
if ICloudManager.fileExists(at: game.cover_icloud_path) {
Image(uiImage: ICloudManager.imageFrom(path: game.cover_icloud_path) ?? defaultImage)
.resizable()
.scaledToFit()
.cornerRadius(5)
}else{
Group {
Text(game.name)
.font(.caption)
.foregroundColor(Color.black)
.padding()
.multilineTextAlignment(.center)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.gray)
.cornerRadius(5)
}
if game.isDigital {
Image("digitalGame")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(height: 15)
// if game.isDigital {
// Image("digitalGame")
// .resizable()
// .aspectRatio(contentMode: .fit)
// .frame(height: 15)
// }
}
}
}
}.padding()
}
}else {
List(accessories.filter({$0.inWishlist == self.showWishlist})) {accessory in

View File

@@ -91,7 +91,7 @@ struct Overview: View {
Text("\(console.name)")
.font(.caption)
.frame(width: 100)
.frame(width: 100)
}.padding(.leading, 15)
}.buttonStyle(PlainButtonStyle())