Fix rounding resulting in choppy timing animations

Summary: Casting to long too early here and dropping some precision, resulting in skipped (not dropped) frames.

Reviewed By: sahrens

Differential Revision: D3819153

fbshipit-source-id: 83676cf4c9129638348890c74d563db121049e4a
This commit is contained in:
Felix Oghina 2016-09-07 06:10:24 -07:00 committed by Facebook Github Bot 3
parent de3457f31d
commit 40baf6a5b9
1 changed files with 5 additions and 4 deletions

View File

@ -19,6 +19,9 @@ import com.facebook.react.bridge.ReadableMap;
*/
class FrameBasedAnimationDriver extends AnimationDriver {
// 60FPS
private static final double FRAME_TIME_MILLIS = 1000d / 60d;
private long mStartFrameTimeNanos = -1;
private final double[] mFrames;
private final double mToValue;
@ -40,10 +43,8 @@ class FrameBasedAnimationDriver extends AnimationDriver {
mStartFrameTimeNanos = frameTimeNanos;
mFromValue = mAnimatedValue.mValue;
}
long timeFromStartNanos = (frameTimeNanos - mStartFrameTimeNanos);
// frames are calculated at 60FPS, to get index by a given time offset from the start of the
// animation, we take the time diff in millisecond and divide it by 60 frames per 1000ms.
int frameIndex = (int) (timeFromStartNanos / 1000000L * 60L / 1000L);
long timeFromStartMillis = (frameTimeNanos - mStartFrameTimeNanos) / 1000000;
int frameIndex = (int) (timeFromStartMillis / FRAME_TIME_MILLIS);
if (frameIndex < 0) {
throw new IllegalStateException("Calculated frame index should never be lower than 0");
} else if (mHasFinished) {