diff --git a/Sora/Views/LibraryView/LibraryView.swift b/Sora/Views/LibraryView/LibraryView.swift index 4d2a104..396300c 100644 --- a/Sora/Views/LibraryView/LibraryView.swift +++ b/Sora/Views/LibraryView/LibraryView.swift @@ -76,6 +76,10 @@ struct LibraryView: View { .frame(maxWidth: .infinity) } else { LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 12), count: columnsCount), spacing: 12) { + let totalSpacing: CGFloat = 16 * CGFloat(columnsCount + 1) // Spacing between items + let availableWidth = UIScreen.main.bounds.width - totalSpacing + let cellWidth = availableWidth / CGFloat(columnsCount) + ForEach(libraryManager.bookmarks) { item in if let module = moduleManager.modules.first(where: { $0.id.uuidString == item.moduleId }) { NavigationLink(destination: MediaInfoView(title: item.title, imageUrl: item.imageUrl, href: item.href, module: module)) { @@ -89,9 +93,9 @@ struct LibraryView: View { .shimmering() } .resizable() - .aspectRatio(2/3, contentMode: .fill) - // Allow the image to expand to fill the available width of its grid cell. - .frame(maxWidth: .infinity) + .aspectRatio(contentMode: .fill) + .frame(height: cellWidth * 3 / 2) + .frame(maxWidth: cellWidth) .cornerRadius(10) .clipped() .overlay( diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index 8b47f57..2ad0986 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -65,9 +65,10 @@ struct MediaInfoView: View { .shimmering() } .resizable() - .aspectRatio(2/3, contentMode: .fit) - .cornerRadius(10) + .aspectRatio(contentMode: .fill) .frame(width: 150, height: 225) + .clipped() + .cornerRadius(10) VStack(alignment: .leading, spacing: 4) { Text(title) diff --git a/Sora/Views/SearchView.swift b/Sora/Views/SearchView.swift index de0bb1b..9680cca 100644 --- a/Sora/Views/SearchView.swift +++ b/Sora/Views/SearchView.swift @@ -112,15 +112,21 @@ struct SearchView: View { .frame(maxWidth: .infinity) .padding(.top) } else { + let totalSpacing: CGFloat = 16 * CGFloat(columnsCount + 1) // Spacing between items + let availableWidth = UIScreen.main.bounds.width - totalSpacing + let cellWidth = availableWidth / CGFloat(columnsCount) + LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 16), count: columnsCount), spacing: 16) { ForEach(searchItems) { item in NavigationLink(destination: MediaInfoView(title: item.title, imageUrl: item.imageUrl, href: item.href, module: selectedModule!)) { VStack { KFImage(URL(string: item.imageUrl)) .resizable() - .aspectRatio(2/3, contentMode: .fit) + .aspectRatio(contentMode: .fill) + .frame(height: cellWidth * 3 / 2) + .frame(maxWidth: cellWidth) .cornerRadius(10) - .frame(maxWidth: .infinity) + .clipped() Text(item.title) .font(.subheadline) .foregroundColor(Color.primary)