Skip to content

Commit

Permalink
Use Animated.loop(), when possible, to limit JS thread utilization
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesreggio committed Aug 16, 2018
1 parent d9cbb61 commit 34e3cb7
Showing 1 changed file with 6 additions and 15 deletions.
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

0 comments on commit 34e3cb7

Please sign in to comment.