|
9 | 9 |
|
10 | 10 | import Animated from '..';
|
11 | 11 | import Easing from '../../Easing';
|
| 12 | +import AnimatedImplementation from '../../../vendor/react-native/Animated/AnimatedImplementation'; |
12 | 13 |
|
13 | 14 | const AnimatedInterpolation = Animated.Interpolation;
|
14 | 15 |
|
@@ -329,4 +330,74 @@ describe('Animated', () => {
|
329 | 330 | expect(interpolation(2 / 3)).toBe('rgba(0, 0, 0, 0.667)');
|
330 | 331 | });
|
331 | 332 | });
|
| 333 | + |
| 334 | + describe('sequence and loop', () => { |
| 335 | + it('supports restarting sequence after it was stopped during execution', () => { |
| 336 | + const anim1 = { start: jest.fn(), stop: jest.fn() }; |
| 337 | + const anim2 = { start: jest.fn(), stop: jest.fn() }; |
| 338 | + const cb = jest.fn(); |
| 339 | + |
| 340 | + const seq = AnimatedImplementation.sequence([anim1, anim2]); |
| 341 | + |
| 342 | + seq.start(cb); |
| 343 | + |
| 344 | + anim1.start.mock.calls[0][0]({ finished: true }); |
| 345 | + seq.stop(); |
| 346 | + |
| 347 | + // anim1 should be finished so anim2 should also start |
| 348 | + expect(anim1.start).toHaveBeenCalledTimes(1); |
| 349 | + expect(anim2.start).toHaveBeenCalledTimes(1); |
| 350 | + |
| 351 | + seq.start(cb); |
| 352 | + |
| 353 | + // after restart the sequence should resume from the anim2 |
| 354 | + expect(anim1.start).toHaveBeenCalledTimes(1); |
| 355 | + expect(anim2.start).toHaveBeenCalledTimes(2); |
| 356 | + }); |
| 357 | + |
| 358 | + it('supports restarting sequence after it was finished without a reset', () => { |
| 359 | + const anim1 = { start: jest.fn(), stop: jest.fn() }; |
| 360 | + const anim2 = { start: jest.fn(), stop: jest.fn() }; |
| 361 | + const cb = jest.fn(); |
| 362 | + |
| 363 | + const seq = AnimatedImplementation.sequence([anim1, anim2]); |
| 364 | + |
| 365 | + seq.start(cb); |
| 366 | + anim1.start.mock.calls[0][0]({ finished: true }); |
| 367 | + anim2.start.mock.calls[0][0]({ finished: true }); |
| 368 | + |
| 369 | + // sequence should be finished |
| 370 | + expect(cb).toBeCalledWith({ finished: true }); |
| 371 | + |
| 372 | + seq.start(cb); |
| 373 | + |
| 374 | + // sequence should successfully restart from the anim1 |
| 375 | + expect(anim1.start).toHaveBeenCalledTimes(2); |
| 376 | + expect(anim2.start).toHaveBeenCalledTimes(1); |
| 377 | + }); |
| 378 | + |
| 379 | + it('restarts sequence normally in a loop if resetBeforeIteration is false', () => { |
| 380 | + const anim1 = { start: jest.fn(), stop: jest.fn() }; |
| 381 | + const anim2 = { start: jest.fn(), stop: jest.fn() }; |
| 382 | + const seq = AnimatedImplementation.sequence([anim1, anim2]); |
| 383 | + |
| 384 | + const loop = AnimatedImplementation.loop(seq, { |
| 385 | + resetBeforeIteration: false |
| 386 | + }); |
| 387 | + |
| 388 | + loop.start(); |
| 389 | + |
| 390 | + expect(anim1.start).toHaveBeenCalledTimes(1); |
| 391 | + |
| 392 | + anim1.start.mock.calls[0][0]({ finished: true }); |
| 393 | + |
| 394 | + expect(anim2.start).toHaveBeenCalledTimes(1); |
| 395 | + |
| 396 | + anim2.start.mock.calls[0][0]({ finished: true }); |
| 397 | + |
| 398 | + // after anim2 is finished, the sequence is finished, |
| 399 | + // hence the loop iteration is finished, so the next iteration starts |
| 400 | + expect(anim1.start).toHaveBeenCalledTimes(2); |
| 401 | + }); |
| 402 | + }); |
332 | 403 | });
|
0 commit comments