diff --git a/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimation.kt b/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimation.kt index 4fd1b8284c..c4644009b3 100644 --- a/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimation.kt +++ b/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimation.kt @@ -17,6 +17,7 @@ import androidx.compose.ui.graphics.drawscope.drawIntoCanvas import androidx.compose.ui.graphics.nativeCanvas import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ScaleFactor +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.IntSize import com.airbnb.lottie.AsyncUpdates import com.airbnb.lottie.LottieComposition @@ -101,6 +102,7 @@ fun LottieAnimation( if (composition == null || composition.duration == 0f) return Box(modifier) val bounds = composition.bounds + val context = LocalContext.current Canvas( modifier = modifier .lottieSize(bounds.width(), bounds.height()) @@ -131,7 +133,12 @@ fun LottieAnimation( drawable.maintainOriginalImageBounds = maintainOriginalImageBounds drawable.clipToCompositionBounds = clipToCompositionBounds drawable.clipTextToBoundingBox = clipTextToBoundingBox - drawable.progress = progress() + val markerForAnimationsDisabled = drawable.markerForAnimationsDisabled + if (!drawable.animationsEnabled(context) && markerForAnimationsDisabled != null) { + drawable.progress = markerForAnimationsDisabled.startFrame + } else { + drawable.progress = progress() + } drawable.setBounds(0, 0, bounds.width(), bounds.height()) drawable.draw(canvas.nativeCanvas, matrix) } diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java index edcb668b62..38abec2684 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java @@ -823,7 +823,7 @@ public void playAnimation() { } computeRenderMode(); - if (animationsEnabled() || getRepeatCount() == 0) { + if (animationsEnabled(getContext()) || getRepeatCount() == 0) { if (isVisible()) { animator.playAnimation(); onVisibleAction = OnVisibleAction.NONE; @@ -831,7 +831,7 @@ public void playAnimation() { onVisibleAction = OnVisibleAction.PLAY; } } - if (!animationsEnabled()) { + if (!animationsEnabled(getContext())) { Marker markerForAnimationsDisabled = getMarkerForAnimationsDisabled(); if (markerForAnimationsDisabled != null) { setFrame((int) markerForAnimationsDisabled.startFrame); @@ -853,7 +853,8 @@ public void playAnimation() { * * @return The first non-null marker from the list of allowed reduced motion markers, or null if no such marker is found. */ - private Marker getMarkerForAnimationsDisabled() { + @RestrictTo(RestrictTo.Scope.LIBRARY) + public Marker getMarkerForAnimationsDisabled() { Marker marker = null; for (String markerName : ALLOWED_REDUCED_MOTION_MARKERS) { marker = composition.getMarker(markerName); @@ -885,7 +886,7 @@ public void resumeAnimation() { } computeRenderMode(); - if (animationsEnabled() || getRepeatCount() == 0) { + if (animationsEnabled(getContext()) || getRepeatCount() == 0) { if (isVisible()) { animator.resumeAnimation(); onVisibleAction = OnVisibleAction.NONE; @@ -893,7 +894,7 @@ public void resumeAnimation() { onVisibleAction = OnVisibleAction.RESUME; } } - if (!animationsEnabled()) { + if (!animationsEnabled(getContext())) { setFrame((int) (getSpeed() < 0 ? getMinFrame() : getMaxFrame())); animator.endAnimation(); if (!isVisible()) { @@ -1244,12 +1245,12 @@ boolean isAnimatingOrWillAnimateOnVisible() { } } - private boolean animationsEnabled() { + public boolean animationsEnabled(Context context) { if (ignoreSystemAnimationsDisabled) { return true; } return systemAnimationsEnabled && - L.getReducedMotionOption().getCurrentReducedMotionMode(getContext()) == ReducedMotionMode.STANDARD_MOTION; + L.getReducedMotionOption().getCurrentReducedMotionMode(context) == ReducedMotionMode.STANDARD_MOTION; } /**