Skip to content

Commit

Permalink
Fix rounding-off error on progress calculation (#346)
Browse files Browse the repository at this point in the history
I fix a blinking issue when change lottie progress. The duration of
compositon has offset in LottieCompositionParser (parameters.endFrame =
reader.nextDouble() - 0.01), but progress calculate is based on the
original value(no-offset), the function roundProgress() will caculate a
error progress.

The issue is same as: airbnb/lottie-android#1372.

---------

Co-authored-by: Xavier Hainaux <xavier.hainaux@gmail.com>
  • Loading branch information
yunlinos and xvrh authored May 12, 2024
1 parent d0fed17 commit 3c58936
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/src/composition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ class LottieComposition {
fps ??= frameRate.framesPerSecond;
assert(!fps.isNaN && fps.isFinite && !fps.isNegative);

var totalFrameCount = seconds * fps;
var noOffsetDurationFrames = durationFrames + 0.01;
var totalFrameCount = (noOffsetDurationFrames / this.frameRate) * fps;
var frameIndex = (totalFrameCount * progress).toInt();
var roundedProgress = frameIndex / totalFrameCount;
assert(roundedProgress >= 0 && roundedProgress <= 1,
Expand Down
Binary file modified test/golden/Logo/LogoSmall_0_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/golden/Mobilo/A_0_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/golden/Mobilo/B_0_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/goldens/dynamic/opacity_interpolation_05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/goldens/dynamic/opacity_interpolation_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/goldens/dynamic/time_remapping.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/goldens/enable_render_cache.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/goldens/opacity_layers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3c58936

Please sign in to comment.