Fix scroll on profile lists/feeds (#2168)

This commit is contained in:
dan 2023-12-11 21:24:31 +00:00 committed by GitHub
parent b82c5177b9
commit 8929ff526f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 54 additions and 53 deletions

View file

@ -1,44 +1,45 @@
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, ctx) {
if (typeof ref.current !== 'function' && ref.current.onBeginDrag) {
ref.current.onBeginDrag(e, ctx)
}
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)
}
},
},
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,
)
}
deps,
)
}