From a90930c7f931a0ecc8f4bd82f618c455c13830b4 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 21 Jul 2020 18:34:31 -0500 Subject: [PATCH] Correct image resize adjustment for scaling up images --- Multiplatform/Shared/Images/IconImageView.swift | 6 +++++- Multiplatform/iOS/Article/IconView.swift | 3 +++ Multiplatform/macOS/Article/IconView.swift | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Multiplatform/Shared/Images/IconImageView.swift b/Multiplatform/Shared/Images/IconImageView.swift index 9ef973b1b..61c067762 100644 --- a/Multiplatform/Shared/Images/IconImageView.swift +++ b/Multiplatform/Shared/Images/IconImageView.swift @@ -39,7 +39,11 @@ struct IconImageView: View { let newSize: CGSize if imageSize.height == imageSize.width { - return imageSize + if imageSize.height >= viewSize.height { + newSize = CGSize(width: viewSize.width, height: viewSize.height) + } else { + newSize = CGSize(width: imageSize.width, height: imageSize.height) + } } else if imageSize.height > imageSize.width { let factor = viewSize.height / imageSize.height let width = imageSize.width * factor diff --git a/Multiplatform/iOS/Article/IconView.swift b/Multiplatform/iOS/Article/IconView.swift index aa7c095b8..d42b17b24 100644 --- a/Multiplatform/iOS/Article/IconView.swift +++ b/Multiplatform/iOS/Article/IconView.swift @@ -100,6 +100,9 @@ private extension IconView { let imageSize = image.size let viewSize = bounds.size if imageSize.height == imageSize.width { + if imageSize.height >= viewSize.height { + return CGRect(x: 0.0, y: 0.0, width: viewSize.width, height: viewSize.height) + } let offset = floor((viewSize.height - imageSize.height) / 2.0) return CGRect(x: offset, y: offset, width: imageSize.width, height: imageSize.height) } diff --git a/Multiplatform/macOS/Article/IconView.swift b/Multiplatform/macOS/Article/IconView.swift index 7616af3f4..7a721c4f8 100644 --- a/Multiplatform/macOS/Article/IconView.swift +++ b/Multiplatform/macOS/Article/IconView.swift @@ -107,6 +107,9 @@ private extension IconView { let imageSize = image.size let viewSize = bounds.size if imageSize.height == imageSize.width { + if imageSize.height >= viewSize.height { + return NSMakeRect(0.0, 0.0, viewSize.width, viewSize.height) + } let offset = floor((viewSize.height - imageSize.height) / 2.0) return NSMakeRect(offset, offset, imageSize.width, imageSize.height) }