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
Set Icon to null and back again, working around Android issue #13267
Conversation
There seems to be an Android bug where it sometimes doesn't compute the updated icon position correctly, treating IconGravityTextEnd as if it were IconGravityTextStart. Setting the Icon to null and then back again forces the resetIconDrawable call here https://github.com/material-components/material-components-android/blob/25b3c2b15c9b9499993d6d4a5fb491ffce04517a/lib/java/com/google/android/material/button/MaterialButton.java#L852-L869 to happen which seems to make things work properly. Fixes #11755
Looks reasonable to me. Is this ready for review? Are you planning on trying to add some tests? |
I went back to this and finally got a working device test. |
src/Controls/tests/DeviceTests/Elements/Layout/LayoutTests.Android.cs
Outdated
Show resolved
Hide resolved
using Microsoft.Maui.Platform; | ||
using Xunit; | ||
|
||
namespace Microsoft.Maui.DeviceTests | ||
{ | ||
public partial class LayoutTests | ||
{ | ||
[Fact, Category(TestCategory.Layout)] | ||
public async Task NestedButtonHasExpectedIconPosition() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update this test so that it takes in all four variations of Button.ButtonContentLayout.ImagePosition
and then those all get validated as being in the correct place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Updated. That caught a failure with Top as well - a failure which I oddly wasn't able to reproduce in the sandbox test app, but nevertheless it looks to be a legit failure, fixed by updating the Top logic similarly in ButtonExtensions, which I did.
* Set Icon to null and back again, working around Android issue There seems to be an Android bug where it sometimes doesn't compute the updated icon position correctly, treating IconGravityTextEnd as if it were IconGravityTextStart. Setting the Icon to null and then back again forces the resetIconDrawable call here https://github.com/material-components/material-components-android/blob/25b3c2b15c9b9499993d6d4a5fb491ffce04517a/lib/java/com/google/android/material/button/MaterialButton.java#L852-L869 to happen which seems to make things work properly. Fixes #11755 * Add device test * Update test so results show in window * Update to use AttachAndRun, for performance * Use new base class method to call AttachAndRun * Remove unneeded InvokeOnMainThreadAsync * Update to use CreateHandlerAndAddToWindow * Use Theory to test all 4 icon positions * Update the logic for Top as well
Description of Change
There seems to be an Android bug where it sometimes doesn't compute the updated icon position correctly, treating IconGravityTextEnd as if it were IconGravityTextStart. Setting the Icon to null and then back again forces the resetIconDrawable call here
https://github.com/material-components/material-components-android/blob/25b3c2b15c9b9499993d6d4a5fb491ffce04517a/lib/java/com/google/android/material/button/MaterialButton.java#L852-L869 to happen which seems to make things work properly.
Thanks go to @PureWeen who helped a lot with this fix. We tried several variations before settling on this.
Issues Fixed
Fixes #11755