Skip to content

Conversation

@Shalini-Ashokan
Copy link
Contributor

@Shalini-Ashokan Shalini-Ashokan commented Mar 11, 2025

Issue Details

The ImageButton image rendered on Android was not adjusting its bounds correctly, leading to improper scaling.

Root Cause

The image button was not rendering based on its bounds value.

Description of Change

In ImageButton Android Handler, set true for SetAdjustViewBounds(), when you enable view bounds adjustment, the ImageView will automatically resize to maintain the image's aspect ratio.

Validated the behavior in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #25558
Fixes #14346

Output ScreenShot

Before After
Screenshot 2025-03-11 at 3 23 41 PM Screenshot 2025-03-11 at 3 27 32 PM

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Mar 11, 2025
@dotnet-policy-service
Copy link
Contributor

Hey there @Shalini-Ashokan! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Mar 11, 2025
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
Copy link
Contributor

Choose a reason for hiding this comment

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

Super-nit: After #28040, you can convert this to file-scope namespace by CTRL+. in Visual Studio (I believe it's the same in VS Code).

If it is converted, then new files will use file-scope namespaces more and more as people IMO copy old files to create new code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion , I have changed the file-scope namespace.

Comment on lines 21 to 27
if (image.Aspect == Aspect.AspectFill)
imageView.SetAdjustViewBounds(false);
else
imageView.SetAdjustViewBounds(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Code style for "new code" should be:

Suggested change
if (image.Aspect == Aspect.AspectFill)
imageView.SetAdjustViewBounds(false);
else
imageView.SetAdjustViewBounds(true);
if (image.Aspect == Aspect.AspectFill)
{
imageView.SetAdjustViewBounds(false);
}
else
{
imageView.SetAdjustViewBounds(true);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MartyIX, Thanks for the suggestion, I have updated the code style.

@jsuarezruiz jsuarezruiz added the area-controls-button Button, ImageButton label Mar 12, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

public void Issue25558VerifyImageButtonAspects()
{
App.WaitForElement("imageButton");
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

Pending snapshots on Mac and Windows. Already available in the latest build.

Example, Mac:
image

Could you commit the images?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz, I have committed the image.


[Test]
[Category(UITestCategories.ImageButton)]
public void Issue25558VerifyImageButtonAspects()
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is failing on Windows:

   at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2367
   at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2384
   at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 665
   at Microsoft.Maui.TestCases.Tests.Issues.Issue25558.Issue25558VerifyImageButtonAspects() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25558.cs:line 19
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz, I have modified the test to resolve the failing.

@Shalini-Ashokan Shalini-Ashokan marked this pull request as ready for review March 13, 2025 06:46
@Shalini-Ashokan Shalini-Ashokan requested a review from a team as a code owner March 13, 2025 06:46
@Shalini-Ashokan
Copy link
Contributor Author

@jsuarezruiz, The Issue18242Test failure is related to my changes. Previously, the ImageButton without a specified height was not rendering correctly. Shall I commit the newly generated image?

Issue18242Test-diff

@jsuarezruiz
Copy link
Contributor

@jsuarezruiz, The Issue18242Test failure is related to my changes. Previously, the ImageButton without a specified height was not rendering correctly. Shall I commit the newly generated image?

Issue18242Test-diff

In that case, yes.

@Shalini-Ashokan
Copy link
Contributor Author

@jsuarezruiz, The Issue18242Test failure is related to my changes. Previously, the ImageButton without a specified height was not rendering correctly. Shall I commit the newly generated image?
Issue18242Test-diff

In that case, yes.

@jsuarezruiz, I have committed the failure image.

@jsuarezruiz
Copy link
Contributor

/rebase

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/rebase

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/rebase

@jsuarezruiz
Copy link
Contributor

/rebase

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-button Button, ImageButton community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImageButton dosen't scale Image correctly ButtonImage width not sizing correctly

3 participants