Skip to content

Commit

Permalink
feat(8️⃣): runLoop animation
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon authored Jul 22, 2019
1 parent 3bf4892 commit 2b2e659
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ const config = {
runTiming(clock, 0, config);
```

### `runLoop(duration: Node, easing: EasingFunction: boomerang? = false)`

Returns an animated node that goes from `0` to `1` during the time set by `duration` continuously. If the `boomerang` option is set to `true`, the animation goes from `0` to `1` and then from `1` to `0` in the next cycle.

Example usage:

```js
const progress = new Value(0);
set(progress, runLoop(400, Easing.linear);
```
### `runDecay(clock: Clock, value: Node, velocity: Node, rerunDecaying: Node, deceleration: number): Node`
Convenience function to run a decay animation.
Expand Down
36 changes: 35 additions & 1 deletion src/AnimationRunners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const {
set,
startClock,
clockRunning,
onChange
onChange,
not
} = Animated;

export function runDecay(
Expand Down Expand Up @@ -113,3 +114,36 @@ export function runTiming(
state.position
]);
}

export const runLoop = (
clock: Animated.Clock,
duration: Animated.Adaptable<number>,
easing: Animated.EasingFunction,
boomerang: boolean = false
) => {
const state = {
finished: new Value(0),
position: new Value(0),
time: new Value(0),
frameTime: new Value(0)
};
const config = {
toValue: new Value(1),
duration,
easing
};

return block([
cond(not(clockRunning(clock)), startClock(clock)),
timing(clock, state, config),
cond(state.finished, [
set(state.finished, 0),
set(state.time, 0),
set(state.frameTime, 0),
boomerang
? set(config.toValue, cond(config.toValue, 0, 1))
: set(state.position, 0)
]),
state.position
]);
};

0 comments on commit 2b2e659

Please sign in to comment.