Fix scroll on native (#2170)
This commit is contained in:
parent
8929ff526f
commit
ab04074197
8 changed files with 53 additions and 54 deletions
|
@ -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'
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue