[iOS] Fix downscaled images not occupying correct space#17120
[iOS] Fix downscaled images not occupying correct space#17120mattleibow merged 15 commits intonet8.0from
Conversation
|
Images.zip |
0c7a000 to
7ba850e
Compare
a857452 to
0a37fd6
Compare
0a37fd6 to
9dc9a20
Compare
9dc9a20 to
a386876
Compare
mattleibow
left a comment
There was a problem hiding this comment.
Is it possible to add some image comparison tests? The current tests look like they just check for "is this color somewhere" and that will not catch much.
|
For tests: maui/src/Controls/tests/UITests/Tests/Issues/Issue15330.cs Lines 16 to 23 in e25d331 maui/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs Lines 288 to 323 in e25d331 |
mattleibow
left a comment
There was a problem hiding this comment.
I missed the image size tests, so this is OK for now
|
/backport to release/8.0.1xx-rc2.1 |
|
Started backporting to release/8.0.1xx-rc2.1: https://github.com/dotnet/maui/actions/runs/6593944764 |
Problem
Large iOS images would not honor their layout's specified height/width nor would they display in a way that's consistent with Android and Windows.
The problem is caused by a limitation in iOS. When calling
SizeThatFitsfor anImageView, the function will always return the image's dimensions regardless of what the user constrains. This is by design from AppleThis also affected image buttons.
Solution
We create our own extension method that calculates "SizeThatFits" in a way that respects the View's given constraints. When the
Aspectis equal toAspectFit, we calculate the how much we need to scale down the image based on the smallest dimension that fit the image. Otherwise, we just return the original constraints.Keep in mind that this custom implementation of "SizeThatFits" is only used for calculating space needed by the view. It does not calculate the size of the image that's inside the view; we leave that to the native
ContentMode(aka the Aspect settings).Issue Before & After Screenshots (Catalyst & iOS)
I didn't include screenshots for every issue that was reported regarding this topic because there were too many as this was a pretty significant issue.
16120 (click me!)
14139 (click me!)
16921 (click me!)
(See the sample given in #16921)
iOS and Mac ran the same but I'm only including the Mac recording. Note that the small blue "button" shows how the large image should actually behave. This is because the "button" is actually a non-downscaled image.
Before
Screen.Recording.2023-08-31.at.5.55.46.PM.mov
After
Screen.Recording.2023-08-31.at.5.50.20.PM.mov
14926 (click me!)
Note The green box is supposed to "overflow" to fulfill the grid's * width requirement. It is not meant to overlap with other buttons, however.
13893 (click me!)
See customer sample in linked issue
There were many samples here, but they boiled down to similar problems, shown in the view below.
Issues Fixed
Fixes #16120
Fixes #14139
Fixes #16921
Fixes #14606
Fixes #13893
Fixes #14926
Fixes #10481
Fixes #12359
Work Remaining