Skip to content

Commit e169ffc

Browse files
pubiqqpaulfthomas
authored andcommitted
[LoadingIndicator] Fix handling of negative morphFraction
Resolves #4642 GIT_ORIGIN_REV_ID=5450fea31c772687203657b010cf228feb1686f6 PiperOrigin-RevId: 734911732
1 parent 672f66f commit e169ffc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/java/com/google/android/material/loadingindicator/LoadingIndicatorDrawingDelegate.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import androidx.graphics.shapes.RoundedPolygon;
3333
import androidx.graphics.shapes.Shapes_androidKt;
3434
import com.google.android.material.color.MaterialColors;
35+
import com.google.android.material.math.MathUtils;
3536
import com.google.android.material.shape.MaterialShapes;
3637

3738
class LoadingIndicatorDrawingDelegate {
@@ -116,9 +117,10 @@ void drawIndicator(
116117
canvas.rotate(indicatorState.rotationDegree);
117118
// Draws the shape morph.
118119
indicatorPath.rewind();
120+
int shapeMorphFraction = (int) Math.floor(indicatorState.morphFraction);
119121
int fractionAmongAllShapes =
120-
(int) (indicatorState.morphFraction % INDETERMINATE_MORPH_SEQUENCE.length);
121-
float fractionPerShape = indicatorState.morphFraction % 1;
122+
MathUtils.floorMod(shapeMorphFraction, INDETERMINATE_MORPH_SEQUENCE.length);
123+
float fractionPerShape = indicatorState.morphFraction - shapeMorphFraction;
122124
Shapes_androidKt.toPath(
123125
INDETERMINATE_MORPH_SEQUENCE[fractionAmongAllShapes], fractionPerShape, indicatorPath);
124126
// We need to apply the scaling to the path directly, instead of on the canvas, to avoid the

0 commit comments

Comments
 (0)