SDWebImageSwiftUI icon indicating copy to clipboard operation
SDWebImageSwiftUI copied to clipboard

The behavior of aspectRatio between AnimatedImage and WebImage is not same

Open hstdt opened this issue 2 years ago • 9 comments

As screenshot shows, AnimatedImage with aspectRatio is larger/smaller than expected.

CleanShot 2023-11-03 at 10 59 29

Environment: Xcode 15.1 beta, iOS 17 Demo Project: SDDisplayDemo.zip

hstdt avatar Nov 03 '23 03:11 hstdt

Update: with scaledToFit() or scaledToFill()

CleanShot 2023-11-03 at 11 11 08

hstdt avatar Nov 03 '23 03:11 hstdt

For animated image, to workaround a old iOS 13 issue, the actual image view is the subview of an container. And use auto layout to edge align to edge of that container

This history work on iOS 13-16, seems broken. Don't know whether compatible issue with auto layout with SwiftUI 's layout system or other case

Need time to investigate

dreampiggy avatar Nov 03 '23 08:11 dreampiggy

Can you use the 3.0.0-beta2 to test the same behavior ?

dreampiggy avatar Dec 19 '23 15:12 dreampiggy

@dreampiggy Xcode 15.2 beta with v3.0.0-beta.2/v3.0.0-beta.3

CleanShot 2023-12-20 at 10 18 54

hstdt avatar Dec 20 '23 02:12 hstdt

Seems the bug still exists....

Do you knwo the layout constraint about auto layout X SwiftUI ? Need more time or other people to help with this.

Can you try to investigate ad debug by checking the AnimatedImageViewWrapper ?

dreampiggy avatar Dec 20 '23 06:12 dreampiggy

What's the point of _AspectRatioLayout(aspectRatio: aspectRatio, contentMode: contentMode), I removed this and everything is ok now(only tested on iOS 17).

demo project: SDDisplayDemo.zip

CleanShot 2023-12-20 at 14 50 47

CleanShot 2023-12-20 at 14 55 06

hstdt avatar Dec 20 '23 06:12 hstdt

It's used to implements the custom aspectRatio. Like 0.5

Not content mode. SwiftUI this modifier provide 2 function (transform) and (display scale mode) using the 1 API, which is hard for UIKit based to implements


I think the biggest bad design it that both WebImage and AnimatedImage try to copy the API design from SwiftUI.Image, which is totally wrong. Especially for async-loading images, there're no actual placeholder aspect ratio or content to place.

But it's introduced at the beginning, all the thing I wrote on the day 2019 :)

dreampiggy avatar Dec 21 '23 17:12 dreampiggy

Try using

Image()
.resizable
.aspectRatio(0.5, .fit)

And compared with WebImage/AnimatedImage to see the result.

dreampiggy avatar Dec 21 '23 17:12 dreampiggy

I think the behavior works on iOS 16-, but break on iOS 17+

You can test the lower version as well, from the iOS 14 ~ iOS 17, each iOS version need to test the behavior again.

dreampiggy avatar Dec 21 '23 17:12 dreampiggy

Any update here?

arnauddorgans avatar Mar 08 '24 17:03 arnauddorgans