|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @flow |
| 8 | + * @format |
| 9 | + */ |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +const AnimatedImplementation = require('AnimatedImplementation'); |
| 13 | +const AnimatedValueXY = require('./nodes/AnimatedValueXY'); |
| 14 | +const AnimatedValue = require('./nodes/AnimatedValue'); |
| 15 | + |
| 16 | +import type {EndCallback} from './animations/Animation'; |
| 17 | +import type {TimingAnimationConfig} from './animations/TimingAnimation'; |
| 18 | +import type {DecayAnimationConfig} from './animations/DecayAnimation'; |
| 19 | +import type {SpringAnimationConfig} from './animations/SpringAnimation'; |
| 20 | +import type {Mapping, EventConfig} from './AnimatedEvent'; |
| 21 | + |
| 22 | +/** |
| 23 | + * Animations are a source of flakiness in snapshot testing. This mock replaces |
| 24 | + * animation functions from AnimatedImplementation with empty animations for |
| 25 | + * predictability in tests. |
| 26 | + */ |
| 27 | +type CompositeAnimation = { |
| 28 | + start: (callback?: ?EndCallback) => void, |
| 29 | + stop: () => void, |
| 30 | + reset: () => void, |
| 31 | + _startNativeLoop: (iterations?: number) => void, |
| 32 | + _isUsingNativeDriver: () => boolean, |
| 33 | +}; |
| 34 | + |
| 35 | +const emptyAnimation = { |
| 36 | + start: () => {}, |
| 37 | + stop: () => {}, |
| 38 | + reset: () => {}, |
| 39 | + _startNativeLoop: () => {}, |
| 40 | + _isUsingNativeDriver: () => { |
| 41 | + return false; |
| 42 | + }, |
| 43 | +}; |
| 44 | + |
| 45 | +const spring = function( |
| 46 | + value: AnimatedValue | AnimatedValueXY, |
| 47 | + config: SpringAnimationConfig, |
| 48 | +): CompositeAnimation { |
| 49 | + return emptyAnimation; |
| 50 | +}; |
| 51 | + |
| 52 | +const timing = function( |
| 53 | + value: AnimatedValue | AnimatedValueXY, |
| 54 | + config: TimingAnimationConfig, |
| 55 | +): CompositeAnimation { |
| 56 | + return emptyAnimation; |
| 57 | +}; |
| 58 | + |
| 59 | +const decay = function( |
| 60 | + value: AnimatedValue | AnimatedValueXY, |
| 61 | + config: DecayAnimationConfig, |
| 62 | +): CompositeAnimation { |
| 63 | + return emptyAnimation; |
| 64 | +}; |
| 65 | + |
| 66 | +const sequence = function( |
| 67 | + animations: Array<CompositeAnimation>, |
| 68 | +): CompositeAnimation { |
| 69 | + return emptyAnimation; |
| 70 | +}; |
| 71 | + |
| 72 | +type ParallelConfig = { |
| 73 | + stopTogether?: boolean, |
| 74 | +}; |
| 75 | +const parallel = function( |
| 76 | + animations: Array<CompositeAnimation>, |
| 77 | + config?: ?ParallelConfig, |
| 78 | +): CompositeAnimation { |
| 79 | + return emptyAnimation; |
| 80 | +}; |
| 81 | + |
| 82 | +const delay = function(time: number): CompositeAnimation { |
| 83 | + return emptyAnimation; |
| 84 | +}; |
| 85 | + |
| 86 | +const stagger = function( |
| 87 | + time: number, |
| 88 | + animations: Array<CompositeAnimation>, |
| 89 | +): CompositeAnimation { |
| 90 | + return emptyAnimation; |
| 91 | +}; |
| 92 | + |
| 93 | +type LoopAnimationConfig = {iterations: number}; |
| 94 | + |
| 95 | +const loop = function( |
| 96 | + animation: CompositeAnimation, |
| 97 | + {iterations = -1}: LoopAnimationConfig = {}, |
| 98 | +): CompositeAnimation { |
| 99 | + return emptyAnimation; |
| 100 | +}; |
| 101 | + |
| 102 | +const event = function(argMapping: Array<?Mapping>, config?: EventConfig): any { |
| 103 | + return null; |
| 104 | +}; |
| 105 | + |
| 106 | +module.exports = { |
| 107 | + ...AnimatedImplementation, |
| 108 | + decay, |
| 109 | + timing, |
| 110 | + spring, |
| 111 | + delay, |
| 112 | + sequence, |
| 113 | + parallel, |
| 114 | + stagger, |
| 115 | + loop, |
| 116 | + event, |
| 117 | +}; |
0 commit comments