Skip to content

Commit d2b959c

Browse files
committed
fix: updated the scrollable locking logic while scrolling (#1939)
1 parent e4f3fe3 commit d2b959c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/hooks/useScrollEventsHandlersDefault.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { State } from 'react-native-gesture-handler';
12
import { scrollTo, useWorkletCallback } from 'react-native-reanimated';
23
import { ANIMATION_STATE, SCROLLABLE_STATE, SHEET_STATE } from '../constants';
34
import type {
@@ -20,13 +21,14 @@ export const useScrollEventsHandlersDefault: ScrollEventsHandlersHookType = (
2021
animatedSheetState,
2122
animatedScrollableState,
2223
animatedAnimationState,
24+
animatedHandleGestureState,
2325
animatedScrollableContentOffsetY: rootScrollableContentOffsetY,
2426
} = useBottomSheetInternal();
2527

2628
//#region callbacks
2729
const handleOnScroll: ScrollEventHandlerCallbackType<ScrollEventContextType> =
2830
useWorkletCallback(
29-
(_, context) => {
31+
({ contentOffset: { y } }, context) => {
3032
/**
3133
* if sheet position is extended or fill parent, then we reset
3234
* `shouldLockInitialPosition` value to false.
@@ -38,6 +40,15 @@ export const useScrollEventsHandlersDefault: ScrollEventsHandlersHookType = (
3840
context.shouldLockInitialPosition = false;
3941
}
4042

43+
/**
44+
* if handle gesture state is active, then we capture the offset y position
45+
* and lock the scrollable with it.
46+
*/
47+
if (animatedHandleGestureState.value === State.ACTIVE) {
48+
context.shouldLockInitialPosition = true;
49+
context.initialContentOffsetY = y;
50+
}
51+
4152
if (animatedScrollableState.value === SCROLLABLE_STATE.LOCKED) {
4253
const lockPosition = context.shouldLockInitialPosition
4354
? (context.initialContentOffsetY ?? 0)
@@ -94,6 +105,7 @@ export const useScrollEventsHandlersDefault: ScrollEventsHandlersHookType = (
94105
scrollableContentOffsetY.value = lockPosition;
95106
return;
96107
}
108+
97109
if (animatedAnimationState.value !== ANIMATION_STATE.RUNNING) {
98110
scrollableContentOffsetY.value = y;
99111
rootScrollableContentOffsetY.value = y;
@@ -119,6 +131,7 @@ export const useScrollEventsHandlersDefault: ScrollEventsHandlersHookType = (
119131
scrollableContentOffsetY.value = 0;
120132
return;
121133
}
134+
122135
if (animatedAnimationState.value !== ANIMATION_STATE.RUNNING) {
123136
scrollableContentOffsetY.value = y;
124137
rootScrollableContentOffsetY.value = y;

0 commit comments

Comments
 (0)