Skip to content

Commit

Permalink
[v1] Remove dead code from animation classes (#1018)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakub-gonet committed Aug 12, 2020
1 parent 8c7e1a7 commit 1940009
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 249 deletions.
24 changes: 15 additions & 9 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 @@ -25,11 +23,20 @@ import {
} from './Transitioning';
import SpringUtils from './animations/SpringUtils';
import useValue from './useValue';
import * as reanimated2 from './reanimated2'
import * as reanimated2 from './reanimated2';

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 @@ -62,7 +69,7 @@ const Animated = {
useValue,

// reanimated2
...reanimated2
...reanimated2,
};

export default Animated;
Expand All @@ -87,7 +94,6 @@ export {
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);
};
}

0 comments on commit 1940009

Please sign in to comment.