Manage open with transitionState so that the Bottom Sheet is not unmounted even when another Activity is pushed on top.
Set modal to false when the Bottom Sheet Activity is inactive with modal={isActive}. If you don't do this, interactions such as focus, screen reader access, and scrolling will not work in the Activity pushed above.
Execute pop() only when isActive in the onOpenChange handler to prevent unintended Activity termination in an inactive state.
When pushing another modal Activity with its own backdrop (e.g., Alert Dialog Activity) on top of the Bottom Sheet Activity, it is recommended to always set modal to true instead of modal={isActive}.
The modal={isActive} pattern is to ensure interactions such as scrolling when the Activity pushed above is a normal AppScreen, but if the Activity pushed above is a modal overlay with its own backdrop, the backdrop of the Bottom Sheet may disappear at the point of becoming inactive, which can make the dim layering appear broken.
Loading...
ActivityNestedBottomSheet.tsx
import { VStack } from "@seed-design/react";import { useActivityZIndexBase } from "@seed-design/stackflow";import { useActivity, useFlow, type StaticActivityComponentType } from "@stackflow/react/future";import { ActionButton } from "seed-design/ui/action-button";import { BottomSheetBody, BottomSheetContent, BottomSheetFooter, BottomSheetRoot,} from "seed-design/ui/bottom-sheet";import { Callout } from "seed-design/ui/callout";declare module "@stackflow/config" { interface Register { ActivityNestedBottomSheet: {}; }}const ActivityNestedBottomSheet: StaticActivityComponentType<"ActivityNestedBottomSheet"> = () => { const { pop, push } = useFlow(); const { isActive, transitionState } = useActivity(); const open = transitionState === "enter-active" || transitionState === "enter-done"; const onOpenChange = (next: boolean) => !next && isActive && pop(); return ( // 위에 AlertDialog Activity가 push되어 BottomSheet가 비활성(isActive=false)이 되더라도 // BottomSheet 자체의 modal 동작과 backdrop을 유지해 dim layering이 끊기지 않도록 modal을 항상 true로 둔다. // outside close는 onOpenChange에서 isActive 가드로 막혀 비활성 상태에서는 pop이 발생하지 않는다. <BottomSheetRoot open={open} onOpenChange={onOpenChange} modal> <BottomSheetContent showHandle title="BottomSheet × AlertDialog (Activity)" description="아래 버튼으로 AlertDialog Activity를 push해 위에 얹어보세요." layerIndex={useActivityZIndexBase()} > <BottomSheetBody> <Callout tone="neutral" description="Activity 패턴: BottomSheet가 자체 Activity로 떠 있고, 그 위에 AlertDialog Activity가 push되어 얹힙니다. 위에 떠 있는 AlertDialog의 Backdrop이나 Content 빈 영역을 클릭해 동작을 관찰해보세요." /> </BottomSheetBody> <BottomSheetFooter> <VStack gap="x2"> <ActionButton variant="neutralSolid" flexGrow onClick={() => push("ActivityAlertDialog", {})} > Open AlertDialog </ActionButton> <ActionButton variant="neutralWeak" onClick={pop}> 닫기 </ActionButton> </VStack> </BottomSheetFooter> </BottomSheetContent> </BottomSheetRoot> );};export default ActivityNestedBottomSheet;
Keep modal always true so that the Bottom Sheet's backdrop layering is not broken even when another modal Activity is pushed above.
Thanks to the isActive guard in onOpenChange, pop() does not occur unintentionally from outside interactions in an inactive state.
When should I keep `modal={isActive}`?
If the Activity pushed above is a normal AppScreen that does not have a backdrop covering the Bottom Sheet area, the modal={isActive} guide is appropriate for interactions such as scrolling in the above Activity. Use the variation where modal is always true only when two modal overlays are stacked.
If you cannot create a Bottom Sheet as an Activity, you can create the state where the Bottom Sheet is displayed as a Step.
You can close the Bottom Sheet with a back button, etc., while maintaining the current Activity.
You can open and close the Bottom Sheet using BottomSheetTrigger.
Constraints
Before pushing another Activity from a Bottom Sheet not created as an Activity, close the Bottom Sheet to prevent z-index issues.
If you cannot close the Bottom Sheet, or if you need to maintain the Bottom Sheet in an open state when returning to the Activity that opened it, it is recommended to create the Bottom Sheet as an Activity.
To provide smooth transitions between Activities, some lower AppScreen elements are positioned above upper AppScreen elements. Due to this constraint, an open Bottom Sheet cannot be positioned between lower and upper Activities unless it is created as an independent Activity.
Both hooks return values needed for z-index styling based on which Activity the current Activity is among the entered Activities.
While the values returned by both hooks are the same, when using Crispy components instead of @stackflow/plugin-basic-ui, it is recommended to use the useActivityZIndexBase hook from the @seed-design/stackflow package managed by Crispy.
The useActivityZIndexBase hook in the @stackflow/react-ui-core package does not provide the activityOffset option.
The useActivityZIndexBase hook is provided starting from @seed-design/stackflow@1.1.1.
If you were specifying layerIndex in the form useActivity().zIndex * 5 + n, you can change it to useActivityZIndexBase() + n. As you make the change, also review whether + n is necessary.