Skip to content

Fixed improper rendering of ThumbimageSource in Slider#27472

Closed
NirmalKumarYuvaraj wants to merge 18 commits intodotnet:mainfrom
NirmalKumarYuvaraj:fix-13258
Closed

Fixed improper rendering of ThumbimageSource in Slider#27472
NirmalKumarYuvaraj wants to merge 18 commits intodotnet:mainfrom
NirmalKumarYuvaraj:fix-13258

Conversation

@NirmalKumarYuvaraj
Copy link
Contributor

@NirmalKumarYuvaraj NirmalKumarYuvaraj commented Jan 30, 2025

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

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #13258

Output

Before After

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jan 30, 2025
Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

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

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we get the size from the default thumb drawable and avoid set a specific size here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@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);

Copy link
Member

Choose a reason for hiding this comment

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

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?

Copy link
Member

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as Android comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated the measure logic. Please let me know if you have any concerns.

@sheiksyedm sheiksyedm added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Jan 30, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@NirmalKumarYuvaraj NirmalKumarYuvaraj marked this pull request as ready for review February 4, 2025 04:49
@NirmalKumarYuvaraj NirmalKumarYuvaraj requested a review from a team as a code owner February 4, 2025 04:49
Copy link
Contributor

Choose a reason for hiding this comment

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

Test failing on iOS with small differences:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz , i have attached the snapshots. please let me know if you have any concerns.

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jfversluis
Copy link
Member

@NirmalKumarYuvaraj please address feedback, thanks!

@NirmalKumarYuvaraj
Copy link
Contributor Author

@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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Used using statements to ensure proper disposal of BitmapDrawable:

using (BitmapDrawable finalDrawable = new BitmapDrawable(context.Resources, bitmap))
{
    seekBar.SetThumb(finalDrawable);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz , I have updated the code changes. please let me know if you have any concerns.

@jfversluis jfversluis added this to the .NET 9 SR6 milestone Feb 28, 2025
@jsuarezruiz
Copy link
Contributor

/rebase

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen moved this from Todo to Ready To Review in MAUI SDK Ongoing Mar 18, 2025
@rmarinho
Copy link
Member

/rebase

Copy link
Member

@rmarinho rmarinho left a comment

Choose a reason for hiding this comment

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

Small comments and improvements

@github-project-automation github-project-automation bot moved this from Ready To Review to Changes Requested in MAUI SDK Ongoing Mar 18, 2025
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

// Validate thumb size
if (thumbSize <= 0)
    return;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

static void SetThumbDrawable(SeekBar seekBar, Android.Content.Context context, Drawable thumbDrawable)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

// Check if we're setting the same drawable to avoid unnecessary work
if (ReferenceEquals(seekBar.Thumb, thumbDrawable))
    return;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the code changes

@PureWeen PureWeen modified the milestones: .NET 9 SR9, .NET 9 SR10 Jul 3, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR10, .NET 9 SR12 Aug 4, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR12, .NET 10 SR1 Sep 10, 2025
Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

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

@NirmalKumarYuvaraj Could you rebase and fix the conflicts? Thanks in advance.

@PureWeen PureWeen modified the milestones: .NET 10 SR1, .NET 10.0 SR2 Nov 4, 2025
@PureWeen PureWeen modified the milestones: .NET 10.0 SR2, .NET 10 SR4 Dec 13, 2025
@PureWeen PureWeen modified the milestones: .NET 10.0 SR4, .NET 10 SR5 Jan 21, 2026
@kubaflo
Copy link
Contributor

kubaflo commented Feb 14, 2026

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

@NirmalKumarYuvaraj
Copy link
Contributor Author

@kubaflo , Could not reopen this PR. so created new one #34064

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-slider Slider community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Slider] MAUI Slider thumb image is big on android

9 participants