-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ScrollView event handlers not working: onScrollBeginDrag, onScrollEndDrag, onMomentumScrollBegin, onMomentumScrollEnd #2249
Comments
Similar issue: #2247 |
This is something that those of you who need these events (aligned with what RN does with them) will need to implement and submit PRs for. I do not plan to work on adding these features myself. |
Does anyone get any solution/workaround for this? |
if you need |
Will this work on react-vative? |
I only needed You can use it like this: const webProps = useWebScrollEvents({
onMomentumScrollEnd: e => console.log(e.nativeEvent.layout)
})
return (
<ScrollView
{...webProps}
/>
) Here's the code for /* eslint-disable react-hooks/rules-of-hooks */
import { ComponentProps, useEffect, useRef } from 'react'
import { Platform, ScrollView } from 'react-native'
const MOMENTUM_SCROLL_END_THROTTLE_MILLISECONDS = 200
export function useWebScrollEvents<
Props extends Partial<ComponentProps<typeof ScrollView>>
>(props: Props): Props {
if (Platform.OS === 'web') {
const momentumScrollEndTimer = useRef<number>()
useEffect(function cleanup() {
return () => {
clearTimeout(momentumScrollEndTimer.current)
}
}, [])
return {
...props,
onScroll(e) {
props.onScroll?.(e)
if (props.onMomentumScrollEnd) {
clearTimeout(momentumScrollEndTimer.current)
momentumScrollEndTimer.current = setTimeout(() => {
props.onMomentumScrollEnd?.(e)
}, MOMENTUM_SCROLL_END_THROTTLE_MILLISECONDS)
}
},
}
}
return props
} |
For anyone looking about |
The problem
How to reproduce
Simplified test case: https://codesandbox.io/s/hopeful-flower-y6uf7m
Steps to reproduce:
Expected behavior
Environment (include versions). Did this work in previous versions?
0.13.12
The text was updated successfully, but these errors were encountered: