1
+ import { State } from 'react-native-gesture-handler' ;
1
2
import { scrollTo , useWorkletCallback } from 'react-native-reanimated' ;
2
3
import { ANIMATION_STATE , SCROLLABLE_STATE , SHEET_STATE } from '../constants' ;
3
4
import type {
@@ -20,13 +21,14 @@ export const useScrollEventsHandlersDefault: ScrollEventsHandlersHookType = (
20
21
animatedSheetState,
21
22
animatedScrollableState,
22
23
animatedAnimationState,
24
+ animatedHandleGestureState,
23
25
animatedScrollableContentOffsetY : rootScrollableContentOffsetY ,
24
26
} = useBottomSheetInternal ( ) ;
25
27
26
28
//#region callbacks
27
29
const handleOnScroll : ScrollEventHandlerCallbackType < ScrollEventContextType > =
28
30
useWorkletCallback (
29
- ( _ , context ) => {
31
+ ( { contentOffset : { y } } , context ) => {
30
32
/**
31
33
* if sheet position is extended or fill parent, then we reset
32
34
* `shouldLockInitialPosition` value to false.
@@ -38,6 +40,15 @@ export const useScrollEventsHandlersDefault: ScrollEventsHandlersHookType = (
38
40
context . shouldLockInitialPosition = false ;
39
41
}
40
42
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
+
41
52
if ( animatedScrollableState . value === SCROLLABLE_STATE . LOCKED ) {
42
53
const lockPosition = context . shouldLockInitialPosition
43
54
? ( context . initialContentOffsetY ?? 0 )
@@ -94,6 +105,7 @@ export const useScrollEventsHandlersDefault: ScrollEventsHandlersHookType = (
94
105
scrollableContentOffsetY . value = lockPosition ;
95
106
return ;
96
107
}
108
+
97
109
if ( animatedAnimationState . value !== ANIMATION_STATE . RUNNING ) {
98
110
scrollableContentOffsetY . value = y ;
99
111
rootScrollableContentOffsetY . value = y ;
@@ -119,6 +131,7 @@ export const useScrollEventsHandlersDefault: ScrollEventsHandlersHookType = (
119
131
scrollableContentOffsetY . value = 0 ;
120
132
return ;
121
133
}
134
+
122
135
if ( animatedAnimationState . value !== ANIMATION_STATE . RUNNING ) {
123
136
scrollableContentOffsetY . value = y ;
124
137
rootScrollableContentOffsetY . value = y ;
0 commit comments