diff options
author | Shav Kinderlehrer <[email protected]> | 2023-12-27 08:25:35 -0500 |
---|---|---|
committer | Shav Kinderlehrer <[email protected]> | 2023-12-27 08:25:35 -0500 |
commit | 7aa602f19dec3cf526c4550c5e63a8fc6dfac723 (patch) | |
tree | a4ee5ed0a5e8b9a40ad0ef5e98b1e65b8fd207cb /Jel/Views/Library/LibraryIconView.swift | |
parent | bd0b6ff491b33088a4db55c495b8aab797f0b22a (diff) | |
download | jel-7aa602f19dec3cf526c4550c5e63a8fc6dfac723.tar.gz jel-7aa602f19dec3cf526c4550c5e63a8fc6dfac723.zip |
Implement auto aspect ratio for LibraryIconViews
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 { |