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

Reseting thumb image #26085

Merged
merged 3 commits into from
Dec 3, 2024
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25939.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue25939">
<StackLayout>
<Slider
x:Name="SliderControl"
WidthRequest="300"
HeightRequest="50"
Minimum="0"
Maximum="100"
Value="50"/>

<Button
AutomationId="ChangeThumbImageSourceButton"
Text="Change thumb image source"
Clicked="OnThumbImageSourceButtonClicked"/>

<Slider
x:Name="SliderControl2"
WidthRequest="300"
HeightRequest="50"
Minimum="0"
Maximum="100"
Value="50"/>

<Button
AutomationId="ResetThumbImageSourceButton"
Text="Reset thumb"
Clicked="OnResetButtonClicked"/>

</StackLayout>
</ContentPage>
21 changes: 21 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25939.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 25939, "Unable to Remove Thumb Image in Slider Control ", PlatformAffected.Android | PlatformAffected.iOS)]
public partial class Issue25939 : ContentPage
{
public Issue25939()
{
InitializeComponent();
}

private void OnThumbImageSourceButtonClicked(object sender, EventArgs e)
{
SliderControl.ThumbImageSource = "coffee.png";
SliderControl2.ThumbImageSource = "coffee.png";
}
private void OnResetButtonClicked(object sender, EventArgs e)
{
SliderControl2.ThumbImageSource = null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue25939 : _IssuesUITest
{
public Issue25939(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Unable to Remove Thumb Image in Slider Control ";

[Test]
[Category(UITestCategories.Slider)]
public void SliderShouldChangeThumbImageAndResetIt()
{
App.WaitForElement("ChangeThumbImageSourceButton");
App.Click("ChangeThumbImageSourceButton");
App.Click("ResetThumbImageSourceButton");
VerifyScreenshot();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion src/Core/src/Platform/Android/SliderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Threading.Tasks;
using Android.Content.Res;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Util;
using Android.Widget;

namespace Microsoft.Maui.Platform
Expand Down Expand Up @@ -63,6 +63,21 @@ public static async Task UpdateThumbImageSourceAsync(this SeekBar seekBar, ISlid
if (seekBar.IsAlive() && thumbDrawable != null)
seekBar.SetThumb(thumbDrawable);
}
else
{
seekBar.SetThumb(context.GetDrawable(Resource.Drawable.abc_seekbar_thumb_material));
if (slider.ThumbColor is null && context.Theme is not null)
{
using var value = new TypedValue();
context.Theme.ResolveAttribute(Android.Resource.Attribute.ColorAccent, value, true);
var color = new Color(value.Data);
seekBar.Thumb?.SetColorFilter(color, FilterMode.SrcIn);
}
else
{
seekBar.UpdateThumbColor(slider);
}
}
}
}
}
5 changes: 5 additions & 0 deletions src/Core/src/Platform/iOS/SliderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public static async Task UpdateThumbImageSourceAsync(this UISlider uiSlider, ISl

uiSlider.SetThumbImage(thumbImage, UIControlState.Normal);
}
else
{
uiSlider.SetThumbImage(null, UIControlState.Normal);
uiSlider.UpdateThumbColor(slider);
}
}
}
}
Loading