From 2ee4b0119d749594371f2582fe736e3344f1f93a Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Mon, 20 Dec 2021 15:23:31 +1100 Subject: [PATCH] improve image message ratio --- .../Message Cells/VisibleMessageCell.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Session/Conversations/Message Cells/VisibleMessageCell.swift b/Session/Conversations/Message Cells/VisibleMessageCell.swift index c7c6a5cf2..0d39cc9f1 100644 --- a/Session/Conversations/Message Cells/VisibleMessageCell.swift +++ b/Session/Conversations/Message Cells/VisibleMessageCell.swift @@ -612,8 +612,15 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate { let maxAspectRatio = 1 / minAspectRatio aspectRatio = aspectRatio.clamp(minAspectRatio, maxAspectRatio) let maxSize = CGSize(width: maxMessageWidth, height: maxMessageWidth) - var width = with(maxSize.height * aspectRatio) { $0 > maxSize.width ? maxSize.width : $0 } - var height = (width > maxSize.width) ? (maxSize.width / aspectRatio) : maxSize.height + var width: CGFloat + var height: CGFloat + if aspectRatio > 1 { + width = maxSize.width + height = width / aspectRatio + } else { + height = maxSize.height + width = height * aspectRatio + } // Don't blow up small images unnecessarily let minSize: CGFloat = 150 let shortSourceDimension = min(size.width, size.height)