Skip to content

Commit

Permalink
feat(➰): useLoop() function
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon authored Apr 29, 2020
1 parent 5702ea6 commit 4dc288d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/core/src/Hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
verticalPanGestureHandler,
} from "./Gesture";
import { vec } from "./Vectors";
import { loop } from "./AnimationRunners";

const { Clock, Value, diff, set, useCode, debug, block } = Animated;

Expand Down Expand Up @@ -41,6 +42,12 @@ export const useClock = () => useLazyRef(() => new Clock());
export const useValue = <V extends Atomic>(value: V) =>
useLazyRef(() => new Value(value));

export const useLoop = (duration = 1000, boomerang = true) => {
const progress = useValue(0);
useCode(() => set(progress, loop({ duration, boomerang })), [progress]);
return progress;
};

export const useValues = <V extends Atomic>(values: V[]): Animated.Value<V>[] =>
useLazyRef(() => values.map((v) => new Value(v)));

Expand Down

0 comments on commit 4dc288d

Please sign in to comment.