Skip to content

Commit

Permalink
refactor: calling dismiss without a key will remove the current modal…
Browse files Browse the repository at this point in the history
… if any (#676)(by @Shywim)
  • Loading branch information
Shywim authored Oct 3, 2021
1 parent c1fce95 commit fd4bb8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,15 @@ const BottomSheetModalProviderWrapper = ({
//#endregion

//#region public methods
const handleDismiss = useCallback((key: string) => {
const sheetToBeDismissed = sheetsQueueRef.current.find(
item => item.key === key
);
const handleDismiss = useCallback((key?: string) => {
const sheetToBeDismissed = key
? sheetsQueueRef.current.find(item => item.key === key)
: sheetsQueueRef.current[sheetsQueueRef.current.length - 1];
if (sheetToBeDismissed) {
sheetToBeDismissed.ref.current.dismiss();
return true;
}
return false;
}, []);
const handleDismissAll = useCallback(() => {
sheetsQueueRef.current.map(item => {
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/modal/external.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';

export interface BottomSheetModalContextType {
dismiss: (key: string) => void;
dismiss: (key?: string) => boolean;
dismissAll: () => void;
}

Expand Down

0 comments on commit fd4bb8d

Please sign in to comment.