mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Follow up to address Spencer's feedback on D13811035 With the spread of AnimatedImplementation, it's impossible to tell whether AnimatedMock gets out of date. This change coupled with D13953915 forces anyone adding to AnimatedImplementation to consider the mock. Reviewed By: sahrens Differential Revision: D13965249 fbshipit-source-id: e324364a75abd42d89d6222151453021618bcd5d
139 lines
3.6 KiB
JavaScript
139 lines
3.6 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
* @format
|
|
*/
|
|
'use strict';
|
|
|
|
const {AnimatedEvent, attachNativeEvent} = require('./AnimatedEvent');
|
|
const AnimatedImplementation = require('AnimatedImplementation');
|
|
const AnimatedInterpolation = require('./nodes/AnimatedInterpolation');
|
|
const AnimatedNode = require('./nodes/AnimatedNode');
|
|
const AnimatedProps = require('./nodes/AnimatedProps');
|
|
const AnimatedValue = require('./nodes/AnimatedValue');
|
|
const AnimatedValueXY = require('./nodes/AnimatedValueXY');
|
|
|
|
const createAnimatedComponent = require('./createAnimatedComponent');
|
|
|
|
import type {EndCallback} from './animations/Animation';
|
|
import type {TimingAnimationConfig} from './animations/TimingAnimation';
|
|
import type {DecayAnimationConfig} from './animations/DecayAnimation';
|
|
import type {SpringAnimationConfig} from './animations/SpringAnimation';
|
|
import type {Mapping, EventConfig} from './AnimatedEvent';
|
|
|
|
/**
|
|
* Animations are a source of flakiness in snapshot testing. This mock replaces
|
|
* animation functions from AnimatedImplementation with empty animations for
|
|
* predictability in tests.
|
|
*/
|
|
type CompositeAnimation = {
|
|
start: (callback?: ?EndCallback) => void,
|
|
stop: () => void,
|
|
reset: () => void,
|
|
_startNativeLoop: (iterations?: number) => void,
|
|
_isUsingNativeDriver: () => boolean,
|
|
};
|
|
|
|
const emptyAnimation = {
|
|
start: () => {},
|
|
stop: () => {},
|
|
reset: () => {},
|
|
_startNativeLoop: () => {},
|
|
_isUsingNativeDriver: () => {
|
|
return false;
|
|
},
|
|
};
|
|
|
|
const spring = function(
|
|
value: AnimatedValue | AnimatedValueXY,
|
|
config: SpringAnimationConfig,
|
|
): CompositeAnimation {
|
|
return emptyAnimation;
|
|
};
|
|
|
|
const timing = function(
|
|
value: AnimatedValue | AnimatedValueXY,
|
|
config: TimingAnimationConfig,
|
|
): CompositeAnimation {
|
|
return emptyAnimation;
|
|
};
|
|
|
|
const decay = function(
|
|
value: AnimatedValue | AnimatedValueXY,
|
|
config: DecayAnimationConfig,
|
|
): CompositeAnimation {
|
|
return emptyAnimation;
|
|
};
|
|
|
|
const sequence = function(
|
|
animations: Array<CompositeAnimation>,
|
|
): CompositeAnimation {
|
|
return emptyAnimation;
|
|
};
|
|
|
|
type ParallelConfig = {
|
|
stopTogether?: boolean,
|
|
};
|
|
const parallel = function(
|
|
animations: Array<CompositeAnimation>,
|
|
config?: ?ParallelConfig,
|
|
): CompositeAnimation {
|
|
return emptyAnimation;
|
|
};
|
|
|
|
const delay = function(time: number): CompositeAnimation {
|
|
return emptyAnimation;
|
|
};
|
|
|
|
const stagger = function(
|
|
time: number,
|
|
animations: Array<CompositeAnimation>,
|
|
): CompositeAnimation {
|
|
return emptyAnimation;
|
|
};
|
|
|
|
type LoopAnimationConfig = {iterations: number};
|
|
|
|
const loop = function(
|
|
animation: CompositeAnimation,
|
|
{iterations = -1}: LoopAnimationConfig = {},
|
|
): CompositeAnimation {
|
|
return emptyAnimation;
|
|
};
|
|
|
|
const event = function(argMapping: Array<?Mapping>, config?: EventConfig): any {
|
|
return null;
|
|
};
|
|
|
|
module.exports = {
|
|
Value: AnimatedValue,
|
|
ValueXY: AnimatedValueXY,
|
|
Interpolation: AnimatedInterpolation,
|
|
Node: AnimatedNode,
|
|
decay,
|
|
timing,
|
|
spring,
|
|
add: AnimatedImplementation.add,
|
|
subtract: AnimatedImplementation.subtract,
|
|
divide: AnimatedImplementation.divide,
|
|
multiply: AnimatedImplementation.multiply,
|
|
modulo: AnimatedImplementation.modulo,
|
|
diffClamp: AnimatedImplementation.diffClamp,
|
|
delay,
|
|
sequence,
|
|
parallel,
|
|
stagger,
|
|
loop,
|
|
event,
|
|
createAnimatedComponent,
|
|
attachNativeEvent,
|
|
forkEvent: AnimatedImplementation.forkEvent,
|
|
unforkEvent: AnimatedImplementation.unforkEvent,
|
|
Event: AnimatedEvent,
|
|
__PropsOnlyForTests: AnimatedProps,
|
|
};
|