1
- import React , { memo , useCallback , useMemo , useState } from 'react' ;
1
+ import React , {
2
+ memo ,
3
+ useCallback ,
4
+ useEffect ,
5
+ useMemo ,
6
+ useRef ,
7
+ useState ,
8
+ } from 'react' ;
2
9
import { ViewProps } from 'react-native' ;
3
10
import Animated , {
4
11
interpolate ,
@@ -44,6 +51,7 @@ const BottomSheetBackdropComponent = ({
44
51
} : BottomSheetDefaultBackdropProps ) => {
45
52
//#region hooks
46
53
const { snapToIndex, close } = useBottomSheet ( ) ;
54
+ const isMounted = useRef ( false ) ;
47
55
//#endregion
48
56
49
57
//#region defaults
@@ -75,7 +83,8 @@ const BottomSheetBackdropComponent = ({
75
83
} , [ snapToIndex , close , disappearsOnIndex , pressBehavior , onPress ] ) ;
76
84
const handleContainerTouchability = useCallback (
77
85
( shouldDisableTouchability : boolean ) => {
78
- setPointerEvents ( shouldDisableTouchability ? 'none' : 'auto' ) ;
86
+ isMounted . current &&
87
+ setPointerEvents ( shouldDisableTouchability ? 'none' : 'auto' ) ;
79
88
} ,
80
89
[ ]
81
90
) ;
@@ -121,6 +130,16 @@ const BottomSheetBackdropComponent = ({
121
130
[ disappearsOnIndex ]
122
131
) ;
123
132
133
+ // addressing updating the state after unmounting.
134
+ // [link](https://github.com/gorhom/react-native-bottom-sheet/issues/1376)
135
+ useEffect ( ( ) => {
136
+ isMounted . current = true ;
137
+ return ( ) => {
138
+ isMounted . current = false ;
139
+ } ;
140
+ } , [ ] ) ;
141
+ //#endregion
142
+
124
143
const AnimatedView = (
125
144
< Animated . View
126
145
style = { containerStyle }
@@ -139,7 +158,6 @@ const BottomSheetBackdropComponent = ({
139
158
{ children }
140
159
</ Animated . View >
141
160
) ;
142
- //#endregion
143
161
144
162
return pressBehavior !== 'none' ? (
145
163
< TapGestureHandler onGestureEvent = { gestureHandler } >
0 commit comments