mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-06-19 10:58:27 +08:00
add new config resetBeforeIteration for Animated.loop (#20561)
Summary: Fixes #20560 Pull Request resolved: https://github.com/facebook/react-native/pull/20561 Differential Revision: D14103437 Pulled By: cpojer fbshipit-source-id: 35f2b3426304248e1a28f6a88812f07414618ea2
This commit is contained in:
committed by
Facebook Github Bot
parent
65cfb9a47d
commit
53b87dcfff
@@ -417,11 +417,14 @@ const stagger = function(
|
||||
);
|
||||
};
|
||||
|
||||
type LoopAnimationConfig = {iterations: number};
|
||||
type LoopAnimationConfig = {
|
||||
iterations: number,
|
||||
resetBeforeIteration?: boolean,
|
||||
};
|
||||
|
||||
const loop = function(
|
||||
animation: CompositeAnimation,
|
||||
{iterations = -1}: LoopAnimationConfig = {},
|
||||
{iterations = -1, resetBeforeIteration = true}: LoopAnimationConfig = {},
|
||||
): CompositeAnimation {
|
||||
let isFinished = false;
|
||||
let iterationsSoFar = 0;
|
||||
@@ -436,7 +439,7 @@ const loop = function(
|
||||
callback && callback(result);
|
||||
} else {
|
||||
iterationsSoFar++;
|
||||
animation.reset();
|
||||
resetBeforeIteration && animation.reset();
|
||||
animation.start(restart);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -445,6 +445,37 @@ describe('Animated tests', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not reset animation in a loop if resetBeforeIteration is false', () => {
|
||||
const animation = {
|
||||
start: jest.fn(),
|
||||
reset: jest.fn(),
|
||||
_isUsingNativeDriver: () => false,
|
||||
};
|
||||
const cb = jest.fn();
|
||||
|
||||
const loop = Animated.loop(animation, {resetBeforeIteration: false});
|
||||
|
||||
expect(animation.start).not.toBeCalled();
|
||||
|
||||
loop.start(cb);
|
||||
|
||||
expect(animation.start).toBeCalled();
|
||||
expect(animation.reset).not.toBeCalled();
|
||||
expect(cb).not.toBeCalled();
|
||||
|
||||
animation.start.mock.calls[0][0]({finished: true}); // End of loop 1
|
||||
expect(animation.reset).not.toBeCalled();
|
||||
expect(cb).not.toBeCalled();
|
||||
|
||||
animation.start.mock.calls[0][0]({finished: true}); // End of loop 2
|
||||
expect(animation.reset).not.toBeCalled();
|
||||
expect(cb).not.toBeCalled();
|
||||
|
||||
animation.start.mock.calls[0][0]({finished: true}); // End of loop 3
|
||||
expect(animation.reset).not.toBeCalled();
|
||||
expect(cb).not.toBeCalled();
|
||||
});
|
||||
|
||||
describe('Animated Parallel', () => {
|
||||
it('works with an empty parallel', () => {
|
||||
const cb = jest.fn();
|
||||
|
||||
Reference in New Issue
Block a user