@@ -6,7 +6,7 @@ import React from 'react';
6
6
import styled from 'styled-components' ;
7
7
import { rubberbandIfOutOfBounds , useDrag } from '@use-gesture/react' ;
8
8
import usePresence from 'use-presence' ;
9
- import { clearAllBodyScrollLocks } from 'body-scroll-lock-upgrade' ;
9
+ import { clearAllBodyScrollLocks , enableBodyScroll } from 'body-scroll-lock-upgrade' ;
10
10
import { BottomSheetHeader } from './BottomSheetHeader' ;
11
11
import { BottomSheetFooter } from './BottomSheetFooter' ;
12
12
import { BottomSheetBody } from './BottomSheetBody' ;
@@ -433,6 +433,22 @@ const _BottomSheet = ({
433
433
}
434
434
} , [ addBottomSheetToStack , id , isMounted , removeBottomSheetFromStack ] ) ;
435
435
436
+ // Remove the bottomsheet from the stack, if it's unmounted forcefully
437
+ React . useEffect ( ( ) => {
438
+ return ( ) => {
439
+ if ( id === undefined ) return ;
440
+ removeBottomSheetFromStack ( id ) ;
441
+ } ;
442
+ } , [ id , removeBottomSheetFromStack ] ) ;
443
+
444
+ // Disable body scroll lock when the component is unmounted forcefully
445
+ React . useEffect ( ( ) => {
446
+ const lockTarget = scrollRef . current ! ;
447
+ return ( ) => {
448
+ enableBodyScroll ( lockTarget ) ;
449
+ } ;
450
+ } , [ ] ) ;
451
+
436
452
// We will need to reset these values otherwise the next time the bottomsheet opens
437
453
// this will be populated and the animations won't run
438
454
// why?: because how the usePresence hook works, we actually just unmount the
0 commit comments