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

Fix Android ImageButton background, ripple and padding #22298

Merged
merged 47 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ed416e4
Added sample
jsuarezruiz Apr 4, 2024
5578fd0
Fix the issue
jsuarezruiz Apr 4, 2024
19cc997
Updated sample
jsuarezruiz Apr 4, 2024
caa88d7
More changes
jsuarezruiz Apr 4, 2024
3f39572
Fixed mistake
jsuarezruiz Apr 4, 2024
e0f8116
Avoid recreate RippleDrawable updating the Background
jsuarezruiz Apr 5, 2024
f96d086
Merge branch 'main' into fix-ripple-imagebutton
mattleibow Apr 23, 2024
c7be23f
Share the ripple logic for buttons
mattleibow May 8, 2024
9d75900
this
mattleibow May 8, 2024
9901acc
Added UITest
jsuarezruiz May 9, 2024
c7ae455
Added snapshot
jsuarezruiz May 9, 2024
888b564
Updated sample test
jsuarezruiz May 9, 2024
3caebc6
Updated snapshot
jsuarezruiz May 9, 2024
f714c94
Merge remote-tracking branch 'origin/main' into dev/shared-ripple
mattleibow May 9, 2024
d3a0482
Merge remote-tracking branch 'origin/main' into dev/shared-ripple
mattleibow May 9, 2024
69cc06f
fix that
mattleibow May 9, 2024
694d038
Updated snapshot
jsuarezruiz May 13, 2024
2e82eaf
Merge remote-tracking branch 'origin/main' into dev/shared-ripple
mattleibow May 13, 2024
21d260f
Fix ImageButton Padding
mattleibow May 13, 2024
6ba5178
samples
mattleibow May 13, 2024
c411e6f
Add the UI tests
mattleibow May 14, 2024
c5079b7
Merge branch 'main' into dev/shared-ripple
mattleibow May 14, 2024
dd8281c
that too
mattleibow May 14, 2024
6af4e4c
this
mattleibow May 14, 2024
f458175
a bit better
mattleibow May 14, 2024
99ad697
img
mattleibow May 15, 2024
cf91039
img
mattleibow May 15, 2024
52a6b2a
Merge remote-tracking branch 'origin/main' into dev/shared-ripple
mattleibow May 17, 2024
2094cda
Merge remote-tracking branch 'origin/main' into dev/shared-ripple
mattleibow May 17, 2024
a4dfbf7
fix after the merge
mattleibow May 17, 2024
b895262
terrible
mattleibow May 17, 2024
3f532f7
android
mattleibow May 17, 2024
e878fee
img
mattleibow May 17, 2024
fe3802f
fix more
mattleibow May 17, 2024
10b6db8
Merge remote-tracking branch 'origin/main' into dev/shared-ripple
mattleibow May 17, 2024
bad952e
Some fixes I needed
mattleibow May 17, 2024
401fb79
this
mattleibow May 17, 2024
11e76c5
Merge branch 'dev/fixes' into dev/shared-ripple
mattleibow May 17, 2024
582778c
this
mattleibow May 17, 2024
83a1765
Merge branch 'dev/fixes' into dev/shared-ripple
mattleibow May 17, 2024
16630a5
moar
mattleibow May 17, 2024
72167e3
Merge branch 'dev/fixes' into dev/shared-ripple
mattleibow May 17, 2024
960c49e
:(
mattleibow May 17, 2024
49ffc74
img
mattleibow May 18, 2024
d27904f
Merge remote-tracking branch 'origin/main' into dev/shared-ripple
mattleibow May 18, 2024
dd97286
Merge remote-tracking branch 'origin/main' into dev/shared-ripple
mattleibow May 20, 2024
a639ae9
fix the name
mattleibow May 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue18857">
<VerticalStackLayout>
<ImageButton
x:Name="BackgroundImageButton"
AutomationId="TestImageButton"
HorizontalOptions="Center"
Aspect="AspectFit"
BorderColor="Red"
BorderWidth="10"
CornerRadius="12"
mattleibow marked this conversation as resolved.
Show resolved Hide resolved
HeightRequest="200"
WidthRequest="200"
Source="shopping_cart.png"
Padding="0" />
<HorizontalStackLayout
HorizontalOptions="Center">
<Button
x:Name="UpdateBackgroundButton"
AutomationId="TestUpdateBackgroundButton"
Text="Update Background"
Clicked="OnUpdateBackgroundButtonClicked"/>
<Button
x:Name="RemoveBackgroundButton"
AutomationId="TestRemoveBackgroundButton"
Text="Remove Background"
Clicked="OnRemoveBackgroundButtonClicked"/>
</HorizontalStackLayout>
</VerticalStackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 18857, "ImageButton Padding & Ripple effect stops working with .NET 8", PlatformAffected.Android)]
public partial class Issue18857 : ContentPage
{
public Issue18857()
{
InitializeComponent();
UpdateImageButtonBackground();
}

void OnUpdateBackgroundButtonClicked(object sender, EventArgs e)
{
UpdateImageButtonBackground();
}

void OnRemoveBackgroundButtonClicked(object sender, EventArgs e)
{
BackgroundImageButton.Background = null;
}

void UpdateImageButtonBackground()
{
Color startColor = Colors.GreenYellow;
Color endColor = Colors.Yellow;

BackgroundImageButton.Background = new LinearGradientBrush
{
EndPoint = new Point(1, 0),
GradientStops = new GradientStopCollection
{
new GradientStop { Color = startColor },
new GradientStop { Color = endColor, Offset = 1 }
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@
Source="cog.png"
CornerRadius="10"
BackgroundColor="Purple"/>
<ImageButton
Aspect="AspectFit"
Source="cog.png"
BackgroundColor="Purple"
CornerRadius="{Binding Source={x:Reference CornerRadiusSlider}, Path=Value}" />
<Slider
x:Name="CornerRadiusSlider"
Minimum="0"
Maximum="60"
Value="10"/>
<Label
Text="Custom Size"
Style="{StaticResource Headline}"/>
Expand Down Expand Up @@ -164,6 +174,40 @@
<Button
Text="Use Online Source"
Clicked="UseOnlineSource_Clicked"/>
<Label
Text="Background (Null)"
Style="{StaticResource Headline}"/>
<ImageButton
HorizontalOptions="Center"
Clicked="OnImageButtonClicked"
Aspect="AspectFit"
BorderColor="Red"
BorderWidth="10"
Source="cog.png"
Padding="0" />
<Label
Text="Background (Gradient)"
Style="{StaticResource Headline}"/>
<ImageButton
x:Name="BackgroundImageButton"
HorizontalOptions="Center"
Clicked="OnImageButtonClicked"
Aspect="AspectFit"
BorderColor="Red"
BorderWidth="10"
Source="cog.png"
Padding="0" />
<HorizontalStackLayout
HorizontalOptions="Center">
<Button
x:Name="UpdateBackgroundButton"
Text="Update Background"
Clicked="OnUpdateBackgroundButtonClicked"/>
<Button
x:Name="RemoveBackgroundButton"
Text="Remove Background"
Clicked="OnRemoveBackgroundButtonClicked"/>
</HorizontalStackLayout>
</VerticalStackLayout>
</ScrollView>
</views:BasePage.Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Windows.Input;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Pages
{
Expand All @@ -20,6 +21,8 @@ public ImageButtonPage()
if (e.PropertyName == ImageButton.IsLoadingProperty.PropertyName)
Debug.WriteLine($"{e.PropertyName}: {ImageButton01.IsLoading}");
};

UpdateImageButtonBackground();
}

void OnImageButtonClicked(object sender, EventArgs e)
Expand All @@ -39,6 +42,33 @@ void UseOnlineSource_Clicked(object sender, EventArgs e)
AnimatedGifImage.Source =
ImageSource.FromUri(new Uri("https://raw.githubusercontent.com/dotnet/maui/126f47aaf9d5c01224f54fe1c6bfb1c8299cc2fe/src/Compatibility/ControlGallery/src/iOS/GifTwo.gif"));
}

void OnUpdateBackgroundButtonClicked(object sender, EventArgs e)
{
UpdateImageButtonBackground();
}

void OnRemoveBackgroundButtonClicked(object sender, EventArgs e)
{
BackgroundImageButton.Background = null;
}

void UpdateImageButtonBackground()
{
Random rnd = new Random();
Color startColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);
Color endColor = Color.FromRgba(rnd.Next(256), rnd.Next(256), rnd.Next(256), 255);

BackgroundImageButton.Background = new LinearGradientBrush
{
EndPoint = new Point(1, 0),
GradientStops = new GradientStopCollection
{
new GradientStop { Color = startColor },
new GradientStop { Color = endColor, Offset = 1 }
}
};
}
}

