Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Natively loopable animations #9513

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion Libraries/Animated/src/AnimatedImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,15 @@ type TimingAnimationConfig = AnimationConfig & {
easing?: (value: number) => number,
duration?: number,
delay?: number,
shouldLoop?: bool,
};

type TimingAnimationConfigSingle = AnimationConfig & {
toValue: number | AnimatedValue,
easing?: (value: number) => number,
duration?: number,
delay?: number,
shouldLoop?: bool,
};

let _easeInOut;
Expand All @@ -236,6 +238,7 @@ class TimingAnimation extends Animation {
_toValue: any;
_duration: number;
_delay: number;
_shouldLoop: bool;
_easing: (value: number) => number;
_onUpdate: (value: number) => void;
_animationFrame: any;
Expand All @@ -250,6 +253,7 @@ class TimingAnimation extends Animation {
this._easing = config.easing !== undefined ? config.easing : easeInOut();
this._duration = config.duration !== undefined ? config.duration : 500;
this._delay = config.delay !== undefined ? config.delay : 0;
this._shouldLoop = config.shouldLoop !== undefined ? config.shouldLoop : false;
this.__isInteraction = config.isInteraction !== undefined ? config.isInteraction : true;
this._useNativeDriver = config.useNativeDriver !== undefined ? config.useNativeDriver : false;
}
Expand All @@ -265,7 +269,8 @@ class TimingAnimation extends Animation {
type: 'frames',
frames,
toValue: this._toValue,
delay: this._delay
delay: this._delay,
shouldLoop: this._shouldLoop
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FrameBasedAnimationDriver extends AnimationDriver {
private final double[] mFrames;
private final double mToValue;
private double mFromValue;
private boolean mShouldLoop;

FrameBasedAnimationDriver(ReadableMap config) {
ReadableArray frames = config.getArray("frames");
Expand All @@ -35,6 +36,7 @@ class FrameBasedAnimationDriver extends AnimationDriver {
mFrames[i] = frames.getDouble(i);
}
mToValue = config.getDouble("toValue");
mShouldLoop = config.getBoolean("shouldLoop");
}

@Override
Expand All @@ -53,9 +55,12 @@ public void runAnimationStep(long frameTimeNanos) {
}
double nextValue;
if (frameIndex >= mFrames.length - 1) {
// animation has completed, no more frames left
mHasFinished = true;
nextValue = mToValue;
if (mShouldLoop) { // looping animation, return to start
mStartFrameTimeNanos = frameTimeNanos;
} else { // animation has completed, no more frames left
mHasFinished = true;
}
} else {
nextValue = mFromValue + mFrames[frameIndex] * (mToValue - mFromValue);
}
Expand Down