Skip to content

Conversation

@aheubusch
Copy link
Contributor

Description of Change

Improve the workaround (#22298) for the iffy Android ShapeImageView contentPadding/padding handling.
The underlying problem is that ShapeImageView updates Padding in onMeasure leading to a double padding. The previous workaround reset the Padding after one eventloop hoping that onMeasure was called in the meantime. This worked for most cases but not all. The "improved" workaround overrides onMeasure and resets the Padding as soon as it was set.

I ran all ImageButton tests I could find and they are all green. So thats a good sign.

Issues Fixed

Fixes #25201
Fixes #16713
Fixes #18001
Fixes #13101

@aheubusch aheubusch requested a review from a team as a code owner October 11, 2024 22:46
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Oct 11, 2024
platformButton.SetContentPadding((int)padding.Left, (int)padding.Top, (int)padding.Right, (int)padding.Bottom);
platformButton.SetPadding(0, 0, 0, 0);

// Just like before, the bugs are not done. This needs to trigger a re-calculation of
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mattleibow You have added this part (ShapeAppearanceModel) in #22298. I am not sure if I can just remove it. None of the tests that looked relevant failed on my machine.

Copy link
Member

Choose a reason for hiding this comment

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

I am scared tbh. I forget the corner cases where this happens - and they yield is especially scary. I think I was going off the fixes the native side was doing.

The current test set may not be enough and we will have to go remove this and see what breaks manually, and then make your change to see if it fixes it.

@jsuarezruiz
Copy link
Contributor

jsuarezruiz commented Oct 14, 2024

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@aheubusch
Copy link
Contributor Author

Not sure if the test failure are because of this PR. They all fail with a System.TimeoutException.

@aheubusch aheubusch closed this Oct 23, 2024
@aheubusch aheubusch deleted the android_imagebutton_padding branch October 23, 2024 07:48
@aheubusch aheubusch restored the android_imagebutton_padding branch October 23, 2024 08:34
@aheubusch aheubusch reopened this Oct 23, 2024
@jfversluis
Copy link
Member

/rebase

Remove ShapeableImageView Padding immediately after it is set in its
onMeasure method to avoid double padding (ContentPadding + Padding).
@github-actions github-actions bot force-pushed the android_imagebutton_padding branch from 0a0de1e to 8a3a074 Compare December 6, 2024 15:02
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

I am super scared with this as the ImageButton was super fragile and I think I have seen padding issues but was super hard to repro in a test or I was not able to reliably repro.

I added tests as I did things, and TJ probably added more. But, I am not sure there are enough.

This comment does not help move the PR along, but I need to play a bit more and try and repro the issues that required the terrible hacks.

platformButton.SetContentPadding((int)padding.Left, (int)padding.Top, (int)padding.Right, (int)padding.Bottom);
platformButton.SetPadding(0, 0, 0, 0);

// Just like before, the bugs are not done. This needs to trigger a re-calculation of
Copy link
Member

Choose a reason for hiding this comment

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

I am scared tbh. I forget the corner cases where this happens - and they yield is especially scary. I think I was going off the fixes the native side was doing.

The current test set may not be enough and we will have to go remove this and see what breaks manually, and then make your change to see if it fixes it.

@BlueRaja
Copy link

Any chance to get this in for the next release? Both Border and Padding on ImageButton are still broken, with no known workaround. This seems like pretty basic functionality to just straight up not work at all.

@@ -0,0 +1,35 @@
#if ANDROID
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we run the test in all the platforms? In that way, we can just verify that the Padding property behavior is aligned.

@karthikraja-arumugam
Copy link
Contributor

This PR also resolves the issue #18875

@rmarinho rmarinho moved this from Todo to Ready To Review in MAUI SDK Ongoing Mar 20, 2025
@github-project-automation github-project-automation bot moved this from Ready To Review to Approved in MAUI SDK Ongoing Mar 20, 2025
@rmarinho rmarinho moved this from Approved to Ready To Review in MAUI SDK Ongoing Mar 20, 2025
Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

Now that I have had a nap, I don't think we should be writing C# anymore ;) OK, maybe we just need to put that new maui shape view into Java and use it there. The hopping back and forth will be a perf hit.


namespace Microsoft.Maui.Platform
{
internal class MauiShapeableImageView : ShapeableImageView
Copy link
Member

Choose a reason for hiding this comment

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

Just looking at this and I think that this is all Java code so we probably should just do it in Java and let the bonding do the magic.

Doing it in C# is probably going have a big perf impact.

Copy link
Member

Choose a reason for hiding this comment

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

New issue for this Java work: #28532

@mattleibow
Copy link
Member

We can do Java in a new PR: #28532

@mattleibow mattleibow changed the base branch from main to inflight/current March 20, 2025 11:30

namespace Microsoft.Maui.Platform
{
internal class MauiShapeableImageView : ShapeableImageView
Copy link
Member

Choose a reason for hiding this comment

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

New issue for this Java work: #28532

@github-project-automation github-project-automation bot moved this from Changes Requested to Approved in MAUI SDK Ongoing Mar 20, 2025
@mattleibow mattleibow merged commit 320b488 into dotnet:inflight/current Mar 20, 2025
108 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Mar 20, 2025
PureWeen pushed a commit that referenced this pull request Mar 26, 2025
Remove ShapeableImageView Padding immediately after it is set in its
onMeasure method to avoid double padding (ContentPadding + Padding).
PureWeen pushed a commit that referenced this pull request Mar 26, 2025
Remove ShapeableImageView Padding immediately after it is set in its
onMeasure method to avoid double padding (ContentPadding + Padding).
github-actions bot pushed a commit that referenced this pull request Mar 27, 2025
Remove ShapeableImageView Padding immediately after it is set in its
onMeasure method to avoid double padding (ContentPadding + Padding).
@github-actions github-actions bot locked and limited conversation to collaborators Apr 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

8 participants