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 1 commit
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
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();
kubaflo marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
6 changes: 5 additions & 1 deletion src/Core/src/Handlers/Slider/SliderHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ namespace Microsoft.Maui.Handlers
public partial class SliderHandler : ViewHandler<ISlider, SeekBar>
{
SeekBarChangeListener ChangeListener { get; } = new SeekBarChangeListener();
internal Drawable? defaultThumbDrawable;

protected override SeekBar CreatePlatformView()
{
return new SeekBar(Context)
var seekBar = new SeekBar(Context)
{
DuplicateParentStateEnabled = false,
Max = (int)SliderExtensions.PlatformMaxValue
};

defaultThumbDrawable = seekBar.Thumb;
return seekBar;
}

protected override void ConnectHandler(SeekBar platformView)
Expand Down
6 changes: 5 additions & 1 deletion src/Core/src/Platform/Android/SliderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Threading.Tasks;
using Android.Content.Res;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Widget;

namespace Microsoft.Maui.Platform
Expand Down Expand Up @@ -63,6 +62,11 @@ public static async Task UpdateThumbImageSourceAsync(this SeekBar seekBar, ISlid
if (seekBar.IsAlive() && thumbDrawable != null)
seekBar.SetThumb(thumbDrawable);
}
else if (slider.Handler is SliderHandler sliderHandler)
{
seekBar.SetThumb(sliderHandler.defaultThumbDrawable);
mattleibow marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
}
}