Closed YoucefBen47 closed 4 months ago
To address the issue where onScrollBegin
fires on vertical scrolls within a ScrollView, you'll need to differentiate between horizontal and vertical gestures. This can be achieved by modifying the gesture handling logic to only trigger onScrollBegin
for horizontal movements. Here's a conceptual approach:
const onGestureUpdate = useCallback((e: PanGestureHandlerEventPayload) => {
"worklet";
const { translationX, translationY } = e;
let isVerticalScroll = Math.abs(translationY) > Math.abs(translationX);
if (!isVerticalScroll) {
// Trigger onScrollBegin for horizontal scrolls
}
}, []);
For the onScrollEnd
not firing, a workaround involves using the onProgressChange
event to manage a scrolling
state, which then determines when scrolling starts and ends. This approach replaces the direct use of onScrollBegin
and onScrollEnd
:
const [scrolling, setScrolling] = useState(false);
useEffect(() => {
if (scrolling) {
// Handle onScrollBegin actions
} else {
// Handle onScrollEnd actions
}
}, [scrolling]);
const onProgressChange = (_: number, absoluteProgress: number) => {
setScrolling(absoluteProgress % 1 !== 0);
};
This solution should help manage the scroll events more accurately for your carousel within a ScrollView, ensuring that onScrollBegin
is only triggered for relevant horizontal gestures and providing a mechanism to detect the end of scrolling.
To continue the conversation, mention @dosu.
I ended up using this: https://github.com/dohooo/react-native-reanimated-carousel/issues/244#issuecomment-1253386041
onProgressChange={(_, absoluteProgress) => {
if (absoluteProgress % 1 !== 0) {
fadeOut();
} else {
fadeIn();
}
}}
To address the issue where
onScrollBegin
fires on vertical scrolls within a ScrollView, you'll need to differentiate between horizontal and vertical gestures. This can be achieved by modifying the gesture handling logic to only triggeronScrollBegin
for horizontal movements. Here's a conceptual approach:const onGestureUpdate = useCallback((e: PanGestureHandlerEventPayload) => { "worklet"; const { translationX, translationY } = e; let isVerticalScroll = Math.abs(translationY) > Math.abs(translationX); if (!isVerticalScroll) { // Trigger onScrollBegin for horizontal scrolls } }, []);
For the
onScrollEnd
not firing, a workaround involves using theonProgressChange
event to manage ascrolling
state, which then determines when scrolling starts and ends. This approach replaces the direct use ofonScrollBegin
andonScrollEnd
:const [scrolling, setScrolling] = useState(false); useEffect(() => { if (scrolling) { // Handle onScrollBegin actions } else { // Handle onScrollEnd actions } }, [scrolling]); const onProgressChange = (_: number, absoluteProgress: number) => { setScrolling(absoluteProgress % 1 !== 0); };
This solution should help manage the scroll events more accurately for your carousel within a ScrollView, ensuring that
onScrollBegin
is only triggered for relevant horizontal gestures and providing a mechanism to detect the end of scrolling.Details
To continue the conversation, mention @dosu.
This is not working, when loop is false and we are on the last item of carousel. When we scroll to left absoluteProgress is 1 so setScroll will not set to True
Describe the bug We have a default Horizontal Carousel inside of a ScrollView. We use onScrollEnd and onScrollBegin to animate a text on swipe. When scrolling down away from the Carousel the onScrollBegin fires but onScrollEnd doesn't. To Reproduce Steps to reproduce the behavior:
Expected behavior onScrollBegin should not fire because the items are not being swiped horizontally.
Versions (please complete the following information):
Smartphone (please complete the following information):