Skip to content
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] Invalidate Button background drawable if size changes #11604

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<Button
Text="Button"/>
<Button
Text="Button with Tooltip" ToolTipProperties.Text="This is a tooltip!" />
Text="Button with Tooltip"
ToolTipProperties.Text="This is a tooltip!" />
<Label
Text="Disabled"
Style="{StaticResource Headline}"/>
Expand Down Expand Up @@ -43,7 +44,10 @@
Text="Background"
Style="{StaticResource Headline}" />
<Button
Text="Background">
x:Name="BackgroundButton"
Text="Background"
HorizontalOptions="Center"
Clicked="OnBackgroundButtonClicked">
<Button.Background>
<LinearGradientBrush EndPoint="1,0">
<GradientStop Color="Yellow"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ LineBreakMode SelectLineBreakMode()
return LineBreakMode.WordWrap;
}
}

int _backgroundCount;

void OnBackgroundButtonClicked(object sender, System.EventArgs e)
{
BackgroundButton.Text = $"Background tapped {_backgroundCount} times";
_backgroundCount++;
}
}

public class ButtonPageViewModel : BindableObject
Expand Down
8 changes: 8 additions & 0 deletions src/Core/src/Handlers/Button/ButtonHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected override void ConnectHandler(MaterialButton platformView)
platformView.SetOnTouchListener(TouchListener);

platformView.FocusChange += OnNativeViewFocusChange;
platformView.LayoutChange += OnPlatformViewLayoutChange;

base.ConnectHandler(platformView);
}
Expand All @@ -57,6 +58,7 @@ protected override void DisconnectHandler(MaterialButton platformView)
platformView.SetOnTouchListener(null);

platformView.FocusChange -= OnNativeViewFocusChange;
platformView.LayoutChange -= OnPlatformViewLayoutChange;

ImageSourceLoader.Reset();

Expand Down Expand Up @@ -157,6 +159,12 @@ void OnNativeViewFocusChange(object? sender, AView.FocusChangeEventArgs e)
VirtualView.IsFocused = e.HasFocus;
}

void OnPlatformViewLayoutChange(object? sender, AView.LayoutChangeEventArgs e)
{
if (sender is MaterialButton platformView && VirtualView != null)
platformView.UpdateBackground(VirtualView);
}

class ButtonClickListener : Java.Lang.Object, AView.IOnClickListener
{
public ButtonHandler? Handler { get; set; }
Expand Down