Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix [Android] Image AspectFill is not honored #25072

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue21368.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue21368">


<HorizontalStackLayout Spacing="40" Padding="10">
<VerticalStackLayout>
<Image Source="dotnet_bot.png" Aspect="AspectFit" HeightRequest="40" WidthRequest="50"
HorizontalOptions="Center" VerticalOptions="Center"/>
<Label Text="AspectFit" AutomationId="Label"/>
</VerticalStackLayout>
<VerticalStackLayout>
<Image Source="dotnet_bot.png" Aspect="AspectFill" WidthRequest="50" HeightRequest="40"
HorizontalOptions="Center" VerticalOptions="Center"/>
<Label Text="AspectFill"/>
</VerticalStackLayout>
</HorizontalStackLayout>

</ContentPage>
11 changes: 11 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue21368.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Maui.Controls.Sample.Issues;

[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 21368, "Image AspectFill is not honored", PlatformAffected.Android)]
public partial class Issue21368 : ContentPage
{
public Issue21368()
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue21368 : _IssuesUITest
{
public override string Issue => "Image AspectFill is not honored";

public Issue21368(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.Image)]
[FailsOnMac]
public void VerifyImageAspects()
{
App.WaitForElement("Label");
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triggered the build, it should generate the reference snapshot for this test.

}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/Core/src/Platform/Android/ImageViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public static void Clear(this ImageView imageView)

public static void UpdateAspect(this ImageView imageView, IImage image)
{
if (image.Aspect is Aspect.AspectFill)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I delete this code the test still passes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new test has been added, and now the test only passes when the fix is applied. This ensures that the fix is correctly addressing the issue, and without it, the test fails as expected.

imageView.SetAdjustViewBounds(false);
else
imageView.SetAdjustViewBounds(true);

imageView.SetScaleType(image.Aspect.ToScaleType());
}

Expand Down
Loading