Commit cb63782
Fix color stop interpolation when positioned stop has no gap before it (#57356)
Summary:
Fixes #57345
`ColorStopUtils.getFixedColorStops()` produced incorrect positions when a
color 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 `lastDefinedIndex` was only advanced when
interpolation actually occurred (`unpositionedStops > 0`). When a positioned
stop was encountered with no unpositioned stops before it, `lastDefinedIndex`
failed 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 if` branch that advances `lastDefinedIndex` whenever
the 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
Pull Request resolved: #57356
Test Plan:
Added `testColorStopsWithPositionedStopAdjacentToUnpositionedStop` to
`ColorStopTest.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).
Reviewed By: Abbondanzo
Differential Revision: D110037894
Pulled By: javache
fbshipit-source-id: f7bc84b01f88aa343c03d83fc3293ee744240c411 parent 3fcde34 commit cb63782
2 files changed
Lines changed: 31 additions & 0 deletions
File tree
- packages/react-native/ReactAndroid/src
- main/java/com/facebook/react/uimanager/style
- test/java/com/facebook/react/uimanager/style
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
127 | 133 | | |
128 | 134 | | |
129 | 135 | | |
| |||
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
161 | 186 | | |
0 commit comments