Skip to content

Commit ef9d1fb

Browse files
kmagierafacebook-github-bot
authored andcommittedFeb 22, 2018
Fix IllegalStateException in looped timing native animation
Summary: This PR fixes regression introduced in #17896 with IllegalStateException being thrown in FrameBasedAnimationDriver. After investigating it seemed that the root cause was the code responsible for looping animations that was setting next frame time by adding the frame interval to the current time. In some circumstances the next frame would run earlier than that and as a result the calculated frame index was negative. Here is the stacktrace as reported by axemclion https://github.com/facebook/react-native/pull/17896/files#r170007224 ``` Caused by: java.lang.IllegalStateException: Calculated frame index should never be lower than 0 at com.facebook.react.animated.FrameBasedAnimationDriver.runAnimationStep(FrameBasedAnimationDriver.java:60) at com.facebook.react.animated.NativeAnimatedNodesManager.runUpdates(NativeAnimatedNodesManager.java:444) at com.facebook.react.animated.NativeAnimatedModule$1.doFrameGuarded(NativeAnimatedModule.java:100) at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29) ``` Run native animated tests suite. Run RNTester and scroll to the loop animation and see it working correctly [ANDROID][BUGFIX][Animated] - Fix exception thrown by timing animation when looping Closes #18061 Differential Revision: D7059335 Pulled By: hramos fbshipit-source-id: b08dfd1398d028eeeabeb11863743666379da374
1 parent cf0193f commit ef9d1fb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
 

‎ReactAndroid/src/main/java/com/facebook/react/animated/FrameBasedAnimationDriver.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public void resetConfig(ReadableMap config) {
5252
public void runAnimationStep(long frameTimeNanos) {
5353
if (mStartFrameTimeNanos < 0) {
5454
mStartFrameTimeNanos = frameTimeNanos;
55-
mFromValue = mAnimatedValue.mValue;
55+
if (mCurrentLoop == 1) {
56+
// initiate start value when animation runs for the first time
57+
mFromValue = mAnimatedValue.mValue;
58+
}
5659
}
5760
long timeFromStartMillis = (frameTimeNanos - mStartFrameTimeNanos) / 1000000;
5861
int frameIndex = (int) Math.round(timeFromStartMillis / FRAME_TIME_MILLIS);
@@ -66,7 +69,7 @@ public void runAnimationStep(long frameTimeNanos) {
6669
if (frameIndex >= mFrames.length - 1) {
6770
nextValue = mToValue;
6871
if (mIterations == -1 || mCurrentLoop < mIterations) { // looping animation, return to start
69-
mStartFrameTimeNanos = frameTimeNanos + ((long) FRAME_TIME_MILLIS) * 1000000L;
72+
mStartFrameTimeNanos = -1;
7073
mCurrentLoop++;
7174
} else { // animation has completed, no more frames left
7275
mHasFinished = true;

0 commit comments

Comments
 (0)
Please sign in to comment.