Fixed improper rendering of ThumbimageSource in Slider#27472
Fixed improper rendering of ThumbimageSource in Slider#27472NirmalKumarYuvaraj wants to merge 18 commits intodotnet:mainfrom
Conversation
jsuarezruiz
left a comment
There was a problem hiding this comment.
Seeing the behavior on Android and iOS makes me doubt, does it not happen on Windows? Is it not necessary to resize?
| if (thumbDrawable is BitmapDrawable bitmapDrawable && bitmapDrawable.Bitmap is { } bitmap) | ||
| { | ||
| // Define the target size for the thumb image | ||
| const int TARGET_SIZE = 48; // 48dp - default size of the thumb in Android |
There was a problem hiding this comment.
Could we get the size from the default thumb drawable and avoid set a specific size here?
There was a problem hiding this comment.
@jsuarezruiz ,Using the default thumbsize causes the image to be appear bigger in the view. So i have used the value 48 which will be the default height and width of the thumb.Please let me know if you have any concerns.
code snippet:
var defaultThumbSize = context.GetDrawable(Resource.Drawable.abc_seekbar_thumb_material);
var thumbImage = bitmap.Downsize(defaultThumbSize!.IntrinsicWidth, defaultThumbSize.IntrinsicHeight);There was a problem hiding this comment.
Can the const be at the top of the file along with a comment as to where the number came from? Is it from some android xml theme file?
There was a problem hiding this comment.
Also, what do you mean by "Using the default thumbsize causes the image to be appear bigger in the view"?
I think Javier is meaning can you read the value from the slider? Like, is there a slider.GetThumb method?
There was a problem hiding this comment.
@mattleibow , The seekBar.Thumb?.IntrinsicHeight and IntrinsicWidth return a value of 47 before resizing the thumb. To avoid pixel discrepancies, I rounded this to 48 and made it a constant value. I researched documentation regarding the thumb size. Material Design 2 (circular) suggests that the radius should be 10dp, whereas Material Design 3 (vertically positioned rectangle) recommends a height of 44dp and a width of 4dp. Could you please confirm which approach we should proceed with?
Material 2 - https://m2.material.io/components/sliders/android#discrete-slider
Material 3 - https://m3.material.io/components/sliders/specs
| var thumbImage = result?.Value; | ||
|
|
||
| var thumbImageSize = result?.Value.Size ?? CGSize.Empty; | ||
| const float TARGET_SIZE = 28f; |
There was a problem hiding this comment.
Same as Android comment.
There was a problem hiding this comment.
I have updated the measure logic. Please let me know if you have any concerns.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
@jsuarezruiz , i have attached the snapshots. please let me know if you have any concerns.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue13258.cs
Outdated
Show resolved
Hide resolved
|
@NirmalKumarYuvaraj please address feedback, thanks! |
@jfversluis , I have addressed the feedback and modified the changes. Please let me know if you have any concern. |
| thumbDrawable.SetBounds(0, 0, thumbSize, thumbSize); | ||
| thumbDrawable.Draw(canvas); | ||
|
|
||
| BitmapDrawable finalDrawable = new BitmapDrawable(context.Resources, bitmap); |
There was a problem hiding this comment.
Used using statements to ensure proper disposal of BitmapDrawable:
using (BitmapDrawable finalDrawable = new BitmapDrawable(context.Resources, bitmap))
{
seekBar.SetThumb(finalDrawable);
}
There was a problem hiding this comment.
@jsuarezruiz , I have updated the code changes. please let me know if you have any concerns.
|
/rebase |
928250f to
357ae53
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/rebase |
357ae53 to
9a4eb81
Compare
rmarinho
left a comment
There was a problem hiding this comment.
Small comments and improvements
46d5b62 to
4602a97
Compare
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
|
||
| static void SetThumbDrawable(SeekBar seekBar, Android.Content.Context context, Drawable thumbDrawable) | ||
| { | ||
| int thumbSize = (int)context.ToPixels(TARGET_SIZE); |
There was a problem hiding this comment.
// Validate thumb size
if (thumbSize <= 0)
return;
| } | ||
|
|
||
| static void SetThumbDrawable(SeekBar seekBar, Android.Content.Context context, Drawable thumbDrawable) | ||
| { |
There was a problem hiding this comment.
// Check if we're setting the same drawable to avoid unnecessary work
if (ReferenceEquals(seekBar.Thumb, thumbDrawable))
return;
There was a problem hiding this comment.
Added the code changes
jsuarezruiz
left a comment
There was a problem hiding this comment.
@NirmalKumarYuvaraj Could you rebase and fix the conflicts? Thanks in advance.
|
Hi @NirmalKumarYuvaraj looks like a stale PR. Closing it for now, if you feel that this shouldn't be closed then please rebase and reopen |

Issue Details
The ThumbImage set on the slider is rendering too large in view.
Root Cause
The image source dimensions are not being properly scaled .
Description of Change
Implementing a custom resizing logic to resize the image before rendering it on the slider to ensure optimal display and improve user experience.
Validated the behaviour in the following platforms
Issues Fixed
Fixes #13258
Output