File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
lib/java/com/google/android/material/loadingindicator Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -121,14 +121,21 @@ public void onAnimationRepeat(Animator animation) {
121121
122122 /** Updates the indicator's rotation based on current playtime. */
123123 private void updateIndicatorRotation (int playtime ) {
124+ float morphFactorBase = morphFactorTarget - 1 ;
125+ float morphFactorPerShape = morphFactor - morphFactorBase ;
126+ float timeFactorPerShape = (float ) playtime / DURATION_PER_SHAPE_IN_MS ;
127+ if (timeFactorPerShape == 1f ) {
128+ // The animation on repeat is called before the playtime restart. So if playtime reaches the
129+ // end, we take it as restarted as 0.
130+ timeFactorPerShape = 0f ;
131+ }
124132 // Initial rotation.
125- indicatorState .rotationDegree = CONSTANT_ROTATION_PER_SHAPE_DEGREES * (morphFactorTarget - 1 );
126- // Constant rotation for the current shape.
127- indicatorState .rotationDegree +=
128- CONSTANT_ROTATION_PER_SHAPE_DEGREES * ((float ) playtime / DURATION_PER_SHAPE_IN_MS );
129- // Rotation driven by spring animation.
130133 indicatorState .rotationDegree =
131- (CONSTANT_ROTATION_PER_SHAPE_DEGREES + EXTRA_ROTATION_PER_SHAPE_DEGREES ) * morphFactor ;
134+ (CONSTANT_ROTATION_PER_SHAPE_DEGREES + EXTRA_ROTATION_PER_SHAPE_DEGREES ) * morphFactorBase ;
135+ // Constant rotation.
136+ indicatorState .rotationDegree += CONSTANT_ROTATION_PER_SHAPE_DEGREES * timeFactorPerShape ;
137+ // Rotation driven by spring animation.
138+ indicatorState .rotationDegree += EXTRA_ROTATION_PER_SHAPE_DEGREES * morphFactorPerShape ;
132139
133140 indicatorState .rotationDegree %= 360 ;
134141 }
You can’t perform that action at this time.
0 commit comments