Fix color stop interpolation when positioned stop has no gap before it#57356
Fix color stop interpolation when positioned stop has no gap before it#57356nduaarte wants to merge 1 commit into
Conversation
|
Hi @nduaarte! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary:
Fixes #57345
ColorStopUtils.getFixedColorStops()produced incorrect positions when acolor stop with an explicit position was immediately followed by a color
stop without a position (i.e. zero unpositioned stops between them).
The root cause is that
lastDefinedIndexwas only advanced wheninterpolation actually occurred (
unpositionedStops > 0). When a positionedstop was encountered with no unpositioned stops before it,
lastDefinedIndexfailed to advance, causing the next interpolation to use a stale start
point and silently overwrite the explicitly declared position of the
skipped stop.
The fix adds an
else ifbranch that advanceslastDefinedIndexwheneverthe current stop has a defined position, even when no interpolation is
needed at that step.
Changelog:
[ANDROID] [FIXED] - Fix incorrect color stop positions in gradients when a positioned stop is immediately followed by an unpositioned stop
Test Plan:
Added
testColorStopsWithPositionedStopAdjacentToUnpositionedStoptoColorStopTest.kt, covering the exact case from the issue:Input: [red 0%, green 20%, blue (no position), yellow 80%, purple 100%]
Expected: [0.0, 0.2, 0.5, 0.8, 1.0]
Before the fix this produced [0.0, 0.267, 0.533, 0.8, 1.0].
Verified the new test passes via CI (no local Android environment available).