From 8d7475c13069f99170b40d696a7371c94020ef46 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 10 Nov 2023 14:58:13 +0000 Subject: Work around web stale closure bug in Reanimated (#1865) --- .../hooks/useAnimatedScrollHandler_FIXED.web.ts | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/lib/hooks/useAnimatedScrollHandler_FIXED.web.ts (limited to 'src/lib/hooks/useAnimatedScrollHandler_FIXED.web.ts') diff --git a/src/lib/hooks/useAnimatedScrollHandler_FIXED.web.ts b/src/lib/hooks/useAnimatedScrollHandler_FIXED.web.ts new file mode 100644 index 000000000..131e7bdd7 --- /dev/null +++ b/src/lib/hooks/useAnimatedScrollHandler_FIXED.web.ts @@ -0,0 +1,44 @@ +import {useRef, useEffect} from 'react' +import {useAnimatedScrollHandler as useAnimatedScrollHandler_BUGGY} from 'react-native-reanimated' + +export const useAnimatedScrollHandler: typeof useAnimatedScrollHandler_BUGGY = ( + config, + deps, +) => { + const ref = useRef(config) + useEffect(() => { + ref.current = config + }) + return useAnimatedScrollHandler_BUGGY( + { + onBeginDrag(e) { + if (typeof ref.current !== 'function' && ref.current.onBeginDrag) { + ref.current.onBeginDrag(e) + } + }, + onEndDrag(e) { + if (typeof ref.current !== 'function' && ref.current.onEndDrag) { + ref.current.onEndDrag(e) + } + }, + onMomentumBegin(e) { + if (typeof ref.current !== 'function' && ref.current.onMomentumBegin) { + ref.current.onMomentumBegin(e) + } + }, + onMomentumEnd(e) { + if (typeof ref.current !== 'function' && ref.current.onMomentumEnd) { + ref.current.onMomentumEnd(e) + } + }, + onScroll(e) { + if (typeof ref.current === 'function') { + ref.current(e) + } else if (ref.current.onScroll) { + ref.current.onScroll(e) + } + }, + }, + deps, + ) +} -- cgit 1.4.1