Skip to content

Commit

Permalink
feat(⏰): add runDelay() function (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon authored Jul 22, 2019
1 parent 2591e59 commit 8e50d2c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ const progress = new Value(0);
set(progress, runLoop(400, Easing.linear);
```
### `runDelay(node: Node, duration: number)`
Evaluate an animation node after a certain amount of time. `duration` is in milliseconds.
Example usage:
```js
runDelay(set(value, 1), 250)
```
### `runDecay(clock: Clock, value: Node, velocity: Node, rerunDecaying: Node, deceleration: number): Node`
Convenience function to run a decay animation.
Expand Down
11 changes: 10 additions & 1 deletion src/AnimationRunners.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Animated from "react-native-reanimated";
import Animated, { Easing } from "react-native-reanimated";
import { Platform } from "react-native";

const {
Clock,
Value,
block,
timing,
Expand Down Expand Up @@ -115,6 +116,14 @@ export function runTiming(
]);
}

export const runDelay = (node: Animated.Node<number>, duration: number) => {
const clock = new Clock();
return block([
runTiming(clock, 0, { toValue: 1, duration, easing: Easing.linear }),
cond(not(clockRunning(clock)), node)
]);
};

export const runLoop = (
clock: Animated.Clock,
duration: Animated.Adaptable<number>,
Expand Down

0 comments on commit 8e50d2c

Please sign in to comment.