Skip to content

Commit

Permalink
feat: added a new bottom sheet stack behaviour replace (#1897)(with @…
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Aug 31, 2024
1 parent 5af3e80 commit 997d794
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/bottomSheetModal/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const DEFAULT_STACK_BEHAVIOR = 'replace';
const DEFAULT_STACK_BEHAVIOR = 'switch';
const DEFAULT_ENABLE_DISMISS_ON_CLOSE = true;

export { DEFAULT_STACK_BEHAVIOR, DEFAULT_ENABLE_DISMISS_ON_CLOSE };
9 changes: 5 additions & 4 deletions src/components/bottomSheetModal/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export interface BottomSheetModalProps

/**
* Defines the stack behavior when modal mount.
* - `push` it will mount the modal on top of current modal.
* - `replace` it will minimize the current modal then mount the modal.
* @type `push` | `replace`
* @default replace
* - `push` it will mount the modal on top of the current one.
* - `switch` it will minimize the current modal then mount the new one.
* - `replace` it will dismiss the current modal then mount the new one.
* @type `push` | `switch` | `replace`
* @default switch
*/
stackBehavior?: BottomSheetModalStackBehavior;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ const BottomSheetModalProviderWrapper = ({
* - it is not unmounting.
* - stack behavior is 'replace'.
*/

/**
* Handle switch or replace stack behaviors, if:
* - a modal is currently presented.
* - it is not unmounting
*/
const currentMountedSheet = _sheetsQueue[_sheetsQueue.length - 1];
if (
currentMountedSheet &&
!currentMountedSheet.willUnmount &&
stackBehavior === MODAL_STACK_BEHAVIOR.replace
) {
currentMountedSheet.ref?.current?.minimize();
if (currentMountedSheet && !currentMountedSheet.willUnmount) {
if (stackBehavior === MODAL_STACK_BEHAVIOR.replace) {
currentMountedSheet.ref?.current?.dismiss();
} else if (stackBehavior === MODAL_STACK_BEHAVIOR.switch) {
currentMountedSheet.ref?.current?.minimize();
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const SCROLLABLE_DECELERATION_RATE_MAPPER = {
const MODAL_STACK_BEHAVIOR = {
replace: 'replace',
push: 'push',
switch: 'switch',
};

const KEYBOARD_BEHAVIOR = {
Expand Down

0 comments on commit 997d794

Please sign in to comment.