-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fixed improper rendering of ThumbimageSource in Slider #27472
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
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
af666ca
Fixed slider thumb image scaling issue
NirmalKumarYuvaraj 02fbdc7
Modified the code changes
NirmalKumarYuvaraj d0612c5
Updated Images
NirmalKumarYuvaraj dac6849
updated code changes
NirmalKumarYuvaraj 54071ee
Modified resizing logic
NirmalKumarYuvaraj c5db800
Updated code changes
NirmalKumarYuvaraj f1fd763
Updated code changes
NirmalKumarYuvaraj dddc686
updated code changes
NirmalKumarYuvaraj e63320a
Updated test case images
NirmalKumarYuvaraj 021e266
Updated code changes
NirmalKumarYuvaraj 4343440
Added snap shots
NirmalKumarYuvaraj d7194e8
Update SliderExtensions.cs
NirmalKumarYuvaraj 79fe6fb
Updated code changes
NirmalKumarYuvaraj 59a67a3
updated snaps
NirmalKumarYuvaraj 8565a38
added issue link to script file
NirmalKumarYuvaraj 4602a97
Resaved Mac snaps
NirmalKumarYuvaraj 64a5b7d
Update SliderExtensions.cs
NirmalKumarYuvaraj 51cfa6c
Update SliderExtensions.cs
NirmalKumarYuvaraj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-2.46 KB
(92%)
...ases.Android.Tests/snapshots/android/SliderShouldChangeThumbImageAndResetIt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+43.7 KB
...ts/TestCases.Android.Tests/snapshots/android/SliderThumbImageShouldBeScaled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.89 KB
(92%)
...oid.Tests/snapshots/android/Slider_ChangeThumbImageSource_VerifyVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.89 KB
(92%)
...snapshots/android/Slider_SetThumbColorAndThumbImageSource_VerifyVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.45 KB
(100%)
...snapshots/android/Slider_SetThumbImageSourceAndThumbColor_VerifyVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.89 KB
(92%)
...ests/snapshots/android/Slider_SetValueAndThumbImageSource_VerifyVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 13258, "MAUI Slider thumb image is big on android", PlatformAffected.Android | PlatformAffected.iOS | PlatformAffected.macOS)] | ||
| public class Issue13258 : TestContentPage | ||
| { | ||
| protected override void Init() | ||
| { | ||
| StackLayout rootLayout = new StackLayout() { Spacing = 10, Padding = 10 }; | ||
|
|
||
| Label slider1DescriptionLabel = CreateLabel("Slider with Thumb Image"); | ||
| Slider slider1 = CreateSlider("avatar.png"); | ||
|
|
||
| Label slider2DescriptionLabel = CreateLabel("Thumb Image will be set to coffee.png at run time"); | ||
| Slider slider2 = CreateSlider(); | ||
|
|
||
| Label slider3DescriptionLabel = CreateLabel("Thumb Image will be set to null at run time"); | ||
| Slider slider3 = CreateSlider("shopping_cart.png"); | ||
|
|
||
| Button button = new Button() { Text = "Change Thumb Image", AutomationId = "ToggleImageBtn" }; | ||
| button.Clicked += (s, e) => ToggleThumbImages(slider2, slider3); | ||
|
|
||
| rootLayout.Children.Add(slider1DescriptionLabel); | ||
| rootLayout.Children.Add(slider1); | ||
|
|
||
| rootLayout.Children.Add(slider2DescriptionLabel); | ||
| rootLayout.Children.Add(slider2); | ||
|
|
||
| rootLayout.Children.Add(slider3DescriptionLabel); | ||
| rootLayout.Children.Add(slider3); | ||
|
|
||
| rootLayout.Children.Add(button); | ||
|
|
||
| Content = rootLayout; | ||
| } | ||
|
|
||
| Label CreateLabel(string text) | ||
| { | ||
| return new Label { Text = text }; | ||
| } | ||
|
|
||
| Slider CreateSlider(string thumbImageSource = null) | ||
| { | ||
| return new Slider { ThumbImageSource = thumbImageSource }; | ||
| } | ||
|
|
||
| private void ToggleThumbImages(Slider slider2, Slider slider3) | ||
| { | ||
| slider2.ThumbImageSource = "coffee.png"; | ||
| slider3.ThumbImageSource = null; | ||
| } | ||
| } |
Binary file modified
BIN
-415 Bytes
(96%)
...ts/TestCases.Mac.Tests/snapshots/mac/SliderShouldChangeThumbImageAndResetIt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.6 KB
...rols/tests/TestCases.Mac.Tests/snapshots/mac/SliderThumbImageShouldBeScaled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-377 Bytes
(98%)
...ses.Mac.Tests/snapshots/mac/Slider_ChangeThumbImageSource_VerifyVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-377 Bytes
(98%)
...sts/snapshots/mac/Slider_SetThumbColorAndThumbImageSource_VerifyVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-377 Bytes
(98%)
...ac.Tests/snapshots/mac/Slider_SetValueAndThumbImageSource_VerifyVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions
25
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue13258.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #if TEST_FAILS_ON_WINDOWS //Issue link - https://github.com/dotnet/maui/issues/29125 | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue13258 : _IssuesUITest | ||
| { | ||
| public Issue13258(TestDevice testDevice) : base(testDevice) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "MAUI Slider thumb image is big on android"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Slider)] | ||
| public void SliderThumbImageShouldBeScaled() | ||
| { | ||
| App.WaitForElement("ToggleImageBtn"); | ||
| App.Tap("ToggleImageBtn"); | ||
| VerifyScreenshot(); | ||
| } | ||
| } | ||
| #endif |
Binary file modified
BIN
-1.36 KB
(96%)
...ts/TestCases.iOS.Tests/snapshots/ios/SliderShouldChangeThumbImageAndResetIt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+52.5 KB
...rols/tests/TestCases.iOS.Tests/snapshots/ios/SliderThumbImageShouldBeScaled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.12 KB
(97%)
...ses.iOS.Tests/snapshots/ios/Slider_ChangeThumbImageSource_VerifyVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.12 KB
(97%)
...sts/snapshots/ios/Slider_SetThumbColorAndThumbImageSource_VerifyVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.12 KB
(97%)
...OS.Tests/snapshots/ios/Slider_SetValueAndThumbImageSource_VerifyVisualState.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,22 @@ | ||
| using System.Threading.Tasks; | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Android.Content.Res; | ||
| using Android.Graphics; | ||
| using Android.Graphics.Drawables; | ||
| using Android.Util; | ||
| using Android.Widget; | ||
| using Microsoft.Maui.Graphics.Platform; | ||
|
|
||
| namespace Microsoft.Maui.Platform | ||
| { | ||
| public static class SliderExtensions | ||
| { | ||
| public const double PlatformMaxValue = int.MaxValue; | ||
|
|
||
| //Material 2 design spec - https://m2.material.io/components/sliders/android#discrete-slider | ||
| //Additional info - https://github.com/material-components/material-components-android/blob/60b0325b39741784fca4d7aba079b65453bc7c66/lib/java/com/google/android/material/slider/res/values/dimens.xml#L27 | ||
| const int TARGET_SIZE = 20; // 10 radius * 2 | ||
|
|
||
| public static void UpdateMinimum(this SeekBar seekBar, ISlider slider) => UpdateValue(seekBar, slider); | ||
|
|
||
| public static void UpdateMaximum(this SeekBar seekBar, ISlider slider) => UpdateValue(seekBar, slider); | ||
|
|
@@ -25,7 +32,7 @@ public static void UpdateValue(this SeekBar seekBar, ISlider slider) | |
|
|
||
| public static void UpdateMinimumTrackColor(this SeekBar seekBar, ISlider slider) | ||
| { | ||
| if (slider.MinimumTrackColor != null) | ||
| if (slider.MinimumTrackColor is not null) | ||
| { | ||
| seekBar.ProgressTintList = ColorStateList.ValueOf(slider.MinimumTrackColor.ToPlatform()); | ||
| seekBar.ProgressTintMode = PorterDuff.Mode.SrcIn; | ||
|
|
@@ -34,7 +41,7 @@ public static void UpdateMinimumTrackColor(this SeekBar seekBar, ISlider slider) | |
|
|
||
| public static void UpdateMaximumTrackColor(this SeekBar seekBar, ISlider slider) | ||
| { | ||
| if (slider.MaximumTrackColor != null) | ||
| if (slider.MaximumTrackColor is not null) | ||
| { | ||
| seekBar.ProgressBackgroundTintList = ColorStateList.ValueOf(slider.MaximumTrackColor.ToPlatform()); | ||
| seekBar.ProgressBackgroundTintMode = PorterDuff.Mode.SrcIn; | ||
|
|
@@ -47,37 +54,81 @@ public static void UpdateThumbColor(this SeekBar seekBar, ISlider slider) => | |
| public static async Task UpdateThumbImageSourceAsync(this SeekBar seekBar, ISlider slider, IImageSourceServiceProvider provider) | ||
| { | ||
| var context = seekBar.Context; | ||
|
|
||
| if (context == null) | ||
| if (context is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var thumbImageSource = slider.ThumbImageSource; | ||
|
|
||
| if (thumbImageSource != null) | ||
| if (thumbImageSource is not null) | ||
| { | ||
| var service = provider.GetRequiredImageSourceService(thumbImageSource); | ||
| var result = await service.GetDrawableAsync(thumbImageSource, context); | ||
|
|
||
| var thumbDrawable = result?.Value; | ||
|
|
||
| if (seekBar.IsAlive() && thumbDrawable != null) | ||
| seekBar.SetThumb(thumbDrawable); | ||
| if (seekBar.IsAlive()) | ||
| { | ||
| if (thumbDrawable is not null) | ||
| { | ||
| SetThumbDrawable(seekBar, context, thumbDrawable); | ||
| } | ||
| else | ||
| { | ||
| SetDefaultThumb(seekBar, slider, context); | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| seekBar.SetThumb(context.GetDrawable(Resource.Drawable.abc_seekbar_thumb_material)); | ||
| if (slider.ThumbColor is null && context.Theme is not null) | ||
| SetDefaultThumb(seekBar, slider, context); | ||
| } | ||
| } | ||
|
|
||
| static void SetThumbDrawable(SeekBar seekBar, Android.Content.Context context, Drawable thumbDrawable) | ||
| { | ||
| // Check if we're setting the same drawable to avoid unnecessary work | ||
| if (ReferenceEquals(seekBar.Thumb, thumbDrawable)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| int thumbSize = (int)context.ToPixels(TARGET_SIZE); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
|
||
| if (thumbSize <= 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
|
|
||
| using (Bitmap bitmap = Bitmap.CreateBitmap(thumbSize, thumbSize, Bitmap.Config.Argb8888!)) | ||
| using (Canvas canvas = new Canvas(bitmap)) | ||
| { | ||
| thumbDrawable.SetBounds(0, 0, thumbSize, thumbSize); | ||
| thumbDrawable.Draw(canvas); | ||
|
|
||
| using (BitmapDrawable finalDrawable = new BitmapDrawable(context.Resources, bitmap)) | ||
| { | ||
| 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); | ||
| seekBar.SetThumb(finalDrawable); | ||
| } | ||
| else | ||
| } | ||
| } | ||
|
|
||
| static void SetDefaultThumb(SeekBar seekBar, ISlider slider, Android.Content.Context context) | ||
| { | ||
| 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(); | ||
| if (context.Theme.ResolveAttribute(Android.Resource.Attribute.ColorAccent, value, true)) | ||
| { | ||
| seekBar.UpdateThumbColor(slider); | ||
| seekBar.Thumb?.SetColorFilter(new Color(value.Data), FilterMode.SrcIn); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| seekBar.UpdateThumbColor(slider); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the code changes