Skip to content

Commit

Permalink
fix: prevent unstable mounting for modals (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Oct 18, 2021
1 parent e777487 commit 657505a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/components/bottomSheetModal/BottomSheetModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const BottomSheetModalComponent = forwardRef<
const restoreIndexRef = useRef(-1);
const minimized = useRef(false);
const forcedDismissed = useRef(false);
const mounted = useRef(true);
const mounted = useRef(false);
mounted.current = mount;
//#endregion

//#region variables
Expand All @@ -82,7 +83,7 @@ const BottomSheetModalComponent = forwardRef<
currentIndexRef.current = -1;
restoreIndexRef.current = -1;
minimized.current = false;
mounted.current = true;
mounted.current = false;
forcedDismissed.current = false;
}, []);
const unmount = useCallback(
Expand Down Expand Up @@ -279,6 +280,14 @@ const BottomSheetModalComponent = forwardRef<
},
[key, unmount, willUnmountSheet]
);
const handlePortalRender = useCallback(function handlePortalRender(
render: () => void
) {
if (mounted.current) {
render();
}
},
[]);
const handleBottomSheetOnChange = useCallback(
function handleBottomSheetOnChange(_index: number) {
print({
Expand Down Expand Up @@ -341,15 +350,20 @@ const BottomSheetModalComponent = forwardRef<
// render
// console.log('BottomSheetModal', index, snapPoints)
return mount ? (
<Portal key={key} name={key} handleOnUnmount={handlePortalOnUnmount}>
<Portal
key={key}
name={key}
handleOnMount={handlePortalRender}
handleOnUpdate={handlePortalRender}
handleOnUnmount={handlePortalOnUnmount}
>
<BottomSheet
{...bottomSheetProps}
ref={bottomSheetRef}
key={key}
index={index}
snapPoints={snapPoints}
enablePanDownToClose={enablePanDownToClose}
animateOnMount={true}
containerHeight={containerHeight}
containerOffset={containerOffset}
onChange={handleBottomSheetOnChange}
Expand Down

0 comments on commit 657505a

Please sign in to comment.