@@ -26,6 +26,7 @@ type Props = {
26
26
visible ?: boolean ;
27
27
animationDuration ?: number ;
28
28
expandable ?: boolean ;
29
+ hideable ?: boolean ;
29
30
hideOnPressOutside ?: boolean ;
30
31
overlayBackgroundColor ?: string ;
31
32
overlayOpacity ?: number ;
@@ -50,20 +51,26 @@ export const DraggablePanel = React.forwardRef<
50
51
borderRadius = 0 ,
51
52
initialHeight = DEFAULT_PANEL_HEIGHT / 2 ,
52
53
hideOnBackButtonPressed = true ,
54
+ hideable = true ,
53
55
onDismiss,
54
56
children,
55
57
} : Props ,
56
58
ref : React . Ref < ReactNativeDraggablePanelRef > ,
57
59
) => {
58
60
const [ animatedValue ] = React . useState ( new Animated . Value ( 0 ) ) ;
61
+
59
62
const [ popupVisible , togglePopupVisibility ] = React . useState ( false ) ;
63
+
60
64
const [ animating , setAnimating ] = React . useState ( false ) ;
65
+
61
66
const [ height ] = React . useState (
62
67
Math . min ( initialHeight , DEFAULT_PANEL_HEIGHT ) ,
63
68
) ;
69
+
64
70
const [ innerContentHeight , setInnerContentHeight ] = React . useState (
65
71
Math . min ( initialHeight , DEFAULT_PANEL_HEIGHT ) ,
66
72
) ;
73
+
67
74
const scrollViewRef : RefObject < ScrollView > = React . useRef ( null ) ;
68
75
69
76
React . useEffect ( ( ) => {
@@ -77,7 +84,7 @@ export const DraggablePanel = React.forwardRef<
77
84
// eslint-disable-next-line react-hooks/exhaustive-deps
78
85
} , [ visible ] ) ;
79
86
80
- const show = React . useCallback ( ( ) => {
87
+ const show = ( ) => {
81
88
if ( ! animating ) {
82
89
animatedValue . setValue ( 0 ) ;
83
90
setInnerContentHeight ( Math . min ( initialHeight , DEFAULT_PANEL_HEIGHT ) ) ;
@@ -96,9 +103,9 @@ export const DraggablePanel = React.forwardRef<
96
103
setAnimating ( false ) ;
97
104
} ) ;
98
105
}
99
- } , [ animatedValue , animating , animationDuration , height , initialHeight ] ) ;
106
+ } ;
100
107
101
- const hide = React . useCallback ( ( ) => {
108
+ const hide = ( ) => {
102
109
if ( ! animating ) {
103
110
setAnimating ( true ) ;
104
111
Animated . timing ( animatedValue , {
@@ -116,18 +123,19 @@ export const DraggablePanel = React.forwardRef<
116
123
onDismiss && onDismiss ( ) ;
117
124
} ) ;
118
125
}
119
- } , [ animatedValue , animating , animationDuration , onDismiss ] ) ;
126
+ } ;
120
127
121
- const onBackButtonPress = React . useCallback ( ( ) => {
128
+ const onBackButtonPress = ( ) => {
122
129
if (
123
130
Platform . OS === 'android' &&
124
131
hideOnBackButtonPressed &&
125
132
! animating &&
126
- popupVisible
133
+ popupVisible &&
134
+ hideable
127
135
) {
128
136
hide ( ) ;
129
137
}
130
- } , [ hideOnBackButtonPressed , animating , popupVisible , hide ] ) ;
138
+ } ;
131
139
132
140
React . useImperativeHandle <
133
141
ReactNativeDraggablePanelRef ,
@@ -137,51 +145,46 @@ export const DraggablePanel = React.forwardRef<
137
145
hide,
138
146
} ) ) ;
139
147
140
- const onScroll = React . useCallback (
141
- ( event : NativeSyntheticEvent < NativeScrollEvent > ) => {
142
- if ( ! animating ) {
143
- const { y} = event . nativeEvent . contentOffset ;
144
- if (
145
- ! expandable &&
146
- y < SCREEN_HEIGHT - ( SCREEN_HEIGHT * height ) / DEFAULT_PANEL_HEIGHT
147
- ) {
148
- return ;
149
- }
150
- animatedValue . setValue ( 1 - Math . floor ( y ) / Math . floor ( SCREEN_HEIGHT ) ) ;
151
- // >= Fix the android issue, cause for some reason it goes for more than SCREEN_HEIGHT
152
- // if the use swipes faster
153
- if ( Math . floor ( y ) >= Math . floor ( SCREEN_HEIGHT ) ) {
154
- togglePopupVisibility ( false ) ;
155
- setAnimating ( false ) ;
156
- onDismiss && onDismiss ( ) ;
157
- }
148
+ const onScroll = ( event : NativeSyntheticEvent < NativeScrollEvent > ) => {
149
+ if ( ! animating ) {
150
+ const { y} = event . nativeEvent . contentOffset ;
151
+ if (
152
+ ! expandable &&
153
+ y < SCREEN_HEIGHT - ( SCREEN_HEIGHT * height ) / DEFAULT_PANEL_HEIGHT
154
+ ) {
155
+ return ;
158
156
}
159
- } ,
160
- [ animatedValue , animating , expandable , height , onDismiss ] ,
161
- ) ;
162
-
163
- const onScrollBeginDrag = React . useCallback (
164
- ( e : NativeSyntheticEvent < NativeScrollEvent > ) => {
165
- if ( e . nativeEvent . contentOffset . y !== 0 && expandable ) {
166
- setInnerContentHeight ( DEFAULT_PANEL_HEIGHT ) ;
157
+ animatedValue . setValue ( 1 - Math . floor ( y ) / Math . floor ( SCREEN_HEIGHT ) ) ;
158
+ // >= Fix the android issue, cause for some reason it goes for more than SCREEN_HEIGHT
159
+ // if the use swipes faster
160
+ if ( Math . floor ( y ) >= Math . floor ( SCREEN_HEIGHT ) ) {
161
+ togglePopupVisibility ( false ) ;
162
+ setAnimating ( false ) ;
163
+ onDismiss && onDismiss ( ) ;
167
164
}
168
- } ,
169
- [ expandable ] ,
170
- ) ;
165
+ }
166
+ } ;
171
167
172
- const onMomentumScrollEnd = React . useCallback (
173
- ( e : NativeSyntheticEvent < NativeScrollEvent > ) => {
174
- if ( expandable ) {
175
- const { y} = e . nativeEvent . contentOffset ;
176
- if ( y !== 0 ) {
177
- setInnerContentHeight ( height ) ;
178
- } else {
179
- setInnerContentHeight ( DEFAULT_PANEL_HEIGHT ) ;
180
- }
168
+ const onScrollBeginDrag = (
169
+ event : NativeSyntheticEvent < NativeScrollEvent > ,
170
+ ) => {
171
+ if ( event . nativeEvent . contentOffset . y !== 0 && expandable ) {
172
+ setInnerContentHeight ( DEFAULT_PANEL_HEIGHT ) ;
173
+ }
174
+ } ;
175
+
176
+ const onMomentumScrollEnd = (
177
+ event : NativeSyntheticEvent < NativeScrollEvent > ,
178
+ ) => {
179
+ if ( expandable ) {
180
+ const { y} = event . nativeEvent . contentOffset ;
181
+ if ( y !== 0 ) {
182
+ setInnerContentHeight ( height ) ;
183
+ } else {
184
+ setInnerContentHeight ( DEFAULT_PANEL_HEIGHT ) ;
181
185
}
182
- } ,
183
- [ height , expandable ] ,
184
- ) ;
186
+ }
187
+ } ;
185
188
186
189
return (
187
190
< Modal
@@ -218,7 +221,7 @@ export const DraggablePanel = React.forwardRef<
218
221
SCREEN_HEIGHT ,
219
222
] } >
220
223
< TouchableWithoutFeedback
221
- disabled = { ! hideOnPressOutside || animating }
224
+ disabled = { ! hideOnPressOutside || animating || ! hideable }
222
225
onPress = { hide } >
223
226
< View style = { styles . hideContainer } />
224
227
</ TouchableWithoutFeedback >
0 commit comments