SDWebImage / SDWebImageSwiftUI

SwiftUI Image loading and Animation framework powered by SDWebImage
https://sdwebimage.github.io/SDWebImageSwiftUI
MIT License
2.18k stars 224 forks source link

The behavior of aspectRatio between AnimatedImage and WebImage is not same #279

Closed hstdt closed 6 months ago

hstdt commented 11 months ago

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 commented 11 months ago

Update: with scaledToFit() or scaledToFill()

CleanShot 2023-11-03 at 11 11 08

dreampiggy commented 11 months ago

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 commented 9 months ago

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

hstdt commented 9 months ago

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

CleanShot 2023-12-20 at 10 18 54

dreampiggy commented 9 months ago

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 ?

hstdt commented 9 months ago

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

dreampiggy commented 9 months ago

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 commented 9 months ago

Try using

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

And compared with WebImage/AnimatedImage to see the result.

dreampiggy commented 9 months ago

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.

arnauddorgans commented 6 months ago

Any update here?