Skip to content
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.
31 changes: 31 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27515.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 27515, "Slider's thumb image doesn't respect color", PlatformAffected.iOS)]
public class Issue27515 : ContentPage
{
public Issue27515()
{
var slider = new Slider() { ThumbColor = Colors.Blue };
Content = new VerticalStackLayout()
{
slider,
new Button()
{
AutomationId = "ChangeThumbImageButton",
Text = "Click to change image",
Command = new Command(() => {
slider.ThumbImageSource = "coffee.png";
})
},
new Button()
{
AutomationId = "ChangeThumbColorButton",
Text = "Click to change color",
Command = new Command(() => {
slider.ThumbColor = Colors.Red;
})
}
};
}
}
}
Loading
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
@@ -0,0 +1,27 @@
#if ANDROID || IOS || MACCATALYST // Slider's thumb image doesn't respect color on Windows
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

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

public override string Issue => "Slider's thumb image doesn't respect color";

[Test]
[Category(UITestCategories.Slider)]
public void SliderThumbImageShouldRespectColor()
{
App.WaitForElement("ChangeThumbImageButton");
App.Click("ChangeThumbImageButton");
App.Click("ChangeThumbColorButton");
VerifyScreenshot();
Copy link
Contributor

@jsuarezruiz jsuarezruiz Feb 3, 2025

Choose a reason for hiding this comment

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

Pending snapshots already available in the latest build:
image

}
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion src/Core/src/Platform/iOS/SliderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@ public static void UpdateMaximumTrackColor(this UISlider uiSlider, ISlider slide

public static void UpdateThumbColor(this UISlider uiSlider, ISlider slider)
{
if (slider.ThumbColor != null)
if (slider.ThumbImageSource is not null && slider.Handler is not null)
{
var provider = slider.Handler.GetRequiredService<IImageSourceServiceProvider>();
uiSlider.UpdateThumbImageSourceAsync(slider, provider).FireAndForget();
}
else if (slider.ThumbColor is not null)
{
uiSlider.ThumbTintColor = slider.ThumbColor.ToPlatform();
}
}

public static async Task UpdateThumbImageSourceAsync(this UISlider uiSlider, ISlider slider, IImageSourceServiceProvider provider)
Expand All @@ -47,11 +54,18 @@ public static async Task UpdateThumbImageSourceAsync(this UISlider uiSlider, ISl

if (thumbImageSource != null)
{
// Clear the thumb color if we have a thumb image, so that slider doesn't clear image when sliding
uiSlider.ThumbTintColor = null;
var service = provider.GetRequiredImageSourceService(thumbImageSource);
var scale = uiSlider.GetDisplayDensity();
var result = await service.GetImageAsync(thumbImageSource, scale);
var thumbImage = result?.Value;

if (thumbImage is not null && slider.ThumbColor is not null)
{
thumbImage = thumbImage.ApplyTintColor(slider.ThumbColor.ToPlatform());
}

uiSlider.SetThumbImage(thumbImage, UIControlState.Normal);
}
else
Expand Down