expo-router 5.2.0-canary-20250701-6a945c5 → 5.2.0-canary-20250713-8f814f8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/modal.module.css +124 -0
- package/build/fork/useLinking.d.ts.map +1 -1
- package/build/fork/useLinking.js +7 -3
- package/build/fork/useLinking.js.map +1 -1
- package/build/layouts/DrawerClient.d.ts +2 -2
- package/build/layouts/Stack.web.d.ts +17 -0
- package/build/layouts/Stack.web.d.ts.map +1 -0
- package/build/layouts/Stack.web.js +17 -0
- package/build/layouts/Stack.web.js.map +1 -0
- package/build/layouts/StackClient.d.ts +41 -3
- package/build/layouts/StackClient.d.ts.map +1 -1
- package/build/layouts/StackClient.js +79 -2
- package/build/layouts/StackClient.js.map +1 -1
- package/build/layouts/TabsClient.d.ts +3 -3
- package/build/link/BaseExpoRouterLink.d.ts +2 -1
- package/build/link/BaseExpoRouterLink.d.ts.map +1 -1
- package/build/link/BaseExpoRouterLink.js +37 -1
- package/build/link/BaseExpoRouterLink.js.map +1 -1
- package/build/link/ExpoLink.d.ts +2 -1
- package/build/link/ExpoLink.d.ts.map +1 -1
- package/build/link/ExpoLink.js +44 -3
- package/build/link/ExpoLink.js.map +1 -1
- package/build/link/Link.d.ts +3 -3
- package/build/link/Link.d.ts.map +1 -1
- package/build/link/Link.js.map +1 -1
- package/build/link/LinkWithPreview.d.ts +19 -6
- package/build/link/LinkWithPreview.d.ts.map +1 -1
- package/build/link/LinkWithPreview.js +47 -17
- package/build/link/LinkWithPreview.js.map +1 -1
- package/build/link/preview/HrefPreview.d.ts.map +1 -1
- package/build/link/preview/HrefPreview.js +2 -2
- package/build/link/preview/HrefPreview.js.map +1 -1
- package/build/link/preview/native.d.ts +2 -0
- package/build/link/preview/native.d.ts.map +1 -1
- package/build/link/preview/native.js.map +1 -1
- package/build/modal/Modal.d.ts +2 -0
- package/build/modal/Modal.d.ts.map +1 -1
- package/build/modal/Modal.js +9 -0
- package/build/modal/Modal.js.map +1 -1
- package/build/modal/utils.d.ts +3 -0
- package/build/modal/utils.d.ts.map +1 -0
- package/build/modal/utils.js +14 -0
- package/build/modal/utils.js.map +1 -0
- package/build/modal/web/ModalStack.web.d.ts +25 -0
- package/build/modal/web/ModalStack.web.d.ts.map +1 -0
- package/build/modal/web/ModalStack.web.js +86 -0
- package/build/modal/web/ModalStack.web.js.map +1 -0
- package/build/modal/web/ModalStackRouteDrawer.web.d.ts +14 -0
- package/build/modal/web/ModalStackRouteDrawer.web.d.ts.map +1 -0
- package/build/modal/web/ModalStackRouteDrawer.web.js +161 -0
- package/build/modal/web/ModalStackRouteDrawer.web.js.map +1 -0
- package/build/modal/web/TransparentModalStackRouteDrawer.web.d.ts +10 -0
- package/build/modal/web/TransparentModalStackRouteDrawer.web.d.ts.map +1 -0
- package/build/modal/web/TransparentModalStackRouteDrawer.web.js +28 -0
- package/build/modal/web/TransparentModalStackRouteDrawer.web.js.map +1 -0
- package/build/modal/web/modalStyles.d.ts +3 -0
- package/build/modal/web/modalStyles.d.ts.map +1 -0
- package/build/modal/web/modalStyles.js +8 -0
- package/build/modal/web/modalStyles.js.map +1 -0
- package/build/modal/web/types.d.ts +14 -0
- package/build/modal/web/types.d.ts.map +1 -0
- package/build/modal/web/types.js +3 -0
- package/build/modal/web/types.js.map +1 -0
- package/build/modal/web/utils.d.ts +70 -0
- package/build/modal/web/utils.d.ts.map +1 -0
- package/build/modal/web/utils.js +117 -0
- package/build/modal/web/utils.js.map +1 -0
- package/ios/ExpoHead.podspec +1 -1
- package/ios/LinkPreview/LinkPreviewNativeActionView.swift +22 -0
- package/ios/LinkPreview/LinkPreviewNativeModule.swift +3 -0
- package/ios/LinkPreview/LinkPreviewNativeView.swift +30 -11
- package/package.json +9 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LinkWithPreview.js","sourceRoot":"","sources":["../../src/link/LinkWithPreview.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;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K,CAAC,KAAK,IAAI,KAAK,EAAE;QACnC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK;QACxB,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;KAC7B,CAAC,CAAC,CAAC;AACR,CAAC","sourcesContent":["'use client';\n\nimport React, {\n createContext,\n isValidElement,\n use,\n useEffect,\n useRef,\n useState,\n type PropsWithChildren,\n type ReactElement,\n} from 'react';\n\nimport { useRouter } from '../hooks';\nimport { BaseExpoRouterLink } from './BaseExpoRouterLink';\nimport { HrefPreview } from './preview/HrefPreview';\nimport { useLinkPreviewContext } from './preview/LinkPreviewContext';\nimport {\n NativeLinkPreview,\n NativeLinkPreviewAction,\n NativeLinkPreviewContent,\n NativeLinkPreviewTrigger,\n} from './preview/native';\nimport { useNextScreenId } from './preview/useNextScreenId';\nimport { LinkProps } from './useLinkHooks';\nimport { shouldLinkExternally } from '../utils/url';\nimport { useIsPreview } from './preview/PreviewRouteContext';\nimport { Slot } from '../ui/Slot';\n\nconst InternalLinkPreviewContext = createContext<\n { isVisible: boolean; href: LinkProps['href'] } | undefined\n>(undefined);\n\nexport function LinkWithPreview({ children, ...rest }: LinkProps) {\n const router = useRouter();\n const { setIsPreviewOpen } = useLinkPreviewContext();\n const [isCurrentPreviewOpen, setIsCurrenPreviewOpen] = useState(false);\n\n const hrefWithoutQuery = String(rest.href).split('?')[0];\n const prevHrefWithoutQuery = useRef(hrefWithoutQuery);\n\n useEffect(() => {\n if (isCurrentPreviewOpen) {\n if (prevHrefWithoutQuery.current !== hrefWithoutQuery) {\n throw new Error(\n 'Link does not support changing the href prop after the preview has been opened. Please ensure that the href prop is stable and does not change between renders.'\n );\n }\n } else {\n prevHrefWithoutQuery.current = hrefWithoutQuery;\n }\n }, [hrefWithoutQuery]);\n\n const [nextScreenId, updateNextScreenId] = useNextScreenId();\n\n useEffect(() => {\n if (shouldLinkExternally(String(rest.href))) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('External links previews are not supported');\n } else {\n console.warn('External links previews are not supported');\n }\n }\n if (rest.replace) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Using replace links with preview is not supported');\n } else {\n console.warn('Using replace links with preview is not supported');\n }\n }\n }, [rest.href, rest.replace]);\n\n const triggerElement = React.useMemo(\n () => getFirstChildOfType(children, LinkTrigger),\n [children]\n );\n const menuElement = React.useMemo(() => getFirstChildOfType(children, LinkMenu), [children]);\n const previewElement = React.useMemo(\n () => getFirstChildOfType(children, LinkPreview),\n [children]\n );\n\n if (previewElement && !triggerElement) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n 'When you use Link.Preview, you must use Link.Trigger to specify the trigger element.'\n );\n } else {\n console.warn(\n 'When you use Link.Preview, you must use Link.Trigger to specify the trigger element.'\n );\n }\n }\n\n const trigger = React.useMemo(\n () => triggerElement ?? <LinkTrigger>{children}</LinkTrigger>,\n [triggerElement, children]\n );\n\n const actionsHandlers = React.useMemo(\n () =>\n convertActionsToActionsHandlers(\n convertChildrenArrayToActions(React.Children.toArray(menuElement?.props.children))\n ),\n [menuElement]\n );\n const preview = React.useMemo(\n () => previewElement ?? <LinkPreview />,\n [previewElement, rest.href]\n );\n\n if (shouldLinkExternally(String(rest.href)) || rest.replace) {\n return <BaseExpoRouterLink children={children} {...rest} />;\n }\n\n return (\n <NativeLinkPreview\n nextScreenId={nextScreenId}\n onActionSelected={({ nativeEvent: { id } }) => {\n actionsHandlers[id]?.();\n }}\n onWillPreviewOpen={() => {\n router.prefetch(rest.href);\n setIsPreviewOpen(true);\n setIsCurrenPreviewOpen(true);\n }}\n onDidPreviewOpen={() => {\n updateNextScreenId(rest.href);\n }}\n onPreviewDidClose={() => {\n setIsPreviewOpen(false);\n setIsCurrenPreviewOpen(false);\n }}\n onPreviewTapped={() => {\n router.navigate(rest.href, { __internal__PreviewKey: nextScreenId });\n }}>\n <InternalLinkPreviewContext value={{ isVisible: isCurrentPreviewOpen, href: rest.href }}>\n <NativeLinkPreviewTrigger>\n <BaseExpoRouterLink {...rest} children={trigger} ref={rest.ref} />\n </NativeLinkPreviewTrigger>\n {preview}\n {menuElement}\n </InternalLinkPreviewContext>\n </NativeLinkPreview>\n );\n}\n\ninterface LinkMenuAction {\n /**\n * The title of the menu item.\n */\n title: string;\n onPress: () => void;\n}\n\nexport function LinkMenuAction(_: LinkMenuAction) {\n return null;\n}\ninterface LinkMenuProps {\n children: ReactElement<LinkMenuAction> | ReactElement<LinkMenuAction>[];\n}\n\nexport function LinkMenu({ children }: LinkMenuProps) {\n if (useIsPreview() || !use(InternalLinkPreviewContext)) {\n return null;\n }\n return convertChildrenArrayToActions(React.Children.toArray(children)).map((action) => {\n return <NativeLinkPreviewAction key={action.id} title={action.title} id={action.id} />;\n });\n}\n\ninterface LinkPreviewProps {\n /**\n * Sets the preferred width of the preview.\n * If not set, full width of the screen will be used.\n *\n * This is only **preferred** width, the actual width may be different\n */\n width?: number;\n\n /**\n * Sets the preferred height of the preview.\n * If not set, full height of the screen will be used.\n *\n * This is only **preferred** height, the actual height may be different\n */\n height?: number;\n children?: React.ReactNode;\n}\n\nexport function LinkPreview({ children, width, height }: LinkPreviewProps) {\n const internalPreviewContext = use(InternalLinkPreviewContext);\n if (useIsPreview() || !internalPreviewContext) {\n return null;\n }\n const { isVisible, href } = internalPreviewContext;\n const contentSize = {\n width: width ?? 0,\n height: height ?? 0,\n };\n let content: React.ReactNode;\n if (children) {\n content = isVisible ? children : null;\n } else {\n content = isVisible ? <HrefPreview href={href} /> : null;\n }\n\n return (\n <NativeLinkPreviewContent\n style={{\n /* Setting default background here, so that the preview is not transparent */\n backgroundColor: '#fff',\n }}\n preferredContentSize={contentSize}>\n {content}\n </NativeLinkPreviewContent>\n );\n}\n\nexport function LinkTrigger(props: PropsWithChildren) {\n if (React.Children.count(props.children) > 1 || !isValidElement(props.children)) {\n // If onPress is passed, this means that Link passed props to this component.\n // We can assume that asChild is used, so we throw an error, because link will not work in this case.\n if (props && typeof props === 'object' && 'onPress' in props) {\n throw new Error(\n 'When using Link.Trigger in an asChild Link, you must pass a single child element that will emit onPress event.'\n );\n }\n return props.children;\n }\n return <Slot {...props} />;\n}\n\nfunction getFirstChildOfType<PropsT>(\n children: React.ReactNode | React.ReactNode[],\n type: (props: PropsT) => unknown\n) {\n return React.Children.toArray(children).find(\n (child): child is ReactElement<PropsT> => isValidElement(child) && child.type === type\n );\n}\n\nfunction convertActionsToActionsHandlers(\n items: { id: string; title: string; onPress: () => void }[] | undefined\n) {\n return (items ?? []).reduce(\n (acc, item) => ({\n ...acc,\n [item.id]: item.onPress,\n }),\n {} as Record<string, () => void>\n );\n}\n\nfunction convertChildrenArrayToActions(children: ReturnType<typeof React.Children.toArray>) {\n return children\n .filter(\n (item): item is ReactElement<LinkMenuAction> =>\n isValidElement(item) && item.type === LinkMenuAction\n )\n .map((child, index) => ({\n id: `${child.props.title}-${index}`,\n title: child.props.title,\n onPress: child.props.onPress,\n }));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"LinkWithPreview.js","sourceRoot":"","sources":["../../src/link/LinkWithPreview.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCb,0CAgIC;AAcD,wCAEC;AAoDD,kCA2BC;AAED,kCAYC;AAhRD,+CAWe;AAGf,oCAAqC;AACrC,6DAA0D;AAC1D,uDAAoD;AACpD,qEAAqE;AACrE,6CAM0B;AAC1B,+DAA4D;AAE5D,sCAAoD;AACpD,uEAA6D;AAC7D,qCAAkC;AAElC,MAAM,0BAA0B,GAAG,IAAA,qBAAa,EAE9C,SAAS,CAAC,CAAC;AAEb,SAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAa;IAC9D,MAAM,MAAM,GAAG,IAAA,iBAAS,GAAE,CAAC;IAC3B,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAA,0CAAqB,GAAE,CAAC;IACrD,MAAM,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,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","sourcesContent":["'use client';\n\nimport React, {\n createContext,\n createElement,\n isValidElement,\n use,\n useEffect,\n useRef,\n useState,\n type FC,\n type PropsWithChildren,\n type ReactElement,\n} from 'react';\nimport type { SFSymbol } from 'sf-symbols-typescript';\n\nimport { useRouter } from '../hooks';\nimport { BaseExpoRouterLink } from './BaseExpoRouterLink';\nimport { HrefPreview } from './preview/HrefPreview';\nimport { useLinkPreviewContext } from './preview/LinkPreviewContext';\nimport {\n NativeLinkPreview,\n NativeLinkPreviewAction,\n NativeLinkPreviewContent,\n NativeLinkPreviewTrigger,\n type NativeLinkPreviewActionProps,\n} from './preview/native';\nimport { useNextScreenId } from './preview/useNextScreenId';\nimport { LinkProps } from './useLinkHooks';\nimport { shouldLinkExternally } from '../utils/url';\nimport { useIsPreview } from './preview/PreviewRouteContext';\nimport { Slot } from '../ui/Slot';\n\nconst InternalLinkPreviewContext = createContext<\n { isVisible: boolean; href: LinkProps['href'] } | undefined\n>(undefined);\n\nexport function LinkWithPreview({ children, ...rest }: LinkProps) {\n const router = useRouter();\n const { setIsPreviewOpen } = useLinkPreviewContext();\n const [isCurrentPreviewOpen, setIsCurrenPreviewOpen] = useState(false);\n\n const hrefWithoutQuery = String(rest.href).split('?')[0];\n const prevHrefWithoutQuery = useRef(hrefWithoutQuery);\n\n useEffect(() => {\n if (isCurrentPreviewOpen) {\n if (prevHrefWithoutQuery.current !== hrefWithoutQuery) {\n throw new Error(\n 'Link does not support changing the href prop after the preview has been opened. Please ensure that the href prop is stable and does not change between renders.'\n );\n }\n } else {\n prevHrefWithoutQuery.current = hrefWithoutQuery;\n }\n }, [hrefWithoutQuery]);\n\n const [nextScreenId, updateNextScreenId] = useNextScreenId();\n\n useEffect(() => {\n if (shouldLinkExternally(String(rest.href))) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('External links previews are not supported');\n } else {\n console.warn('External links previews are not supported');\n }\n }\n if (rest.replace) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Using replace links with preview is not supported');\n } else {\n console.warn('Using replace links with preview is not supported');\n }\n }\n }, [rest.href, rest.replace]);\n\n const triggerElement = React.useMemo(\n () => getFirstChildOfType(children, LinkTrigger),\n [children]\n );\n const menuElement = React.useMemo(() => getFirstChildOfType(children, LinkMenu), [children]);\n const previewElement = React.useMemo(\n () => getFirstChildOfType(children, LinkPreview),\n [children]\n );\n\n if (previewElement && !triggerElement) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n 'When you use Link.Preview, you must use Link.Trigger to specify the trigger element.'\n );\n } else {\n console.warn(\n 'When you use Link.Preview, you must use Link.Trigger to specify the trigger element.'\n );\n }\n }\n\n const trigger = React.useMemo(\n () => triggerElement ?? <LinkTrigger>{children}</LinkTrigger>,\n [triggerElement, children]\n );\n\n const actionsHandlers = React.useMemo(\n () =>\n menuElement\n ? convertActionsToActionsHandlers(convertChildrenArrayToActions([menuElement]))\n : {},\n [menuElement]\n );\n const preview = React.useMemo(\n () => previewElement ?? <LinkPreview />,\n [previewElement, rest.href]\n );\n\n const isPreviewTapped = useRef(false);\n\n if (shouldLinkExternally(String(rest.href)) || rest.replace) {\n return <BaseExpoRouterLink children={children} {...rest} />;\n }\n\n return (\n <NativeLinkPreview\n nextScreenId={nextScreenId}\n onActionSelected={({ nativeEvent: { id } }) => {\n actionsHandlers[id]?.();\n }}\n onWillPreviewOpen={() => {\n isPreviewTapped.current = false;\n router.prefetch(rest.href);\n setIsPreviewOpen(true);\n setIsCurrenPreviewOpen(true);\n }}\n onDidPreviewOpen={() => {\n updateNextScreenId(rest.href);\n }}\n onPreviewWillClose={() => {\n // When preview was not tapped, then we need to enable the screen stack animation\n // Otherwise a quick user could tap another link before onDidPreviewClose is called\n if (!isPreviewTapped.current) {\n setIsCurrenPreviewOpen(false);\n setIsPreviewOpen(false);\n }\n }}\n onPreviewDidClose={() => {\n // If preview was tapped we need to enable the screen stack animation\n // For other cases we did it in onPreviewWillClose\n if (isPreviewTapped.current) {\n setIsCurrenPreviewOpen(false);\n setIsPreviewOpen(false);\n }\n }}\n onPreviewTapped={() => {\n isPreviewTapped.current = true;\n router.navigate(rest.href, { __internal__PreviewKey: nextScreenId });\n }}>\n <InternalLinkPreviewContext value={{ isVisible: isCurrentPreviewOpen, href: rest.href }}>\n <NativeLinkPreviewTrigger>\n <BaseExpoRouterLink {...rest} children={trigger} ref={rest.ref} />\n </NativeLinkPreviewTrigger>\n {preview}\n {menuElement}\n </InternalLinkPreviewContext>\n </NativeLinkPreview>\n );\n}\n\ninterface LinkMenuActionProps {\n /**\n * The title of the menu item.\n */\n title: string;\n /**\n * Optional SF Symbol displayed alongside the menu item.\n */\n icon?: SFSymbol;\n onPress: () => void;\n}\n\nexport function LinkMenuAction(_: LinkMenuActionProps) {\n return null;\n}\n\nexport interface LinkMenuProps {\n /**\n * The title of the menu item\n */\n title?: string;\n /**\n * Optional SF Symbol displayed alongside the menu item.\n */\n icon?: string;\n children: ReactElement<LinkMenuActionProps> | ReactElement<LinkMenuActionProps>[];\n}\n\nexport const LinkMenu: FC<LinkMenuProps> = (props) => {\n if (useIsPreview() || process.env.EXPO_OS !== 'ios' || !use(InternalLinkPreviewContext)) {\n return null;\n }\n return convertActionsToNativeElements(\n convertChildrenArrayToActions([createElement(LinkMenu, props, props.children)])\n );\n};\n\nfunction convertActionsToNativeElements(actions: ConvertChildrenArrayToActionsReturnType) {\n return actions.map(({ children, onPress, ...props }) => (\n <NativeLinkPreviewAction\n {...props}\n key={props.id}\n children={convertActionsToNativeElements(children)}\n />\n ));\n}\n\ninterface LinkPreviewProps {\n /**\n * Sets the preferred width of the preview.\n * If not set, full width of the screen will be used.\n *\n * This is only **preferred** width, the actual width may be different\n */\n width?: number;\n\n /**\n * Sets the preferred height of the preview.\n * If not set, full height of the screen will be used.\n *\n * This is only **preferred** height, the actual height may be different\n */\n height?: number;\n children?: React.ReactNode;\n}\n\nexport function LinkPreview({ children, width, height }: LinkPreviewProps) {\n const internalPreviewContext = use(InternalLinkPreviewContext);\n if (useIsPreview() || process.env.EXPO_OS !== 'ios' || !internalPreviewContext) {\n return null;\n }\n const { isVisible, href } = internalPreviewContext;\n const contentSize = {\n width: width ?? 0,\n height: height ?? 0,\n };\n let content: React.ReactNode;\n if (children) {\n content = isVisible ? children : null;\n } else {\n content = isVisible ? <HrefPreview href={href} /> : null;\n }\n\n return (\n <NativeLinkPreviewContent\n style={{\n /* Setting default background here, so that the preview is not transparent */\n backgroundColor: '#fff',\n }}\n preferredContentSize={contentSize}>\n {content}\n </NativeLinkPreviewContent>\n );\n}\n\nexport function LinkTrigger(props: PropsWithChildren) {\n if (React.Children.count(props.children) > 1 || !isValidElement(props.children)) {\n // If onPress is passed, this means that Link passed props to this component.\n // We can assume that asChild is used, so we throw an error, because link will not work in this case.\n if (props && typeof props === 'object' && 'onPress' in props) {\n throw new Error(\n 'When using Link.Trigger in an asChild Link, you must pass a single child element that will emit onPress event.'\n );\n }\n return props.children;\n }\n return <Slot {...props} />;\n}\n\nfunction getFirstChildOfType<PropsT>(\n children: React.ReactNode | React.ReactNode[],\n type: (props: PropsT) => unknown\n) {\n return React.Children.toArray(children).find(\n (child): child is ReactElement<PropsT> => isValidElement(child) && child.type === type\n );\n}\n\nfunction convertActionsToActionsHandlers(\n items: ConvertChildrenArrayToActionsReturnType | undefined\n) {\n return flattenActions(items ?? []).reduce(\n (acc, item) => ({\n ...acc,\n [item.id]: item.onPress,\n }),\n {} as Record<string, () => void>\n );\n}\n\nfunction flattenActions(\n actions: ConvertChildrenArrayToActionsReturnType\n): ConvertChildrenArrayToActionsReturnType {\n return actions.reduce((acc, action) => {\n if (action.children.length > 0) {\n return [...acc, action, ...flattenActions(action.children)];\n }\n return [...acc, action];\n }, [] as ConvertChildrenArrayToActionsReturnType);\n}\n\ntype ConvertChildrenArrayToActionsReturnType = (Omit<NativeLinkPreviewActionProps, 'children'> & {\n onPress: () => void;\n children: ConvertChildrenArrayToActionsReturnType;\n})[];\n\nfunction convertChildrenArrayToActions(\n children: ReturnType<typeof React.Children.toArray>,\n parentId: string = ''\n): ConvertChildrenArrayToActionsReturnType {\n return children\n .filter(\n (item): item is ReactElement<LinkMenuActionProps | LinkMenuProps> =>\n isValidElement(item) && (item.type === LinkMenuAction || item.type === LinkMenu)\n )\n .map((child, index) => ({\n id: `${parentId}${child.props.title}-${index}`,\n title: child.props.title ?? '',\n onPress: 'onPress' in child.props ? child.props.onPress : () => {},\n icon: child.props.icon,\n children:\n 'children' in child.props\n ? convertChildrenArrayToActions(\n React.Children.toArray(child.props.children),\n `${parentId}${child.props.title}-${index}`\n )\n : [],\n }));\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HrefPreview.d.ts","sourceRoot":"","sources":["../../../src/link/preview/HrefPreview.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HrefPreview.d.ts","sourceRoot":"","sources":["../../../src/link/preview/HrefPreview.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,IAAI,EAAuB,MAAM,aAAa,CAAC;AAKxD,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,sCA+BnD"}
|
|
@@ -5,11 +5,11 @@ exports.HrefPreview = HrefPreview;
|
|
|
5
5
|
const native_1 = require("@react-navigation/native");
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const PreviewRouteContext_1 = require("./PreviewRouteContext");
|
|
8
|
+
const constants_1 = require("../../constants");
|
|
8
9
|
const router_store_1 = require("../../global-state/router-store");
|
|
9
10
|
const useNavigation_1 = require("../../useNavigation");
|
|
10
11
|
const useScreens_1 = require("../../useScreens");
|
|
11
12
|
const linking_1 = require("../linking");
|
|
12
|
-
const constants_1 = require("../../constants");
|
|
13
13
|
function HrefPreview({ href }) {
|
|
14
14
|
const navigation = (0, useNavigation_1.useNavigation)();
|
|
15
15
|
const { routeNode, params, state } = getParamsAndNodeFromHref(href);
|
|
@@ -91,7 +91,7 @@ const navigationPropWithWarnings = {
|
|
|
91
91
|
index: 0,
|
|
92
92
|
routeNames: [],
|
|
93
93
|
routes: [],
|
|
94
|
-
type: '
|
|
94
|
+
type: '',
|
|
95
95
|
stale: false,
|
|
96
96
|
};
|
|
97
97
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HrefPreview.js","sourceRoot":"","sources":["../../../src/link/preview/HrefPreview.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAkBb,kCA+BC;AA/CD,qDAIkC;AAClC,iCAAgC;AAEhC,+DAA4D;AAE5D,kEAAwD;AAExD,uDAAoD;AACpD,iDAA8D;AAC9D,wCAA8C;
|
|
1
|
+
{"version":3,"file":"HrefPreview.js","sourceRoot":"","sources":["../../../src/link/preview/HrefPreview.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAkBb,kCA+BC;AA/CD,qDAIkC;AAClC,iCAAgC;AAEhC,+DAA4D;AAE5D,+CAAqD;AACrD,kEAAwD;AAExD,uDAAoD;AACpD,iDAA8D;AAC9D,wCAA8C;AAE9C,SAAgB,WAAW,CAAC,EAAE,IAAI,EAAkB;IAClD,MAAM,UAAU,GAAG,IAAA,6BAAa,GAAE,CAAC;IACnC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAC;IAEpE,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAA,0BAAgB,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEzD,MAAM,KAAK,GAAG,IAAA,eAAO,EACnB,GAAG,EAAE,CAAC,CAAC;QACL,MAAM;QACN,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE;QACzB,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE;KACjD,CAAC,EACF,CAAC,MAAM,EAAE,IAAI,CAAC,CACf,CAAC;IAEF,8GAA8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C,KAAK,EAAE,qBAAqB,CAAC,OAAO,CAAC;IACrC,IAAI,EAAE,qBAAqB,CAAC,MAAM,CAAC;IACnC,GAAG,EAAE,qBAAqB,CAAC,KAAK,CAAC;IACjC,QAAQ,EAAE,qBAAqB,CAAC,UAAU,CAAC;IAC3C,kBAAkB,EAAE,qBAAqB,CAAC,oBAAoB,CAAC;IAC/D,OAAO,EAAE,qBAAqB,CAAC,SAAS,CAAC;IACzC,KAAK,EAAE,GAAG,EAAE;QACV,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAC/B,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,mBAAmB;IACnB,SAAS,EAAE,qBAAqB,CAAC,WAAW,CAAC;IAC7C,QAAQ,EAAE,GAAG,EAAE;QACb,qBAAqB,CAAC,UAAU,CAAC,CAAC;QAClC,OAAO;YACL,GAAG,EAAE,EAAE;YACP,KAAK,EAAE,CAAC;YACR,UAAU,EAAE,EAAE;YACd,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,EAAE;YACR,KAAK,EAAE,KAAK;SACb,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["'use client';\n\nimport {\n NavigationContext,\n type NavigationProp,\n type ParamListBase,\n} from '@react-navigation/native';\nimport { useMemo } from 'react';\n\nimport { PreviewRouteContext } from './PreviewRouteContext';\nimport { RouteNode } from '../../Route';\nimport { INTERNAL_SLOT_NAME } from '../../constants';\nimport { store } from '../../global-state/router-store';\nimport { Href, UnknownOutputParams } from '../../types';\nimport { useNavigation } from '../../useNavigation';\nimport { getQualifiedRouteComponent } from '../../useScreens';\nimport { getPathFromState } from '../linking';\n\nexport function HrefPreview({ href }: { href: Href }) {\n const navigation = useNavigation();\n const { routeNode, params, state } = getParamsAndNodeFromHref(href);\n\n const path = state ? getPathFromState(state) : undefined;\n\n const value = useMemo(\n () => ({\n params,\n pathname: href.toString(),\n segments: path?.split('/').filter(Boolean) || [],\n }),\n [params, href]\n );\n\n // This can happen in a theoretical case where the state is not yet initialized or is incorrectly initialized.\n // It also check ensures TypeScript type safety.\n if (!routeNode) {\n return null;\n }\n\n const Component = getQualifiedRouteComponent(routeNode);\n\n return (\n <PreviewRouteContext value={value}>\n {/* Using NavigationContext to override useNavigation */}\n <NavigationContext value={navigationPropWithWarnings}>\n <Component navigation={navigation} />\n </NavigationContext>\n </PreviewRouteContext>\n );\n}\n\nfunction getParamsAndNodeFromHref(href: Href) {\n const hrefState = store.getStateForHref(href as any);\n if (hrefState?.routes[0] && hrefState.routes[0].name !== INTERNAL_SLOT_NAME) {\n const error = `Expo Router Error: Expected navigation state to begin with a ${INTERNAL_SLOT_NAME} route`;\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(error);\n } else {\n console.warn(error);\n }\n }\n // Assuming that root of the state is __root\n const initialState = hrefState?.routes[0]?.state;\n let state = initialState;\n let routeNode: RouteNode | undefined | null = store.routeNode;\n\n const params: UnknownOutputParams = {};\n\n while (state && routeNode) {\n const route = state.routes[state.index || state.routes.length - 1];\n Object.assign(params, route.params);\n state = route.state;\n routeNode = routeNode.children.find((child) => child.route === route.name);\n }\n\n return { params, routeNode, state: initialState };\n}\n\nconst displayWarningForProp = (prop: string) => {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `navigation.${prop} should not be used in a previewed screen. To fix this issue, wrap navigation calls with 'if (!isPreview) { ... }'.`\n );\n }\n};\n\nconst createNOOPWithWarning = (prop: string) => () => displayWarningForProp(prop);\n\nconst navigationPropWithWarnings: NavigationProp<ParamListBase> = {\n setParams: createNOOPWithWarning('setParams'),\n setOptions: createNOOPWithWarning('setOptions'),\n addListener: (() => () => {}) as NavigationProp<ParamListBase>['addListener'],\n removeListener: () => {},\n isFocused: () => true,\n canGoBack: () => false,\n dispatch: createNOOPWithWarning('dispatch'),\n navigate: createNOOPWithWarning('navigate'),\n goBack: createNOOPWithWarning('goBack'),\n reset: createNOOPWithWarning('reset'),\n push: createNOOPWithWarning('push'),\n pop: createNOOPWithWarning('pop'),\n popToTop: createNOOPWithWarning('popToTop'),\n navigateDeprecated: createNOOPWithWarning('navigateDeprecated'),\n preload: createNOOPWithWarning('preload'),\n getId: () => {\n displayWarningForProp('getId');\n return '';\n },\n // @ts-expect-error\n getParent: createNOOPWithWarning('getParent'),\n getState: () => {\n displayWarningForProp('getState');\n return {\n key: '',\n index: 0,\n routeNames: [],\n routes: [],\n type: '',\n stale: false,\n };\n },\n};\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type ViewProps } from 'react-native';
|
|
2
2
|
export interface NativeLinkPreviewActionProps {
|
|
3
3
|
title: string;
|
|
4
|
+
icon?: string;
|
|
4
5
|
id: string;
|
|
6
|
+
children?: React.ReactNode;
|
|
5
7
|
}
|
|
6
8
|
export declare function NativeLinkPreviewAction(props: NativeLinkPreviewActionProps): import("react").JSX.Element | null;
|
|
7
9
|
export type NativeLinkPreviewTriggerProps = ViewProps;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/link/preview/native.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAGpE,MAAM,WAAW,4BAA4B;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/link/preview/native.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAGpE,MAAM,WAAW,4BAA4B;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAKD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,sCAK1E;AAID,MAAM,MAAM,6BAA6B,GAAG,SAAS,CAAC;AAKtD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,sCAK5E;AAID,MAAM,WAAW,sBAAuB,SAAQ,SAAS;IACvD,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,KAAK,IAAI,CAAC;IACpE,iBAAiB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;IAChC,iBAAiB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,IAAI,CAAC;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAKD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,sCAK9D;AAID,MAAM,WAAW,6BAA8B,SAAQ,SAAS;IAC9D,oBAAoB,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1D;AAMD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,sCAW5E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.js","sourceRoot":"","sources":["../../../src/link/preview/native.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;
|
|
1
|
+
{"version":3,"file":"native.js","sourceRoot":"","sources":["../../../src/link/preview/native.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAgBb,0DAKC;AASD,4DAKC;AAkBD,8CAKC;AAYD,4DAWC;AA/ED,+BAAyC;AACzC,+CAAoE;AASpE,MAAM,2BAA2B,GAC/B,uBAAQ,CAAC,EAAE,KAAK,KAAK;IACnB,CAAC,CAAC,IAAA,wBAAiB,EAAC,6BAA6B,EAAE,6BAA6B,CAAC;IACjF,C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,QAAQ,EAAE,UAAU;SACZ;KACX,CAAC,CAAC;IACH,OAAO,CAAC,4BAA4B,CAAC,IAAI,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,EAAG,CAAC;AACnE,CAAC;AACD,aAAa","sourcesContent":["'use client';\n\nimport { requireNativeView } from 'expo';\nimport { Platform, StyleSheet, type ViewProps } from 'react-native';\n\n// #region Action View\nexport interface NativeLinkPreviewActionProps {\n title: string;\n icon?: string;\n id: string;\n children?: React.ReactNode;\n}\nconst LinkPreviewNativeActionView: React.ComponentType<NativeLinkPreviewActionProps> | null =\n Platform.OS === 'ios'\n ? requireNativeView('ExpoRouterNativeLinkPreview', 'LinkPreviewNativeActionView')\n : null;\nexport function NativeLinkPreviewAction(props: NativeLinkPreviewActionProps) {\n if (!LinkPreviewNativeActionView) {\n return null;\n }\n return <LinkPreviewNativeActionView {...props} />;\n}\n// #endregion\n\n// #region Trigger View\nexport type NativeLinkPreviewTriggerProps = ViewProps;\nconst NativeLinkPreviewTriggerView: React.ComponentType<NativeLinkPreviewTriggerProps> | null =\n Platform.OS === 'ios'\n ? requireNativeView('ExpoRouterNativeLinkPreview', 'NativeLinkPreviewTrigger')\n : null;\nexport function NativeLinkPreviewTrigger(props: NativeLinkPreviewTriggerProps) {\n if (!NativeLinkPreviewTriggerView) {\n return null;\n }\n return <NativeLinkPreviewTriggerView {...props} />;\n}\n// #endregion\n\n// #region Preview View\nexport interface NativeLinkPreviewProps extends ViewProps {\n nextScreenId: string | undefined;\n onActionSelected?: (event: { nativeEvent: { id: string } }) => void;\n onWillPreviewOpen?: () => void;\n onDidPreviewOpen?: () => void;\n onPreviewWillClose?: () => void;\n onPreviewDidClose?: () => void;\n onPreviewTapped?: () => void;\n children: React.ReactNode;\n}\nconst NativeLinkPreviewView: React.ComponentType<NativeLinkPreviewProps> | null =\n Platform.OS === 'ios'\n ? requireNativeView('ExpoRouterNativeLinkPreview', 'NativeLinkPreviewView')\n : null;\nexport function NativeLinkPreview(props: NativeLinkPreviewProps) {\n if (!NativeLinkPreviewView) {\n return null;\n }\n return <NativeLinkPreviewView {...props} />;\n}\n// #endregion\n\n// #region Preview Content View\nexport interface NativeLinkPreviewContentProps extends ViewProps {\n preferredContentSize?: { width: number; height: number };\n}\nconst NativeLinkPreviewContentView: React.ComponentType<NativeLinkPreviewContentProps> | null =\n Platform.OS === 'ios'\n ? requireNativeView('ExpoRouterNativeLinkPreview', 'NativeLinkPreviewContentView')\n : null;\n\nexport function NativeLinkPreviewContent(props: NativeLinkPreviewContentProps) {\n if (!NativeLinkPreviewContentView) {\n return null;\n }\n const style = StyleSheet.flatten([\n props.style,\n {\n position: 'absolute',\n } as const,\n ]);\n return <NativeLinkPreviewContentView {...props} style={style} />;\n}\n// #endregion\n"]}
|
package/build/modal/Modal.d.ts
CHANGED
|
@@ -60,6 +60,8 @@ export interface ModalProps extends ViewProps {
|
|
|
60
60
|
* It always renders on top of the application's content.
|
|
61
61
|
* Internally, the modal is rendered as a `Stack.Screen`, with the presentation style determined by the `presentationStyle` prop.
|
|
62
62
|
*
|
|
63
|
+
* **Props should be set before the modal is opened. Changes to the props will take effect after the modal is reopened.**
|
|
64
|
+
*
|
|
63
65
|
* This component is not linkable. If you need to link to a modal, use `<Stack.Screen options={{ presentationStyle: "modal" }} />` instead.
|
|
64
66
|
*
|
|
65
67
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../../src/modal/Modal.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../../src/modal/Modal.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAInE,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC3C;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B;;;;OAIG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB;;;OAGG;IACH,aAAa,CAAC,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC;IAC7C;;;;;;;;;OASG;IACH,iBAAiB,CAAC,EAAE,WAAW,CAAC,mBAAmB,CAAC,CAAC;IACrD;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,QAgEtC"}
|
package/build/modal/Modal.js
CHANGED
|
@@ -6,11 +6,14 @@ const non_secure_1 = require("nanoid/non-secure");
|
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const ModalContext_1 = require("./ModalContext");
|
|
8
8
|
const useNavigation_1 = require("../useNavigation");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
9
10
|
/**
|
|
10
11
|
* A standalone modal component that can be used in Expo Router apps.
|
|
11
12
|
* It always renders on top of the application's content.
|
|
12
13
|
* Internally, the modal is rendered as a `Stack.Screen`, with the presentation style determined by the `presentationStyle` prop.
|
|
13
14
|
*
|
|
15
|
+
* **Props should be set before the modal is opened. Changes to the props will take effect after the modal is reopened.**
|
|
16
|
+
*
|
|
14
17
|
* This component is not linkable. If you need to link to a modal, use `<Stack.Screen options={{ presentationStyle: "modal" }} />` instead.
|
|
15
18
|
*
|
|
16
19
|
* @example
|
|
@@ -34,6 +37,11 @@ function Modal(props) {
|
|
|
34
37
|
const { openModal, closeModal, addEventListener } = (0, ModalContext_1.useModalContext)();
|
|
35
38
|
const [currentModalId, setCurrentModalId] = (0, react_1.useState)();
|
|
36
39
|
const navigation = (0, useNavigation_1.useNavigation)();
|
|
40
|
+
(0, react_1.useEffect)(() => {
|
|
41
|
+
if (!(0, utils_1.areDetentsValid)(props.detents)) {
|
|
42
|
+
throw new Error(`Invalid detents provided to Modal: ${JSON.stringify(props.detents)}`);
|
|
43
|
+
}
|
|
44
|
+
}, [props.detents]);
|
|
37
45
|
(0, react_1.useEffect)(() => {
|
|
38
46
|
if (!currentModalId && visible) {
|
|
39
47
|
const newId = (0, non_secure_1.nanoid)();
|
|
@@ -43,6 +51,7 @@ function Modal(props) {
|
|
|
43
51
|
transparent,
|
|
44
52
|
viewProps,
|
|
45
53
|
component: children,
|
|
54
|
+
detents: props.detents,
|
|
46
55
|
uniqueId: newId,
|
|
47
56
|
parentNavigationProp: navigation,
|
|
48
57
|
});
|
package/build/modal/Modal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.js","sourceRoot":"","sources":["../../src/modal/Modal.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;
|
|
1
|
+
{"version":3,"file":"Modal.js","sourceRoot":"","sources":["../../src/modal/Modal.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AA6Fb,sBAgEC;AA1JD,kDAA2C;AAC3C,iCAA4C;AAI5C,iDAAmE;AACnE,oDAAiD;AACjD,mCAA0C;AA0D1C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,KAAK,CAAC,KAAiB;IACrC,MAAM,EACJ,QAAQ,EACR,OAAO,EACP,OAAO,EACP,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,GAAG,SAAS,EACb,GAAG,KAAK,CAAC;IACV,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,IAAA,8BAAe,GAAE,CAAC;IACtE,MA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,EAAE;gBACtD,IAAI,EAAE,KAAK,cAAc,EAAE,CAAC;oBAC1B,MAAM,EAAE,EAAE,CAAC;gBACb,CAAC;YACH,CAAC,CAAC,CAAC;YACH,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE;gBACxD,IAAI,EAAE,KAAK,cAAc,EAAE,CAAC;oBAC1B,OAAO,EAAE,EAAE,CAAC;oBACZ,iBAAiB,CAAC,SAAS,CAAC,CAAC;gBAC/B,CAAC;YACH,CAAC,CAAC,CAAC;YACH,OAAO,GAAG,EAAE;gBACV,eAAe,EAAE,CAAC;gBAClB,gBAAgB,EAAE,CAAC;YACrB,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IAClB,CAAC,EAAE,CAAC,cAAc,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC,CAAC;IAChD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["'use client';\n\nimport { type NavigationProp, type ParamListBase } from '@react-navigation/native';\nimport { nanoid } from 'nanoid/non-secure';\nimport { useEffect, useState } from 'react';\nimport { ViewProps } from 'react-native';\nimport { type ScreenProps } from 'react-native-screens';\n\nimport { useModalContext, type ModalConfig } from './ModalContext';\nimport { useNavigation } from '../useNavigation';\nimport { areDetentsValid } from './utils';\n\nexport interface ModalProps extends ViewProps {\n /**\n * The content of the modal.\n */\n children?: React.ReactNode;\n /**\n * Whether the modal is visible or not.\n * When set to `true`, the modal will be opened.\n * When set to `false`, the modal will be closed.\n */\n visible: boolean;\n /**\n * Callback that is called after modal is closed.\n * This is called when the modal is dismissed by the user or programmatically.\n */\n onClose?: () => void;\n /**\n * Callback that is called after modal is shown.\n */\n onShow?: () => void;\n /**\n * The animation type for the modal.\n * This can be one of 'none', 'slide', or 'fade'.\n */\n animationType?: ModalConfig['animationType'];\n /**\n * The presentation style for the modal.\n * This can be one of 'fullScreen', 'pageSheet', 'formSheet', or 'overFullScreen'.\n * - `fullScreen`: The modal covers the entire screen. When `transparent` is set to `true`, it will fallback to `overFullScreen`.\n * - `pageSheet`: The modal is presented as a page sheet on iOS. Defaults to `fullScreen` on Android.\n * - `formSheet`: The modal is presented as a form sheet.\n * - `overFullScreen`: The modal is presented over the full screen, allowing interaction with the underlying content.\n *\n * @default 'fullScreen'\n */\n presentationStyle?: ModalConfig['presentationStyle'];\n /**\n * Whether the modal should be rendered as a transparent overlay.\n * This will render the modal without a background, allowing the content behind it to be visible.\n *\n * On Android, this will fallback to `overFullScreen` presentation style.\n */\n transparent?: boolean;\n /**\n * See {@link ScreenProps[\"sheetAllowedDetents\"]}.\n *\n * Describes heights where a sheet can rest.\n * Works only when `presentation` is set to `formSheet`.\n *\n * Heights should be described as fraction (a number from `[0, 1]` interval) of screen height / maximum detent height.\n * You can pass an array of ascending values each defining allowed sheet detent. iOS accepts any number of detents,\n * while **Android is limited to three**.\n */\n detents?: ModalConfig['detents'];\n}\n\n/**\n * A standalone modal component that can be used in Expo Router apps.\n * It always renders on top of the application's content.\n * Internally, the modal is rendered as a `Stack.Screen`, with the presentation style determined by the `presentationStyle` prop.\n *\n * **Props should be set before the modal is opened. Changes to the props will take effect after the modal is reopened.**\n *\n * This component is not linkable. If you need to link to a modal, use `<Stack.Screen options={{ presentationStyle: \"modal\" }} />` instead.\n *\n * @example\n * ```tsx\n * import { Modal } from 'expo-router';\n *\n * function Page() {\n * const [modalVisible, setModalVisible] = useState(false);\n * return (\n * <Modal\n * visible={modalVisible}\n * onClose={() => setModalVisible(false)}\n * >\n * <Text>Hello World</Text>\n * </Modal>\n * );\n * }\n */\nexport function Modal(props: ModalProps) {\n const {\n children,\n visible,\n onClose,\n onShow,\n animationType,\n presentationStyle,\n transparent,\n ...viewProps\n } = props;\n const { openModal, closeModal, addEventListener } = useModalContext();\n const [currentModalId, setCurrentModalId] = useState<string | undefined>();\n const navigation = useNavigation<NavigationProp<ParamListBase>>();\n useEffect(() => {\n if (!areDetentsValid(props.detents)) {\n throw new Error(`Invalid detents provided to Modal: ${JSON.stringify(props.detents)}`);\n }\n }, [props.detents]);\n useEffect(() => {\n if (!currentModalId && visible) {\n const newId = nanoid();\n openModal({\n animationType,\n presentationStyle,\n transparent,\n viewProps,\n component: children,\n detents: props.detents,\n uniqueId: newId,\n parentNavigationProp: navigation,\n });\n setCurrentModalId(newId);\n return () => {\n closeModal(newId);\n };\n } else if (currentModalId && !visible) {\n closeModal(currentModalId);\n setCurrentModalId(undefined);\n }\n return () => {};\n }, [visible]);\n\n useEffect(() => {\n if (currentModalId) {\n const unsubscribeShow = addEventListener('show', (id) => {\n if (id === currentModalId) {\n onShow?.();\n }\n });\n const unsubscribeClose = addEventListener('close', (id) => {\n if (id === currentModalId) {\n onClose?.();\n setCurrentModalId(undefined);\n }\n });\n return () => {\n unsubscribeShow();\n unsubscribeClose();\n };\n }\n return () => {};\n }, [currentModalId, addEventListener, onClose]);\n return null;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/modal/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,wBAAgB,eAAe,CAAC,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,GAAG,OAAO,CAcvE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.areDetentsValid = areDetentsValid;
|
|
4
|
+
function areDetentsValid(detents) {
|
|
5
|
+
if (Array.isArray(detents)) {
|
|
6
|
+
return (!!detents.length &&
|
|
7
|
+
detents.every((detent, index, arr) => typeof detent === 'number' &&
|
|
8
|
+
detent >= 0 &&
|
|
9
|
+
detent <= 1 &&
|
|
10
|
+
detent >= (arr[index - 1] ?? 0)));
|
|
11
|
+
}
|
|
12
|
+
return detents === 'fitToContents' || detents === undefined || detents === null;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/modal/utils.ts"],"names":[],"mappings":";;AAEA,0CAcC;AAdD,SAAgB,eAAe,CAAC,OAA8B;IAC5D,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,CACL,CAAC,CAAC,OAAO,CAAC,MAAM;YAChB,OAAO,CAAC,KAAK,CACX,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CACrB,OAAO,MAAM,KAAK,QAAQ;gBAC1B,MAAM,IAAI,CAAC;gBACX,MAAM,IAAI,CAAC;gBACX,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAClC,CACF,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,KAAK,eAAe,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,CAAC;AAClF,CAAC","sourcesContent":["import type { ModalProps } from './Modal';\n\nexport function areDetentsValid(detents: ModalProps['detents']): boolean {\n if (Array.isArray(detents)) {\n return (\n !!detents.length &&\n detents.every(\n (detent, index, arr) =>\n typeof detent === 'number' &&\n detent >= 0 &&\n detent <= 1 &&\n detent >= (arr[index - 1] ?? 0)\n )\n );\n }\n return detents === 'fitToContents' || detents === undefined || detents === null;\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ParamListBase } from '@react-navigation/native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
declare const RouterModal: React.ForwardRefExoticComponent<Omit<import("../..").PickPartial<any, "children">, "ref"> & React.RefAttributes<unknown>> & {
|
|
4
|
+
Screen: (props: import("../..").ScreenProps<object, Readonly<{
|
|
5
|
+
key: string;
|
|
6
|
+
index: number;
|
|
7
|
+
routeNames: string[];
|
|
8
|
+
history?: unknown[];
|
|
9
|
+
routes: import("@react-navigation/native").NavigationRoute<ParamListBase, string>[];
|
|
10
|
+
type: string;
|
|
11
|
+
stale: false;
|
|
12
|
+
}>, import("@react-navigation/native").EventMapBase>) => null;
|
|
13
|
+
Protected: typeof import("../../views/Protected").Protected;
|
|
14
|
+
};
|
|
15
|
+
declare const RouterModalScreen: (props: import("../..").ScreenProps<object, Readonly<{
|
|
16
|
+
key: string;
|
|
17
|
+
index: number;
|
|
18
|
+
routeNames: string[];
|
|
19
|
+
history?: unknown[];
|
|
20
|
+
routes: import("@react-navigation/native").NavigationRoute<ParamListBase, string>[];
|
|
21
|
+
type: string;
|
|
22
|
+
stale: false;
|
|
23
|
+
}>, import("@react-navigation/native").EventMapBase>) => null;
|
|
24
|
+
export { RouterModal, RouterModalScreen };
|
|
25
|
+
//# sourceMappingURL=ModalStack.web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModalStack.web.d.ts","sourceRoot":"","sources":["../../../src/modal/web/ModalStack.web.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,aAAa,EAOd,MAAM,0BAA0B,CAAC;AAMlC,OAAO,KAAsB,MAAM,OAAO,CAAC;AAwG3C,QAAA,MAAM,WAAW;;;;;;;;;;;CAAkD,CAAC;AACpE,QAAA,MAAM,iBAAiB;;;;;;;;6DAAqB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.RouterModalScreen = exports.RouterModal = void 0;
|
|
38
|
+
const native_1 = require("@react-navigation/native");
|
|
39
|
+
const native_stack_1 = require("@react-navigation/native-stack");
|
|
40
|
+
const react_1 = __importStar(require("react"));
|
|
41
|
+
const ModalStackRouteDrawer_web_1 = require("./ModalStackRouteDrawer.web");
|
|
42
|
+
const TransparentModalStackRouteDrawer_web_1 = require("./TransparentModalStackRouteDrawer.web");
|
|
43
|
+
const utils_1 = require("./utils");
|
|
44
|
+
const withLayoutContext_1 = require("../../layouts/withLayoutContext");
|
|
45
|
+
function ModalStackNavigator({ initialRouteName, children, screenOptions, }) {
|
|
46
|
+
const { state, navigation, descriptors, NavigationContent, describe } = (0, native_1.useNavigationBuilder)(native_1.StackRouter, {
|
|
47
|
+
children,
|
|
48
|
+
screenOptions,
|
|
49
|
+
initialRouteName,
|
|
50
|
+
});
|
|
51
|
+
return (<NavigationContent>
|
|
52
|
+
<ModalStackView state={state} navigation={navigation} descriptors={descriptors} describe={describe}/>
|
|
53
|
+
</NavigationContent>);
|
|
54
|
+
}
|
|
55
|
+
const ModalStackView = ({ state, navigation, descriptors, describe }) => {
|
|
56
|
+
const isWeb = process.env.EXPO_OS === 'web';
|
|
57
|
+
const { colors } = (0, native_1.useTheme)();
|
|
58
|
+
const { routes: filteredRoutes, index: nonModalIndex } = (0, utils_1.convertStackStateToNonModalState)(state, descriptors, isWeb);
|
|
59
|
+
const newStackState = { ...state, routes: filteredRoutes, index: nonModalIndex };
|
|
60
|
+
const dismiss = (0, react_1.useCallback)(() => {
|
|
61
|
+
navigation.goBack();
|
|
62
|
+
}, [navigation]);
|
|
63
|
+
const overlayRoutes = react_1.default.useMemo(() => {
|
|
64
|
+
if (!isWeb)
|
|
65
|
+
return [];
|
|
66
|
+
const idx = (0, utils_1.findLastNonModalIndex)(state, descriptors);
|
|
67
|
+
return state.routes.slice(idx + 1);
|
|
68
|
+
}, [isWeb, state, descriptors]);
|
|
69
|
+
return (<div style={{ flex: 1, display: 'flex' }}>
|
|
70
|
+
<native_stack_1.NativeStackView state={newStackState} navigation={navigation} descriptors={descriptors} describe={describe}/>
|
|
71
|
+
{isWeb &&
|
|
72
|
+
overlayRoutes.map((route) => {
|
|
73
|
+
const isTransparentModal = (0, utils_1.isTransparentModalPresentation)(descriptors[route.key].options);
|
|
74
|
+
if (isTransparentModal) {
|
|
75
|
+
return (<TransparentModalStackRouteDrawer_web_1.TransparentModalStackRouteDrawer key={route.key} routeKey={route.key} options={descriptors[route.key].options} renderScreen={descriptors[route.key].render} onDismiss={dismiss}/>);
|
|
76
|
+
}
|
|
77
|
+
return (<ModalStackRouteDrawer_web_1.ModalStackRouteDrawer key={route.key} routeKey={route.key} options={descriptors[route.key].options} renderScreen={descriptors[route.key].render} onDismiss={dismiss} themeColors={colors}/>);
|
|
78
|
+
})}
|
|
79
|
+
</div>);
|
|
80
|
+
};
|
|
81
|
+
const createModalStack = (0, native_1.createNavigatorFactory)(ModalStackNavigator);
|
|
82
|
+
const RouterModal = (0, withLayoutContext_1.withLayoutContext)(createModalStack().Navigator);
|
|
83
|
+
exports.RouterModal = RouterModal;
|
|
84
|
+
const RouterModalScreen = RouterModal.Screen;
|
|
85
|
+
exports.RouterModalScreen = RouterModalScreen;
|
|
86
|
+
//# sourceMappingURL=ModalStack.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModalStack.web.js","sourceRoot":"","sources":["../../../src/modal/web/ModalStack.web.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACb,qDASkC;AAClC,iEAIwC;AACxC,+CAA2C;AAE3C,2EAAoE;AACpE,iGAA0F;AAE1F,mCAIiB;AAEjB,uEAAoE;AAEpE,SAAS,mBAAmB,CAAC,EAC3B,gBAAgB,EAChB,QAAQ,EACR,aAAa,GACY;IACzB,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,QAAQ,EAAE,GAAG,IAAA,6BAAoB,EAM1F,oBAAW,EAAE;QACb,QAAQ;QACR,aAAa;QACb,gBAAgB;KACjB,CAAC,CAAC;IAEH,OAAO,CACL,CAAC,iBAAiB,CAChB;MAAA,CAAC,cAAc,CACb,KAAK,CAAC,CAAC,KAAK,CAAC,CACb,UAAU,CAAC,CAAC,UAAU,CAAC,CACvB,WAAW,CAAC,CAAC,WAAW,CAAC,CACzB,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAEvB;IAAA,EAAE,iBAAiB,CAAC,CACrB,CAAC;AACJ,CAAC;AAED,MAAM,cAAc,GAAG,CAAC,EAAE,KAAK,EAAE,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import {\n createNavigatorFactory,\n ParamListBase,\n StackActionHelpers,\n StackNavigationState,\n StackRouter,\n StackRouterOptions,\n useNavigationBuilder,\n useTheme,\n} from '@react-navigation/native';\nimport {\n NativeStackNavigationEventMap,\n NativeStackNavigationOptions,\n NativeStackView,\n} from '@react-navigation/native-stack';\nimport React, { useCallback } from 'react';\n\nimport { ModalStackRouteDrawer } from './ModalStackRouteDrawer.web';\nimport { TransparentModalStackRouteDrawer } from './TransparentModalStackRouteDrawer.web';\nimport { ModalStackNavigatorProps, ModalStackViewProps } from './types';\nimport {\n convertStackStateToNonModalState,\n findLastNonModalIndex,\n isTransparentModalPresentation,\n} from './utils';\nimport { ExtendedStackNavigationOptions } from '../../layouts/StackClient';\nimport { withLayoutContext } from '../../layouts/withLayoutContext';\n\nfunction ModalStackNavigator({\n initialRouteName,\n children,\n screenOptions,\n}: ModalStackNavigatorProps) {\n const { state, navigation, descriptors, NavigationContent, describe } = useNavigationBuilder<\n StackNavigationState<ParamListBase>,\n StackRouterOptions,\n StackActionHelpers<ParamListBase>,\n NativeStackNavigationOptions,\n NativeStackNavigationEventMap\n >(StackRouter, {\n children,\n screenOptions,\n initialRouteName,\n });\n\n return (\n <NavigationContent>\n <ModalStackView\n state={state}\n navigation={navigation}\n descriptors={descriptors}\n describe={describe}\n />\n </NavigationContent>\n );\n}\n\nconst ModalStackView = ({ state, navigation, descriptors, describe }: ModalStackViewProps) => {\n const isWeb = process.env.EXPO_OS === 'web';\n const { colors } = useTheme();\n\n const { routes: filteredRoutes, index: nonModalIndex } = convertStackStateToNonModalState(\n state,\n descriptors,\n isWeb\n );\n\n const newStackState = { ...state, routes: filteredRoutes, index: nonModalIndex };\n\n const dismiss = useCallback(() => {\n navigation.goBack();\n }, [navigation]);\n\n const overlayRoutes = React.useMemo(() => {\n if (!isWeb) return [];\n const idx = findLastNonModalIndex(state, descriptors);\n return state.routes.slice(idx + 1);\n }, [isWeb, state, descriptors]);\n\n return (\n <div style={{ flex: 1, display: 'flex' }}>\n <NativeStackView\n state={newStackState}\n navigation={navigation}\n descriptors={descriptors}\n describe={describe}\n />\n {isWeb &&\n overlayRoutes.map((route) => {\n const isTransparentModal = isTransparentModalPresentation(descriptors[route.key].options);\n\n if (isTransparentModal) {\n return (\n <TransparentModalStackRouteDrawer\n key={route.key}\n routeKey={route.key}\n options={descriptors[route.key].options as ExtendedStackNavigationOptions}\n renderScreen={descriptors[route.key].render}\n onDismiss={dismiss}\n />\n );\n }\n\n return (\n <ModalStackRouteDrawer\n key={route.key}\n routeKey={route.key}\n options={descriptors[route.key].options as ExtendedStackNavigationOptions}\n renderScreen={descriptors[route.key].render}\n onDismiss={dismiss}\n themeColors={colors}\n />\n );\n })}\n </div>\n );\n};\n\nconst createModalStack = createNavigatorFactory(ModalStackNavigator);\nconst RouterModal = withLayoutContext(createModalStack().Navigator);\nconst RouterModalScreen = RouterModal.Screen;\n\nexport { RouterModal, RouterModalScreen };\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ExtendedStackNavigationOptions } from '../../layouts/StackClient';
|
|
3
|
+
declare function ModalStackRouteDrawer({ routeKey, options, renderScreen, onDismiss, themeColors, }: {
|
|
4
|
+
routeKey: string;
|
|
5
|
+
options: ExtendedStackNavigationOptions;
|
|
6
|
+
renderScreen: () => React.ReactNode;
|
|
7
|
+
onDismiss: () => void;
|
|
8
|
+
themeColors: {
|
|
9
|
+
card: string;
|
|
10
|
+
background: string;
|
|
11
|
+
};
|
|
12
|
+
}): React.JSX.Element;
|
|
13
|
+
export { ModalStackRouteDrawer };
|
|
14
|
+
//# sourceMappingURL=ModalStackRouteDrawer.web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModalStackRouteDrawer.web.d.ts","sourceRoot":"","sources":["../../../src/modal/web/ModalStackRouteDrawer.web.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAE3E,iBAAS,qBAAqB,CAAC,EAC7B,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,SAAS,EACT,WAAW,GACZ,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,8BAA8B,CAAC;IACxC,YAAY,EAAE,MAAM,KAAK,CAAC,SAAS,CAAC;IACpC,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CACnD,qBAmMA;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|