Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead code from animation classes #1018

Merged
merged 3 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/Animated.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import createAnimatedComponent from './createAnimatedComponent';
import decay from './animations/decay';
import timing from './animations/timing';
import spring from './animations/spring';
import TimingAnimation from './animations/TimingAnimation';
import SpringAnimation from './animations/SpringAnimation';
import DecayAnimation from './animations/DecayAnimation';
import Animation from './animations/Animation';
import {
addWhitelistedNativeProps,
addWhitelistedUIProps,
Expand All @@ -26,10 +24,18 @@ import {
import SpringUtils from './animations/SpringUtils';
import useValue from './useValue';


const decayWrapper = backwardCompatibleAnimWrapper(decay, DecayAnimation);
const timingWrapper = backwardCompatibleAnimWrapper(timing, TimingAnimation);
const springWrapper = backwardCompatibleAnimWrapper(spring, SpringAnimation);
const decayWrapper = backwardCompatibleAnimWrapper(
decay,
Animation.decayDefaultState
);
const timingWrapper = backwardCompatibleAnimWrapper(
timing,
Animation.timingDefaultState
);
const springWrapper = backwardCompatibleAnimWrapper(
spring,
Animation.springDefaultState
);
const Animated = {
// components
View: createAnimatedComponent(View),
Expand Down Expand Up @@ -72,19 +78,16 @@ export {
Easing,
Transitioning,
Transition,
createTransitioningComponent,

createTransitioningComponent,
// classes
AnimatedClock as Clock,
AnimatedValue as Value,
AnimatedNode as Node,

// animations
decayWrapper as decay,
timingWrapper as timing,
springWrapper as spring,
SpringUtils,

// hooks
useValue,
};
33 changes: 28 additions & 5 deletions src/animations/Animation.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
// Important note: start() and stop() will only be called at most once.
// Once an animation has been stopped or finished its course, it will
// not be reused.
import AnimatedValue from '../core/InternalAnimatedValue';

class Animation {
start(fromValue, onUpdate, onEnd, previousAnimation, animatedValue) {}
stop() {}
static springDefaultState() {
return {
position: new AnimatedValue(0),
finished: new AnimatedValue(0),
velocity: new AnimatedValue(0),
time: new AnimatedValue(0),
};
}

static decayDefaultState() {
return {
position: new AnimatedValue(0),
finished: new AnimatedValue(0),
velocity: new AnimatedValue(0),
time: new AnimatedValue(0),
};
}

static timingDefaultState() {
return {
position: new AnimatedValue(0),
finished: new AnimatedValue(0),
time: new AnimatedValue(0),
frameTime: new AnimatedValue(0),
};
}
}

export default Animation;
50 changes: 0 additions & 50 deletions src/animations/DecayAnimation.js

This file was deleted.

121 changes: 0 additions & 121 deletions src/animations/SpringAnimation.js

This file was deleted.

60 changes: 0 additions & 60 deletions src/animations/TimingAnimation.js

This file was deleted.

11 changes: 7 additions & 4 deletions src/animations/backwardCompatibleAnimWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
import Clock from '../core/AnimatedClock';
import { evaluateOnce } from '../derived/evaluateOnce';

function createOldAnimationObject(node, AnimationClass, value, config) {
function createOldAnimationObject(node, animationStateDefaults, value, config) {
const newClock = new Clock();
const currentState = AnimationClass.getDefaultState();
const currentState = animationStateDefaults();
let alwaysNode;
let isStarted = false;
let isDone = false;
Expand Down Expand Up @@ -104,11 +104,14 @@ function createOldAnimationObject(node, AnimationClass, value, config) {
* Depending on the arguments list we either return animation node or return an
* animation object that is compatible with the original Animated API
*/
export default function backwardsCompatibleAnimWrapper(node, AnimationClass) {
export default function backwardsCompatibleAnimWrapper(
node,
animationStateDefaults
) {
return (clock, state, config) => {
if (config !== undefined) {
return node(clock, state, config);
}
return createOldAnimationObject(node, AnimationClass, clock, state);
return createOldAnimationObject(node, animationStateDefaults, clock, state);
};
}