diff --git a/example/src/screens/HomeScreen.tsx b/example/src/screens/HomeScreen.tsx index 670e5ae..e2bc2dc 100644 --- a/example/src/screens/HomeScreen.tsx +++ b/example/src/screens/HomeScreen.tsx @@ -26,6 +26,7 @@ import { } from '../sheets'; import { colors, sharedStyles } from '../styles/theme'; import { CloseInterceptionDemo } from '../sheets/CloseInterceptionSheets'; +import { PartialCloseDemo } from '../sheets/PartialCloseSheets'; export function HomeScreen() { const { top } = useSafeAreaInsets(); @@ -167,6 +168,14 @@ export function HomeScreen() { persistentWithPortalControl.open({ scaleBackground: true }) } /> + + open(, { scaleBackground: true }) + } + /> ((_, ref) => ( + +)); + +interface LevelProps { + level: number; + /** ID of level 1, threaded down so deeper levels can aim `closeTo` at it. */ + rootId?: string; +} + +const PartialCloseLevel = forwardRef( + ({ level, rootId }, ref) => { + const { open, closeAll, closeTo, closeDepth } = useBottomSheetManager(); + const { id, close, closeAbove } = useBottomSheetContext(); + + const [lastResult, setLastResult] = useState('no call yet'); + const [inclusive, setInclusive] = useState(false); + const [blocking, setBlocking] = useState(false); + + // Lets a level refuse, so a cascade can be stopped mid-way and `stoppedAt` + // observed rather than taken on faith. + useOnBeforeClose(({ onCancel, onConfirm }) => + blocking ? onCancel() : onConfirm() + ); + + const target = rootId ?? id; + + const report = async (call: Promise) => + setLastResult(formatResult(await call)); + + const pushLevel = () => + open(, { + mode: 'push', + scaleBackground: true, + }); + + return ( + + + + {blocking ? : null} + + + Partial close · level {level} + + Push a few levels, then close part of the stack. + + + + LAST RESULT + {lastResult} + + + + Refuse to close (interceptor) + + + + inclusive + + + +