diff options
author | dan <dan.abramov@gmail.com> | 2023-12-11 21:47:41 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-11 13:47:41 -0800 |
commit | ab04074197f8432a3d502ca2393beca3b8f6ca97 (patch) | |
tree | 6ee1a3af73b2afbc4a36300aab9561ebebbcffd6 /src/lib/hooks | |
parent | 8929ff526fa7f81c23decaf05898f396e5fe0de9 (diff) | |
download | voidsky-ab04074197f8432a3d502ca2393beca3b8f6ca97.tar.zst |
Fix scroll on native (#2170)
Diffstat (limited to 'src/lib/hooks')
-rw-r--r-- | src/lib/hooks/useAnimatedScrollHandler_FIXED.ts | 2 | ||||
-rw-r--r-- | src/lib/hooks/useAnimatedScrollHandler_FIXED.web.ts | 81 |
2 files changed, 41 insertions, 42 deletions
diff --git a/src/lib/hooks/useAnimatedScrollHandler_FIXED.ts b/src/lib/hooks/useAnimatedScrollHandler_FIXED.ts index 0ed4139f9..56a1e8b11 100644 --- a/src/lib/hooks/useAnimatedScrollHandler_FIXED.ts +++ b/src/lib/hooks/useAnimatedScrollHandler_FIXED.ts @@ -12,4 +12,4 @@ // - https://github.com/software-mansion/react-native-reanimated/issues/5364 // // It's great when it works though. -export {useAnimatedScrollHandler as useAnimatedScrollHandler_FIXED} from 'react-native-reanimated' +export {useAnimatedScrollHandler} from 'react-native-reanimated' diff --git a/src/lib/hooks/useAnimatedScrollHandler_FIXED.web.ts b/src/lib/hooks/useAnimatedScrollHandler_FIXED.web.ts index b94f49e42..98e05a8ce 100644 --- a/src/lib/hooks/useAnimatedScrollHandler_FIXED.web.ts +++ b/src/lib/hooks/useAnimatedScrollHandler_FIXED.web.ts @@ -1,45 +1,44 @@ import {useRef, useEffect} from 'react' import {useAnimatedScrollHandler as useAnimatedScrollHandler_BUGGY} from 'react-native-reanimated' -export const useAnimatedScrollHandler_FIXED: typeof useAnimatedScrollHandler_BUGGY = - (config, deps) => { - const ref = useRef(config) - useEffect(() => { - ref.current = config - }) - return useAnimatedScrollHandler_BUGGY( - { - onBeginDrag(e, ctx) { - if (typeof ref.current !== 'function' && ref.current.onBeginDrag) { - ref.current.onBeginDrag(e, ctx) - } - }, - onEndDrag(e, ctx) { - if (typeof ref.current !== 'function' && ref.current.onEndDrag) { - ref.current.onEndDrag(e, ctx) - } - }, - onMomentumBegin(e, ctx) { - if ( - typeof ref.current !== 'function' && - ref.current.onMomentumBegin - ) { - ref.current.onMomentumBegin(e, ctx) - } - }, - onMomentumEnd(e, ctx) { - if (typeof ref.current !== 'function' && ref.current.onMomentumEnd) { - ref.current.onMomentumEnd(e, ctx) - } - }, - onScroll(e, ctx) { - if (typeof ref.current === 'function') { - ref.current(e, ctx) - } else if (ref.current.onScroll) { - ref.current.onScroll(e, ctx) - } - }, +export const useAnimatedScrollHandler: typeof useAnimatedScrollHandler_BUGGY = ( + config, + deps, +) => { + const ref = useRef(config) + useEffect(() => { + ref.current = config + }) + return useAnimatedScrollHandler_BUGGY( + { + onBeginDrag(e, ctx) { + if (typeof ref.current !== 'function' && ref.current.onBeginDrag) { + ref.current.onBeginDrag(e, ctx) + } }, - deps, - ) - } + onEndDrag(e, ctx) { + if (typeof ref.current !== 'function' && ref.current.onEndDrag) { + ref.current.onEndDrag(e, ctx) + } + }, + onMomentumBegin(e, ctx) { + if (typeof ref.current !== 'function' && ref.current.onMomentumBegin) { + ref.current.onMomentumBegin(e, ctx) + } + }, + onMomentumEnd(e, ctx) { + if (typeof ref.current !== 'function' && ref.current.onMomentumEnd) { + ref.current.onMomentumEnd(e, ctx) + } + }, + onScroll(e, ctx) { + if (typeof ref.current === 'function') { + ref.current(e, ctx) + } else if (ref.current.onScroll) { + ref.current.onScroll(e, ctx) + } + }, + }, + deps, + ) +} |