KEMBAR78
[Android] Sort gradient stops by offset by kubaflo · Pull Request #31318 · dotnet/maui · GitHub
Skip to content

Conversation

kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Aug 24, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

Updated the gradient stop processing to order stops by their offset before populating color and offset arrays. This ensures gradients are rendered correctly according to stop positions.

Applied the same approach as in here: https://github.dev/kubaflo/maui/blob/be7d14bd4c4c1c31f3dad7bc9e836374aa38c7b1/src/Core/src/Graphics/PaintExtensions.Android.cs#L105

Issues Fixed

Fixes #31314

Updated the gradient stop processing to order stops by their offset before populating color and offset arrays. This ensures gradients are rendered correctly according to stop positions.
@Copilot Copilot AI review requested due to automatic review settings August 24, 2025 18:09
@kubaflo kubaflo requested a review from a team as a code owner August 24, 2025 18:09
@kubaflo kubaflo self-assigned this Aug 24, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes Android gradient rendering by ensuring gradient stops are processed in the correct order. The issue was that gradient stops were being rendered in their declaration order rather than sorted by their offset position, causing incorrect gradient appearance.

  • Sorts gradient stops by their offset value before processing colors and positions
  • Ensures gradients render correctly according to stop positions rather than declaration order

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Aug 24, 2025
@jfversluis
Copy link
Member

jfversluis commented Aug 24, 2025

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jfversluis jfversluis added platform/android area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing labels Aug 24, 2025
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).


int count = 0;
foreach (var orderStop in orderStops)
foreach (var orderStop in orderStops.OrderBy(s => s.Offset))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can sort manually? Can use Sortthat modifies the list in place avoiding the overhead of creating a new collection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But: If some code elsewhere is depending on the original ordering (e.g., holding onto indices or iterating concurrently), we may break that assumption.

@jfversluis jfversluis changed the base branch from main to inflight/current September 9, 2025 14:25
@jfversluis jfversluis added this to the .NET 9 SR11 milestone Sep 9, 2025
@jfversluis jfversluis merged commit 1fc132f into dotnet:inflight/current Sep 9, 2025
78 of 80 checks passed
PureWeen pushed a commit that referenced this pull request Sep 18, 2025
* [Android] Sort gradient stops by offset

Updated the gradient stop processing to order stops by their offset before populating color and offset arrays. This ensures gradients are rendered correctly according to stop positions.

* Added a UITest

* Add snapshots

---------

Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
PureWeen pushed a commit that referenced this pull request Sep 18, 2025
* [Android] Sort gradient stops by offset

Updated the gradient stop processing to order stops by their offset before populating color and offset arrays. This ensures gradients are rendered correctly according to stop positions.

* Added a UITest

* Add snapshots

---------

Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
github-actions bot pushed a commit that referenced this pull request Sep 18, 2025
* [Android] Sort gradient stops by offset

Updated the gradient stop processing to order stops by their offset before populating color and offset arrays. This ensures gradients are rendered correctly according to stop positions.

* Added a UITest

* Add snapshots

---------

Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
github-actions bot pushed a commit that referenced this pull request Sep 23, 2025
* [Android] Sort gradient stops by offset

Updated the gradient stop processing to order stops by their offset before populating color and offset arrays. This ensures gradients are rendered correctly according to stop positions.

* Added a UITest

* Add snapshots

---------

Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
github-actions bot pushed a commit that referenced this pull request Sep 23, 2025
* [Android] Sort gradient stops by offset

Updated the gradient stop processing to order stops by their offset before populating color and offset arrays. This ensures gradients are rendered correctly according to stop positions.

* Added a UITest

* Add snapshots

---------

Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
@github-actions github-actions bot locked and limited conversation to collaborators Oct 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing community ✨ Community Contribution platform/android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LinearGradientBrush can not work

3 participants