import type { ParamListBase } from '@react-navigation/native'; export type BottomSheetActionType = | { type: 'REPLACE'; payload: { name: string; key?: string | undefined; params?: object }; source?: string; target?: string; } | { type: 'PUSH'; payload: { name: string; key?: string | undefined; params?: object }; source?: string; target?: string; } | { type: 'POP'; payload: { name?: string }; source?: string; target?: string; } | { type: 'POP_ALL'; source?: string; target?: string; } | { type: 'POP_TO_TOP'; source?: string; target?: string; }; export type BottomSheetActionHelpers = { /** * Replace the current modal with a new one. * * @param name Route name of the new route. * @param [params] Params object for the new route. */ replace( ...args: undefined extends ParamList[RouteName] ? [RouteName] | [RouteName, ParamList[RouteName]] : [RouteName, ParamList[RouteName]] ): void; /** * Push a new modal onto the sheet navigator. * * @param name Name of the route for the sheet. * @param [params] Params object for the route. */ push( ...args: undefined extends ParamList[RouteName] ? [RouteName] | [RouteName, ParamList[RouteName]] : [RouteName, ParamList[RouteName]] ): void; /** * Dismiss a modal by its key, or the current presented modal. */ pop(name?: string): void; /** * Dismiss all modals except the first modal. */ popToTop(): void; /** * Dismiss all modals. */ popAll(): void; }; function replace(name: string, params?: object): BottomSheetActionType { return { type: 'REPLACE', payload: { name, params, }, }; } function push(name: string, params?: object): BottomSheetActionType { return { type: 'PUSH', payload: { name, params, }, }; } function pop(name?: string): BottomSheetActionType { return { type: 'POP', payload: { name, }, }; } function popAll(): BottomSheetActionType { return { type: 'POP_ALL', }; } function popToTop(): BottomSheetActionType { return { type: 'POP_TO_TOP', }; } export const SheetActions = { push, replace, pop, popToTop, popAll, };