-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[iOS] Fix Background issue in Button CustomRenderer #12395
Conversation
} | ||
|
||
Control.BackgroundColor = backgroundColor; | ||
if (_useBackgroundBrush) |
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.
Should this be using a locally stored _defaultBackgroundColor instead of a bool check?
Basically how SetBackgroundColor is setup?
protected override void SetBackgroundColor(Color color)
{
if (IsElementOrControlEmpty)
return;
#if __MOBILE__
if (color == Color.Default)
Control.BackgroundColor = _defaultColor;
else
Control.BackgroundColor = color.ToUIColor();
#else
Control.Layer.BackgroundColor = color == Color.Default ? _defaultColor : color.ToCGColor();
#endif
}
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.
Yes, we already have a variable with the default color, the new bool variable only indicates if a brush is being used or not. We have two properties Background
and BackgroundColor
and this variable just indicate us when we can update the background using a color.
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 still feels a little bit off to me. _useBackgroundBrush
can only ever be toggled one direction so once it's true it's always true
So, after you set the Background to something it becomes impossible to use the BackgroundColor
. If you set the Background back to "Default" then use the BackgroundColor property it'll just set the Control.BackgroundColor
to null
private void Button_Clicked(object sender, EventArgs e)
{
// this code stops working after you've set the Background to a brush.
btnMe.Background = SolidColorBrush.Default;
btnMe.BackgroundColor = Color.Green;
}
private void Button_Clicked2(object sender, EventArgs e)
{
btnMe.Background = SolidColorBrush.Purple;
}
Is this expected behavior?
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.
Shane, I totally see your feedback and I understand it. I have applied changes with a different approach with more sense.
Now, the custom renderer works and also your case works without using any internal variable etc.
Description of Change
Fix Background issue in Button CustomRenderer in iOS.
Issues Resolved
API Changes
None
Platforms Affected
Behavioral/Visual Changes
None
Before/After Screenshots
Testing Procedure
Launch Core Gallery and navigate to the issue 12372. If you can see the background color of the custom Button below, the test has passed.
PR Checklist