Skip to content

Commit 997d794

Browse files
committed
feat: added a new bottom sheet stack behaviour replace (#1897)(with @janodetzel)
1 parent 5af3e80 commit 997d794

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const DEFAULT_STACK_BEHAVIOR = 'replace';
1+
const DEFAULT_STACK_BEHAVIOR = 'switch';
22
const DEFAULT_ENABLE_DISMISS_ON_CLOSE = true;
33

44
export { DEFAULT_STACK_BEHAVIOR, DEFAULT_ENABLE_DISMISS_ON_CLOSE };

src/components/bottomSheetModal/types.d.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ export interface BottomSheetModalProps
2121

2222
/**
2323
* Defines the stack behavior when modal mount.
24-
* - `push` it will mount the modal on top of current modal.
25-
* - `replace` it will minimize the current modal then mount the modal.
26-
* @type `push` | `replace`
27-
* @default replace
24+
* - `push` it will mount the modal on top of the current one.
25+
* - `switch` it will minimize the current modal then mount the new one.
26+
* - `replace` it will dismiss the current modal then mount the new one.
27+
* @type `push` | `switch` | `replace`
28+
* @default switch
2829
*/
2930
stackBehavior?: BottomSheetModalStackBehavior;
3031

src/components/bottomSheetModalProvider/BottomSheetModalProvider.tsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,19 @@ const BottomSheetModalProviderWrapper = ({
5050
* - it is not unmounting.
5151
* - stack behavior is 'replace'.
5252
*/
53+
54+
/**
55+
* Handle switch or replace stack behaviors, if:
56+
* - a modal is currently presented.
57+
* - it is not unmounting
58+
*/
5359
const currentMountedSheet = _sheetsQueue[_sheetsQueue.length - 1];
54-
if (
55-
currentMountedSheet &&
56-
!currentMountedSheet.willUnmount &&
57-
stackBehavior === MODAL_STACK_BEHAVIOR.replace
58-
) {
59-
currentMountedSheet.ref?.current?.minimize();
60+
if (currentMountedSheet && !currentMountedSheet.willUnmount) {
61+
if (stackBehavior === MODAL_STACK_BEHAVIOR.replace) {
62+
currentMountedSheet.ref?.current?.dismiss();
63+
} else if (stackBehavior === MODAL_STACK_BEHAVIOR.switch) {
64+
currentMountedSheet.ref?.current?.minimize();
65+
}
6066
}
6167

6268
/**

src/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const SCROLLABLE_DECELERATION_RATE_MAPPER = {
100100
const MODAL_STACK_BEHAVIOR = {
101101
replace: 'replace',
102102
push: 'push',
103+
switch: 'switch',
103104
};
104105

105106
const KEYBOARD_BEHAVIOR = {

0 commit comments

Comments
 (0)