Work around web stale closure bug in Reanimated (#1865)
parent
487d871cfd
commit
8d7475c130
|
@ -0,0 +1 @@
|
|||
export {useAnimatedScrollHandler} from 'react-native-reanimated'
|
|
@ -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,
|
||||
)
|
||||
}
|
|
@ -4,12 +4,8 @@ import {useSetMinimalShellMode, useMinimalShellMode} from '#/state/shell'
|
|||
import {useShellLayout} from '#/state/shell/shell-layout'
|
||||
import {s} from 'lib/styles'
|
||||
import {isWeb} from 'platform/detection'
|
||||
import {
|
||||
useAnimatedScrollHandler,
|
||||
useSharedValue,
|
||||
interpolate,
|
||||
runOnJS,
|
||||
} from 'react-native-reanimated'
|
||||
import {useSharedValue, interpolate, runOnJS} from 'react-native-reanimated'
|
||||
import {useAnimatedScrollHandler} from './useAnimatedScrollHandler_FIXED'
|
||||
|
||||
function clamp(num: number, min: number, max: number) {
|
||||
'worklet'
|
||||
|
|
|
@ -3,7 +3,6 @@ import {LayoutChangeEvent, StyleSheet, View} from 'react-native'
|
|||
import Animated, {
|
||||
Easing,
|
||||
useAnimatedReaction,
|
||||
useAnimatedScrollHandler,
|
||||
useAnimatedStyle,
|
||||
useSharedValue,
|
||||
withTiming,
|
||||
|
@ -13,6 +12,7 @@ import {Pager, PagerRef, RenderTabBarFnProps} from 'view/com/pager/Pager'
|
|||
import {TabBar} from './TabBar'
|
||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||
import {OnScrollCb} from 'lib/hooks/useOnMainScroll'
|
||||
import {useAnimatedScrollHandler} from 'lib/hooks/useAnimatedScrollHandler_FIXED'
|
||||
|
||||
const SCROLLED_DOWN_LIMIT = 200
|
||||
|
||||
|
|
Loading…
Reference in New Issue