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

Use Animated.loop(), when possible, to limit JS thread utilization #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions createAnimatableComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export default function createAnimatableComponent(WrappedComponent) {
const { animationValue, compiledAnimation } = this.state;
const { direction, iterationCount, useNativeDriver } = this.props;
let easing = this.props.easing || compiledAnimation.easing || 'ease';
let currentIteration = iteration || 0;
const currentIteration = iteration || 0;
const fromValue = getAnimationOrigin(currentIteration, direction);
const toValue = getAnimationTarget(currentIteration, direction);
animationValue.setValue(fromValue);
Expand All @@ -411,21 +411,12 @@ export default function createAnimatableComponent(WrappedComponent) {
useNativeDriver,
delay: iterationDelay || 0,
};
const iterations = iterationCount === 'infinite' ? -1 : iterationCount;

Animated.timing(animationValue, config).start(endState => {
currentIteration += 1;
if (
endState.finished &&
this.props.animation &&
(iterationCount === 'infinite' || currentIteration < iterationCount)
) {
this.startAnimation(
duration,
currentIteration,
iterationDelay,
callback,
);
} else if (callback) {
Animated.loop(Animated.timing(animationValue, config), {
iterations,
}).start(endState => {
if (callback) {
callback(endState);
}
});
Expand Down