diff options
Diffstat (limited to 'Jel/Views/Library/LibraryIconView.swift')
-rw-r--r-- | Jel/Views/Library/LibraryIconView.swift | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/Jel/Views/Library/LibraryIconView.swift b/Jel/Views/Library/LibraryIconView.swift index a849446..9bd3182 100644 --- a/Jel/Views/Library/LibraryIconView.swift +++ b/Jel/Views/Library/LibraryIconView.swift @@ -32,21 +32,22 @@ struct LibraryIconView: View { if let image = state.image { image .resizable() + .aspectRatio(contentMode: contentMode) } else { if let content = placeHolder { content } else { Image(uiImage: blurHashImage) .resizable() + .aspectRatio(contentMode: .fill) } } } - .aspectRatio(contentMode: contentMode) .frame(width: width, height: height) .clipShape(RoundedRectangle(cornerRadius: imageCornerRadius)) .onAppear { let blurhash = library.imageBlurHashes?.primary?[library.imageTags?[imageType] ?? ""] ?? "" - blurHashImage = UIImage(blurHash: blurhash, size: CGSize(width: 16, height: 16)) ?? UIImage() + blurHashImage = UIImage(blurHash: blurhash, size: CGSize(width: 32, height: 32)) ?? UIImage() let imageId = library.id ?? "" let request = Paths.getItemImage(itemID: imageId, imageType: imageType) @@ -70,6 +71,22 @@ struct LibraryIconView: View { copy.imageCornerRadius = cornerRadius return copy } + + func setAspectRatio(_ aspectRatio: Double?) -> Self { + var copy = self + if aspectRatio == nil { + return copy + } + + if let newWidth = copy.width { + copy.height = newWidth / aspectRatio! + } + if let newHeight = copy.height { + copy.width = newHeight * aspectRatio! + } + + return copy + } } //#Preview { |