From b2bcbf59b615620473a48011925988b87c22cd69 Mon Sep 17 00:00:00 2001 From: William Candillon Date: Wed, 1 Jul 2020 11:14:42 +0200 Subject: [PATCH] =?UTF-8?q?feat(=F0=9F=96=B1):=20useScrollHander()=20and?= =?UTF-8?q?=20scrollHandler()=20(#294)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/Gesture.ts | 12 ++++++++++++ packages/core/src/Hooks.ts | 2 ++ 2 files changed, 14 insertions(+) diff --git a/packages/core/src/Gesture.ts b/packages/core/src/Gesture.ts index 5fe50670..955d3424 100644 --- a/packages/core/src/Gesture.ts +++ b/packages/core/src/Gesture.ts @@ -327,6 +327,18 @@ export const rotationGestureHandler = () => { }; }; +export const scrollHandler = () => { + const x = new Value(0); + const y = new Value(0); + const onScroll = onScrollEvent({ x, y }); + return { + x, + y, + onScroll, + scrollEventThrottle: 1, + }; +}; + export const debugGestureState = ( label: string, state: Animated.Node diff --git a/packages/core/src/Hooks.ts b/packages/core/src/Hooks.ts index 733a3e47..fb6f71ac 100644 --- a/packages/core/src/Hooks.ts +++ b/packages/core/src/Hooks.ts @@ -6,6 +6,7 @@ import { pinchGestureHandler, rotationGestureHandler, tapGestureHandler, + scrollHandler, } from "./Gesture"; import { Vector, vec } from "./Vectors"; import { loop } from "./AnimationRunners"; @@ -30,6 +31,7 @@ export const useRotationGestureHandler = () => export const usePinchGestureHandler = () => useLazyRef(() => pinchGestureHandler()); export const useTapGestureHandler = () => useLazyRef(() => tapGestureHandler()); +export const useScrollHandler = () => useLazyRef(() => scrollHandler()); type Atomic = string | number | boolean;