damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 825a2f944fbdff5d5ccd54eee3a9b790c512ad18
parent 1aa70efee0189d0ac297b0f6aeb1e1ffb1ade5c8
Author: mainvolume <sina@mainvolume.com>
Date:   Tue,  4 Apr 2023 15:57:55 +0200

Improvement to square image displaying.

Closes: #864

Diffstat:
Mdamus/Components/ImageCarousel.swift | 11++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/damus/Components/ImageCarousel.swift b/damus/Components/ImageCarousel.swift @@ -134,23 +134,20 @@ func calculate_image_fill(geo: GeometryProxy, img_size: CGSize, is_animated: Boo let shape = determine_image_shape(img_size) let xfactor = geo.size.width / img_size.width - let yfactor = maxHeight / img_size.height + let scaled = img_size.height * xfactor + let yfactor = maxHeight / scaled // calculate scaled image height // set scale factor and constrain images to minimum 150 // and animations to scaled factor for dynamic size adjustment switch shape { case .portrait: let filling = yfactor <= 1.0 - let scaled = img_size.height * xfactor let height = filling ? maxHeight : max(scaled, minHeight) return ImageFill(filling: filling, height: height) case .square: - let filling = yfactor <= 1.0 && xfactor <= 1.0 - let scaled = img_size.height * xfactor - let height = filling ? maxHeight : max(scaled, minHeight) - return ImageFill(filling: filling, height: height) + let height = max(min(maxHeight, scaled), minHeight) + return ImageFill(filling: nil, height: height) case .landscape: - let scaled = img_size.height * xfactor let filling = scaled > maxHeight || xfactor < 1.0 let height = is_animated ? scaled : filling ? min(maxHeight, scaled) : max(scaled, minHeight) return ImageFill(filling: filling, height: height)