1
- import { scrollTo , useWorkletCallback } from 'react-native-reanimated' ;
1
+ import { useWorkletCallback } from 'react-native-reanimated' ;
2
2
import { useBottomSheetInternal } from './useBottomSheetInternal' ;
3
- import { ANIMATION_STATE , SCROLLABLE_STATE , SHEET_STATE } from '../constants' ;
4
3
import type {
5
4
ScrollEventsHandlersHookType ,
6
5
ScrollEventHandlerCallbackType ,
@@ -13,112 +12,23 @@ export type ScrollEventContextType = {
13
12
14
13
export const useScrollEventsHandlers : ScrollEventsHandlersHookType = ( ) => {
15
14
// hooks
16
- const {
17
- animatedScrollableRef : scrollableRef ,
18
- animatedSheetState,
19
- animatedScrollableState,
20
- animatedAnimationState,
21
- animatedScrollableContentOffsetY : scrollableContentOffsetY ,
22
- } = useBottomSheetInternal ( ) ;
15
+ const { animatedScrollableContentOffsetY : scrollableContentOffsetY } =
16
+ useBottomSheetInternal ( ) ;
23
17
24
18
//#region callbacks
25
19
const handleOnScroll : ScrollEventHandlerCallbackType < ScrollEventContextType > =
26
20
useWorkletCallback (
27
- ( _ , context ) => {
28
- /**
29
- * if sheet position is extended or fill parent, then we reset
30
- * `shouldLockInitialPosition` value to false.
31
- */
32
- if (
33
- animatedSheetState . value === SHEET_STATE . EXTENDED ||
34
- animatedSheetState . value === SHEET_STATE . FILL_PARENT
35
- ) {
36
- context . shouldLockInitialPosition = false ;
37
- }
38
-
39
- if ( animatedScrollableState . value === SCROLLABLE_STATE . LOCKED ) {
40
- const lockPosition = context . shouldLockInitialPosition
41
- ? context . initialContentOffsetY ?? 0
42
- : 0 ;
43
- scrollTo ( scrollableRef , 0 , lockPosition , false ) ;
44
- scrollableContentOffsetY . value = lockPosition ;
45
- return ;
46
- }
21
+ ( event , _ ) => {
22
+ scrollableContentOffsetY . value = event . contentOffset . y ;
47
23
} ,
48
- [
49
- scrollableRef ,
50
- scrollableContentOffsetY ,
51
- animatedScrollableState ,
52
- animatedSheetState ,
53
- ]
24
+ [ scrollableContentOffsetY ]
54
25
) ;
55
26
const handleOnBeginDrag : ScrollEventHandlerCallbackType < ScrollEventContextType > =
56
- useWorkletCallback (
57
- ( event , context ) => {
58
- const y = event . contentOffset . y ;
59
- scrollableContentOffsetY . value = y ;
60
- context . initialContentOffsetY = y ;
61
-
62
- /**
63
- * if sheet position not extended or fill parent and the scrollable position
64
- * not at the top, then we should lock the initial scrollable position.
65
- */
66
- if (
67
- animatedSheetState . value !== SHEET_STATE . EXTENDED &&
68
- animatedSheetState . value !== SHEET_STATE . FILL_PARENT &&
69
- y > 0
70
- ) {
71
- context . shouldLockInitialPosition = true ;
72
- } else {
73
- context . shouldLockInitialPosition = false ;
74
- }
75
- } ,
76
- [ scrollableContentOffsetY , animatedSheetState ]
77
- ) ;
27
+ useWorkletCallback ( ( __ , _ ) => { } , [ ] ) ;
78
28
const handleOnEndDrag : ScrollEventHandlerCallbackType < ScrollEventContextType > =
79
- useWorkletCallback (
80
- ( { contentOffset : { y } } , context ) => {
81
- if ( animatedScrollableState . value === SCROLLABLE_STATE . LOCKED ) {
82
- const lockPosition = context . shouldLockInitialPosition
83
- ? context . initialContentOffsetY ?? 0
84
- : 0 ;
85
- scrollTo ( scrollableRef , 0 , lockPosition , false ) ;
86
- scrollableContentOffsetY . value = lockPosition ;
87
- return ;
88
- }
89
- if ( animatedAnimationState . value !== ANIMATION_STATE . RUNNING ) {
90
- scrollableContentOffsetY . value = y ;
91
- }
92
- } ,
93
- [
94
- scrollableRef ,
95
- scrollableContentOffsetY ,
96
- animatedAnimationState ,
97
- animatedScrollableState ,
98
- ]
99
- ) ;
29
+ useWorkletCallback ( ( __ , _ ) => { } , [ ] ) ;
100
30
const handleOnMomentumEnd : ScrollEventHandlerCallbackType < ScrollEventContextType > =
101
- useWorkletCallback (
102
- ( { contentOffset : { y } } , context ) => {
103
- if ( animatedScrollableState . value === SCROLLABLE_STATE . LOCKED ) {
104
- const lockPosition = context . shouldLockInitialPosition
105
- ? context . initialContentOffsetY ?? 0
106
- : 0 ;
107
- scrollTo ( scrollableRef , 0 , lockPosition , false ) ;
108
- scrollableContentOffsetY . value = 0 ;
109
- return ;
110
- }
111
- if ( animatedAnimationState . value !== ANIMATION_STATE . RUNNING ) {
112
- scrollableContentOffsetY . value = y ;
113
- }
114
- } ,
115
- [
116
- scrollableContentOffsetY ,
117
- scrollableRef ,
118
- animatedAnimationState ,
119
- animatedScrollableState ,
120
- ]
121
- ) ;
31
+ useWorkletCallback ( ( __ , _ ) => { } , [ ] ) ;
122
32
//#endregion
123
33
124
34
return {
0 commit comments