Skip to content

Commit

Permalink
fix: backdrop -> check if mounted before setting state
Browse files Browse the repository at this point in the history
  • Loading branch information
christophby committed Dec 8, 2023
1 parent 65b5dc0 commit be63967
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import React, { memo, useCallback, useMemo, useState } from 'react';
import React, {
memo,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import { ViewProps } from 'react-native';
import Animated, {
interpolate,
Expand Down Expand Up @@ -36,6 +43,7 @@ const BottomSheetBackdropComponent = ({
}: BottomSheetDefaultBackdropProps) => {
//#region hooks
const { snapToIndex, close } = useBottomSheet();
const isMounted = useRef(false);
//#endregion

//#region defaults
Expand All @@ -53,6 +61,16 @@ const BottomSheetBackdropComponent = ({
>(enableTouchThrough ? 'none' : 'auto');
//#endregion

//#region effects
useEffect(() => {
// Without this we get "Warning: Can't perform a React state update on an unmounted component [...] in BottomSheetBackdrop"
isMounted.current = true;
return () => {
isMounted.current = false;
};
}, []);
//#endregion

//#region callbacks
const handleOnPress = useCallback(() => {
onPress?.();
Expand All @@ -67,7 +85,8 @@ const BottomSheetBackdropComponent = ({
}, [snapToIndex, close, disappearsOnIndex, pressBehavior, onPress]);
const handleContainerTouchability = useCallback(
(shouldDisableTouchability: boolean) => {
setPointerEvents(shouldDisableTouchability ? 'none' : 'auto');
isMounted.current &&
setPointerEvents(shouldDisableTouchability ? 'none' : 'auto');
},
[]
);
Expand Down

0 comments on commit be63967

Please sign in to comment.