public class ImageButtonPageViewModel : BindableObject
Expand Down
36 changes: 36 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue18857.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues
{
public class Issue18857 : _IssuesUITest
{
public Issue18857(TestDevice device)
: base(device)
{ }

public override string Issue => "ImageButton Padding & Ripple effect stops working with .NET 8";

[Test]
[Category(UITestCategories.ImageButton)]
public async Task GradientImageButtonBackground()
{
this.IgnoreIfPlatforms(new[]
{
TestDevice.Mac,
TestDevice.iOS,
TestDevice.Windows
});

App.WaitForElement("TestImageButton");

App.Tap("TestRemoveBackgroundButton");
App.Tap("TestUpdateBackgroundButton");

await Task.Delay(500);

VerifyScreenshot();
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the image take into account the BorderWidth and not overflow it?

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ protected override void ConnectHandler(ShapeableImageView platformView)

public static void MapBackground(IImageButtonHandler handler, IImageButton imageButton)
{
(handler.PlatformView as ShapeableImageView)?.UpdateBackground(imageButton);
handler.PlatformView?.UpdateBackground(imageButton);
}

public static void MapStrokeColor(IImageButtonHandler handler, IButtonStroke buttonStroke)
{
(handler.PlatformView as ShapeableImageView)?.UpdateStrokeColor(buttonStroke);
handler.PlatformView?.UpdateStrokeColor(buttonStroke);
}

public static void MapStrokeThickness(IImageButtonHandler handler, IButtonStroke buttonStroke)
{
(handler.PlatformView as ShapeableImageView)?.UpdateStrokeThickness(buttonStroke);
handler.PlatformView?.UpdateStrokeThickness(buttonStroke);
}

public static void MapCornerRadius(IImageButtonHandler handler, IButtonStroke buttonStroke)
{
(handler.PlatformView as ShapeableImageView)?.UpdateCornerRadius(buttonStroke);
handler.PlatformView.UpdateCornerRadius(buttonStroke);
}

public static void MapPadding(IImageButtonHandler handler, IImageButton imageButton)
{
(handler.PlatformView as ShapeableImageView)?.UpdatePadding(imageButton);
handler.PlatformView?.UpdatePadding(imageButton);
}

void OnFocusChange(object? sender, View.FocusChangeEventArgs e)
Expand Down