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
[Android] Fix Ripple effect with custom background (alternative to #17821) #20412
Conversation
base.DisconnectHandler(platformView); | ||
} | ||
|
||
// This is a Android-specific mapping | ||
public static void MapBackground(IButtonHandler handler, IButton button) | ||
{ | ||
handler.PlatformView?.UpdateBackground(button); | ||
if (handler is ButtonHandler buttonHandler) |
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.
I don't think we need to case the handler. The PlatformView on IButtonHandler is MaterialButton
using PlatformView = Google.Android.Material.Button.MaterialButton; |
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.
Right, but require the cast to ButtonHandler
to access to the default drawable and pass it updating the Background.
Yea, @mattleibow is going to get this one buttoned up. |
/rebase |
} | ||
} | ||
// Default obtained by running on Android 34 and inspecting the default drawable | ||
const int DefaultCornerRadius = 4; |
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.
Are these values correct for all supported API levels?
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.
I copied from 34, so maybe... I was hoping consistency is better but we can check later maybe so we can get this PR in.
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.
This is material, so most likely the values are the same across all OS versions - but I have not checked.
gradientDrawable?.SetColor(ColorStateList.ValueOf(solidPaint.Color.ToPlatform())); | ||
} | ||
// Copy the tints from a temporary button. | ||
using var btn = new MaterialButton(context); |
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.
Passing the default drawable has been changed to copy the tints from a temporary button. It is not an operation that happens frequently, set a background and then removing it, but is this perhaps more expensive?
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.
It is a bit more expensive, but we don't need to add fields to handlers and pass the default drawable around. That requires new APIs and a bunch of old ones not working. It is more expensive, but this is smei-temporary because all I am using is the tint:
var defaultTintList = btn.BackgroundTintList;
var defaultColor = defaultTintList?.GetColorForState([R.Attribute.StateEnabled], AColor.Black) ?? AColor.Black;
A better option is to not do either and just figure out the default tint color. There is probably some theme resource or some API to just get the raw color. However the color goes from android resources to the main color of the button - some primary color thing. If we can do that in our code, it will just be reading a resource color from the android resources.
I'll create an issue to fix this.
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.
My change was just fixing the Tizen API shipping txt file nothing functional. |
Hello, approximately when can we expect new MAUI version with this fix? |
Hi @PureWeen and @jsuarezruiz , |
Hopefully next week. In the mean time can you test the nightly and let us know how it works for you? |
I've created a copy of my current project and I've upgraded it from .NET 7 to newest .NET 8 nightly build: 8.0.20-nightly.10431 I don't really have the ability to test iOS, but on Android buttons work just like in .NET 7 which is great :) |
Hi @PureWeen . |
My solution:
@PureWeen , is there a simpler way ? It overrides this part of code. I cannot set platformView.RippleColor (always null after setting) |
Description of Change
Fix Ripple effect with custom background (alternative to #17821).
Ripple effects (without background, using backgound color, using a brush, etc)
Modifying also borders, corners etc
To test, use the added sample to the UITest project.
Also added a device test.
Issues Fixed
Fixes #17642