Fix rounding-off error on progress calculation with time-remapped layer (#1372)
diff --git a/lottie/src/main/java/com/airbnb/lottie/model/layer/CompositionLayer.java b/lottie/src/main/java/com/airbnb/lottie/model/layer/CompositionLayer.java
index 28e6e85..7e9bf1d 100644
--- a/lottie/src/main/java/com/airbnb/lottie/model/layer/CompositionLayer.java
+++ b/lottie/src/main/java/com/airbnb/lottie/model/layer/CompositionLayer.java
@@ -116,10 +116,13 @@
@Override public void setProgress(@FloatRange(from = 0f, to = 1f) float progress) {
super.setProgress(progress);
if (timeRemapping != null) {
- float duration = lottieDrawable.getComposition().getDuration();
- float compositionDelayTime = layerModel.getComposition().getStartFrame() / layerModel.getComposition().getFrameRate() * 1000;
- long remappedTime = (long) (timeRemapping.getValue() * 1000 - compositionDelayTime);
- progress = remappedTime / duration;
+ // The duration has 0.01 frame offset to show end of animation properly.
+ // https://github.com/airbnb/lottie-android/pull/766
+ // Ignore this offset for calculating time-remapping because time-remapping value is based on original duration.
+ float durationFrames = lottieDrawable.getComposition().getDurationFrames() + 0.01f;
+ float compositionDelayFrames = layerModel.getComposition().getStartFrame();
+ float remappedFrames = timeRemapping.getValue() * layerModel.getComposition().getFrameRate() - compositionDelayFrames;
+ progress = remappedFrames / durationFrames;
}
if (layerModel.getTimeStretch() != 0) {
progress /= layerModel.getTimeStretch();