expo-router 5.2.0-canary-20250729-d8899ae → 6.0.0-beta.0
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/_ctx.android.js +1 -1
- package/_ctx.ios.js +1 -1
- package/_ctx.web.js +1 -1
- package/assets/modal.module.css +12 -3
- package/build/ExpoRoot.d.ts.map +1 -1
- package/build/ExpoRoot.js +12 -2
- package/build/ExpoRoot.js.map +1 -1
- package/build/Route.d.ts +9 -0
- package/build/Route.d.ts.map +1 -1
- package/build/Route.js.map +1 -1
- package/build/constants.d.ts +2 -0
- package/build/constants.d.ts.map +1 -1
- package/build/constants.js +3 -1
- package/build/constants.js.map +1 -1
- package/build/doctor/index.d.ts +1 -1
- package/build/doctor/index.d.ts.map +1 -1
- package/build/doctor/index.js +4 -1
- package/build/doctor/index.js.map +1 -1
- package/build/exports.d.ts +2 -2
- package/build/exports.d.ts.map +1 -1
- package/build/exports.js +6 -6
- package/build/exports.js.map +1 -1
- package/build/fork/native-stack/createNativeStackNavigator.d.ts +2 -2
- package/build/fork/native-stack/createNativeStackNavigator.d.ts.map +1 -1
- package/build/fork/native-stack/createNativeStackNavigator.js +82 -2
- package/build/fork/native-stack/createNativeStackNavigator.js.map +1 -1
- package/build/fork/useLinking.js +2 -2
- package/build/fork/useLinking.js.map +1 -1
- package/build/getLinkingConfig.d.ts +29 -2
- package/build/getLinkingConfig.d.ts.map +1 -1
- package/build/getLinkingConfig.js +35 -4
- package/build/getLinkingConfig.js.map +1 -1
- package/build/getRoutesCore.d.ts +1 -0
- package/build/getRoutesCore.d.ts.map +1 -1
- package/build/getRoutesCore.js +60 -0
- package/build/getRoutesCore.js.map +1 -1
- package/build/getServerManifest.d.ts +20 -1
- package/build/getServerManifest.d.ts.map +1 -1
- package/build/getServerManifest.js +8 -1
- package/build/getServerManifest.js.map +1 -1
- package/build/global-state/routeInfo.d.ts.map +1 -1
- package/build/global-state/routeInfo.js +12 -1
- package/build/global-state/routeInfo.js.map +1 -1
- package/build/global-state/router-store.d.ts.map +1 -1
- package/build/global-state/router-store.js +4 -0
- package/build/global-state/router-store.js.map +1 -1
- package/build/global-state/routing.d.ts +29 -1
- package/build/global-state/routing.d.ts.map +1 -1
- package/build/global-state/routing.js +78 -42
- package/build/global-state/routing.js.map +1 -1
- package/build/global-state/utils.d.ts +4 -0
- package/build/global-state/utils.d.ts.map +1 -0
- package/build/global-state/utils.js +29 -0
- package/build/global-state/utils.js.map +1 -0
- package/build/hooks.d.ts +1 -1
- package/build/hooks.d.ts.map +1 -1
- package/build/hooks.js +9 -4
- package/build/hooks.js.map +1 -1
- package/build/layouts/DrawerClient.d.ts +2 -2
- package/build/layouts/Stack.web.d.ts +1 -1
- package/build/layouts/Stack.web.d.ts.map +1 -1
- package/build/layouts/Stack.web.js +3 -3
- package/build/layouts/Stack.web.js.map +1 -1
- package/build/layouts/StackClient.d.ts +2 -2
- package/build/layouts/StackClient.d.ts.map +1 -1
- package/build/layouts/StackClient.js +18 -14
- package/build/layouts/StackClient.js.map +1 -1
- package/build/layouts/TabsClient.d.ts +3 -3
- package/build/layouts/withLayoutContext.d.ts.map +1 -1
- package/build/layouts/withLayoutContext.js +13 -0
- package/build/layouts/withLayoutContext.js.map +1 -1
- package/build/link/ExpoLink.d.ts.map +1 -1
- package/build/link/ExpoLink.js +3 -2
- package/build/link/ExpoLink.js.map +1 -1
- package/build/link/InternalLinkPreviewContext.d.ts +6 -0
- package/build/link/InternalLinkPreviewContext.d.ts.map +1 -0
- package/build/link/InternalLinkPreviewContext.js +6 -0
- package/build/link/InternalLinkPreviewContext.js.map +1 -0
- package/build/link/Link.d.ts +2 -67
- package/build/link/Link.d.ts.map +1 -1
- package/build/link/Link.js +5 -70
- package/build/link/Link.js.map +1 -1
- package/build/link/LinkWithPreview.d.ts +1 -46
- package/build/link/LinkWithPreview.d.ts.map +1 -1
- package/build/link/LinkWithPreview.js +30 -114
- package/build/link/LinkWithPreview.js.map +1 -1
- package/build/link/elements.d.ts +174 -0
- package/build/link/elements.d.ts.map +1 -0
- package/build/link/elements.js +172 -0
- package/build/link/elements.js.map +1 -0
- package/build/link/preview/HrefPreview.d.ts +1 -1
- package/build/link/preview/HrefPreview.d.ts.map +1 -1
- package/build/link/preview/HrefPreview.js +61 -7
- package/build/link/preview/HrefPreview.js.map +1 -1
- package/build/link/preview/LinkPreviewContext.d.ts +3 -2
- package/build/link/preview/LinkPreviewContext.d.ts.map +1 -1
- package/build/link/preview/LinkPreviewContext.js +3 -2
- package/build/link/preview/LinkPreviewContext.js.map +1 -1
- package/build/link/preview/native.d.ts +14 -6
- package/build/link/preview/native.d.ts.map +1 -1
- package/build/link/preview/native.js.map +1 -1
- package/build/link/preview/useNextScreenId.d.ts +8 -1
- package/build/link/preview/useNextScreenId.d.ts.map +1 -1
- package/build/link/preview/useNextScreenId.js +36 -32
- package/build/link/preview/useNextScreenId.js.map +1 -1
- package/build/link/preview/utils.d.ts +12 -0
- package/build/link/preview/utils.d.ts.map +1 -0
- package/build/link/preview/utils.js +66 -0
- package/build/link/preview/utils.js.map +1 -0
- package/build/modal/Modal.js +1 -1
- package/build/modal/Modal.js.map +1 -1
- package/build/modal/ModalsRenderer.js +1 -1
- package/build/modal/ModalsRenderer.js.map +1 -1
- package/build/modal/ModalsRenderer.web.js +4 -4
- package/build/modal/ModalsRenderer.web.js.map +1 -1
- package/build/modal/web/{ModalStack.web.d.ts → ModalStack.d.ts} +1 -1
- package/build/modal/web/ModalStack.d.ts.map +1 -0
- package/build/modal/web/{ModalStack.web.js → ModalStack.js} +5 -5
- package/build/modal/web/ModalStack.js.map +1 -0
- package/build/modal/web/{ModalStackRouteDrawer.web.d.ts → ModalStackRouteDrawer.d.ts} +1 -1
- package/build/modal/web/ModalStackRouteDrawer.d.ts.map +1 -0
- package/build/modal/web/{ModalStackRouteDrawer.web.js → ModalStackRouteDrawer.js} +1 -2
- package/build/modal/web/ModalStackRouteDrawer.js.map +1 -0
- package/build/modal/web/{TransparentModalStackRouteDrawer.web.d.ts → TransparentModalStackRouteDrawer.d.ts} +1 -1
- package/build/modal/web/TransparentModalStackRouteDrawer.d.ts.map +1 -0
- package/build/modal/web/{TransparentModalStackRouteDrawer.web.js → TransparentModalStackRouteDrawer.js} +1 -1
- package/build/modal/web/TransparentModalStackRouteDrawer.js.map +1 -0
- package/build/native-tabs/NativeBottomTabs/NativeBottomTabsNavigator.d.ts +17 -0
- package/build/native-tabs/NativeBottomTabs/NativeBottomTabsNavigator.d.ts.map +1 -0
- package/build/native-tabs/NativeBottomTabs/NativeBottomTabsNavigator.js +27 -0
- package/build/native-tabs/NativeBottomTabs/NativeBottomTabsNavigator.js.map +1 -0
- package/build/native-tabs/NativeBottomTabs/NativeBottomTabsRouter.d.ts +3 -0
- package/build/native-tabs/NativeBottomTabs/NativeBottomTabsRouter.d.ts.map +1 -0
- package/build/native-tabs/NativeBottomTabs/NativeBottomTabsRouter.js +65 -0
- package/build/native-tabs/NativeBottomTabs/NativeBottomTabsRouter.js.map +1 -0
- package/build/native-tabs/NativeBottomTabs/NativeTabTrigger.d.ts +47 -0
- package/build/native-tabs/NativeBottomTabs/NativeTabTrigger.d.ts.map +1 -0
- package/build/native-tabs/NativeBottomTabs/NativeTabTrigger.js +153 -0
- package/build/native-tabs/NativeBottomTabs/NativeTabTrigger.js.map +1 -0
- package/build/native-tabs/NativeBottomTabs/NativeTabs.d.ts +24 -0
- package/build/native-tabs/NativeBottomTabs/NativeTabs.d.ts.map +1 -0
- package/build/native-tabs/NativeBottomTabs/NativeTabs.js +27 -0
- package/build/native-tabs/NativeBottomTabs/NativeTabs.js.map +1 -0
- package/build/native-tabs/NativeBottomTabs/NativeTabsView.d.ts +4 -0
- package/build/native-tabs/NativeBottomTabs/NativeTabsView.d.ts.map +1 -0
- package/build/native-tabs/NativeBottomTabs/NativeTabsView.js +116 -0
- package/build/native-tabs/NativeBottomTabs/NativeTabsView.js.map +1 -0
- package/build/native-tabs/NativeBottomTabs/types.d.ts +166 -0
- package/build/native-tabs/NativeBottomTabs/types.d.ts.map +1 -0
- package/build/native-tabs/NativeBottomTabs/types.js +3 -0
- package/build/native-tabs/NativeBottomTabs/types.js.map +1 -0
- package/build/native-tabs/NativeBottomTabs/utils.d.ts +7 -0
- package/build/native-tabs/NativeBottomTabs/utils.d.ts.map +1 -0
- package/build/native-tabs/NativeBottomTabs/utils.js +21 -0
- package/build/native-tabs/NativeBottomTabs/utils.js.map +1 -0
- package/build/native-tabs/common/elements.d.ts +74 -0
- package/build/native-tabs/common/elements.d.ts.map +1 -0
- package/build/native-tabs/common/elements.js +21 -0
- package/build/native-tabs/common/elements.js.map +1 -0
- package/build/native-tabs/index.d.ts +5 -0
- package/build/native-tabs/index.d.ts.map +1 -0
- package/build/native-tabs/index.js +23 -0
- package/build/native-tabs/index.js.map +1 -0
- package/build/routes-manifest.d.ts +42 -0
- package/build/routes-manifest.d.ts.map +1 -1
- package/build/routes-manifest.js.map +1 -1
- package/build/rsc/middleware.d.ts +1 -1
- package/build/rsc/middleware.d.ts.map +1 -1
- package/build/rsc/middleware.js.map +1 -1
- package/build/testing-library/mock-config.d.ts +18 -0
- package/build/testing-library/mock-config.d.ts.map +1 -1
- package/build/testing-library/mock-config.js +4 -1
- package/build/testing-library/mock-config.js.map +1 -1
- package/build/ui/common.d.ts.map +1 -1
- package/build/ui/common.js +7 -6
- package/build/ui/common.js.map +1 -1
- package/build/useNavigation.d.ts.map +1 -1
- package/build/useNavigation.js +8 -5
- package/build/useNavigation.js.map +1 -1
- package/build/views/NoSSR.d.ts +5 -0
- package/build/views/NoSSR.d.ts.map +1 -0
- package/build/views/NoSSR.js +22 -0
- package/build/views/NoSSR.js.map +1 -0
- package/build/views/Screen.d.ts.map +1 -1
- package/build/views/Screen.js +4 -1
- package/build/views/Screen.js.map +1 -1
- package/build/views/Sitemap.d.ts.map +1 -1
- package/build/views/Sitemap.js +113 -10
- package/build/views/Sitemap.js.map +1 -1
- package/build/views/Unmatched.d.ts.map +1 -1
- package/build/views/Unmatched.js +14 -4
- package/build/views/Unmatched.js.map +1 -1
- package/ios/ExpoHead.podspec +10 -1
- package/ios/LinkPreview/LinkPreviewNativeActionView.swift +159 -21
- package/ios/LinkPreview/LinkPreviewNativeModule.swift +44 -6
- package/ios/LinkPreview/LinkPreviewNativeNavigation.h +37 -11
- package/ios/LinkPreview/LinkPreviewNativeNavigation.mm +110 -87
- package/ios/LinkPreview/LinkPreviewNativeNavigation.swift +136 -0
- package/ios/LinkPreview/LinkPreviewNativePreviewView.swift +0 -1
- package/ios/LinkPreview/LinkPreviewNativeTriggerView.swift +1 -1
- package/ios/LinkPreview/LinkPreviewNativeView.swift +72 -71
- package/package.json +42 -10
- package/plugin/build/index.d.ts +2 -0
- package/plugin/options.json +5 -0
- package/plugin/src/index.ts +2 -0
- package/plugin/tsconfig.tsbuildinfo +1 -0
- package/server.d.ts +2 -1
- package/unstable-native-tabs.d.ts +1 -0
- package/unstable-native-tabs.js +1 -0
- package/build/modal/web/ModalStack.web.d.ts.map +0 -1
- package/build/modal/web/ModalStack.web.js.map +0 -1
- package/build/modal/web/ModalStackRouteDrawer.web.d.ts.map +0 -1
- package/build/modal/web/ModalStackRouteDrawer.web.js.map +0 -1
- package/build/modal/web/TransparentModalStackRouteDrawer.web.d.ts.map +0 -1
- package/build/modal/web/TransparentModalStackRouteDrawer.web.js.map +0 -1
|
@@ -0,0 +1,172 @@
|
|
|
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.LinkMenu = void 0;
|
|
38
|
+
exports.LinkMenuAction = LinkMenuAction;
|
|
39
|
+
exports.LinkPreview = LinkPreview;
|
|
40
|
+
exports.LinkTrigger = LinkTrigger;
|
|
41
|
+
const react_1 = __importStar(require("react"));
|
|
42
|
+
const InternalLinkPreviewContext_1 = require("./InternalLinkPreviewContext");
|
|
43
|
+
const HrefPreview_1 = require("./preview/HrefPreview");
|
|
44
|
+
const PreviewRouteContext_1 = require("./preview/PreviewRouteContext");
|
|
45
|
+
const native_1 = require("./preview/native");
|
|
46
|
+
const Slot_1 = require("../ui/Slot");
|
|
47
|
+
/**
|
|
48
|
+
* This component renders a context menu action for a link.
|
|
49
|
+
* It should only be used as a child of `Link.Menu` or `LinkMenu`.
|
|
50
|
+
*
|
|
51
|
+
* > **Note**: You can use the alias `Link.MenuAction` for this component.
|
|
52
|
+
*
|
|
53
|
+
* @platform ios
|
|
54
|
+
*/
|
|
55
|
+
function LinkMenuAction(props) {
|
|
56
|
+
if ((0, PreviewRouteContext_1.useIsPreview)() || process.env.EXPO_OS !== 'ios' || !(0, react_1.use)(InternalLinkPreviewContext_1.InternalLinkPreviewContext)) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const { unstable_keepPresented, onPress, ...rest } = props;
|
|
60
|
+
return (<native_1.NativeLinkPreviewAction {...rest} onSelected={onPress} keepPresented={unstable_keepPresented}/>);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Groups context menu actions for a link.
|
|
64
|
+
*
|
|
65
|
+
* If multiple `Link.Menu` components are used within a single `Link`, only the first will be rendered.
|
|
66
|
+
* Only `Link.MenuAction` and `LinkMenuAction` components are allowed as children.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```tsx
|
|
70
|
+
* <Link.Menu>
|
|
71
|
+
* <Link.MenuAction title="Action 1" onPress={() => {}} />
|
|
72
|
+
* <Link.MenuAction title="Action 2" onPress={() => {}} />
|
|
73
|
+
* </Link.Menu>
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* > **Note**: You can use the alias `Link.Menu` for this component.
|
|
77
|
+
*
|
|
78
|
+
* @platform ios
|
|
79
|
+
*/
|
|
80
|
+
const LinkMenu = (props) => {
|
|
81
|
+
if ((0, PreviewRouteContext_1.useIsPreview)() || process.env.EXPO_OS !== 'ios' || !(0, react_1.use)(InternalLinkPreviewContext_1.InternalLinkPreviewContext)) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const children = react_1.default.Children.toArray(props.children).filter((child) => (0, react_1.isValidElement)(child) && (child.type === LinkMenuAction || child.type === exports.LinkMenu));
|
|
85
|
+
return (<native_1.NativeLinkPreviewAction {...props} title={props.title ?? ''} onSelected={() => { }} children={children}/>);
|
|
86
|
+
};
|
|
87
|
+
exports.LinkMenu = LinkMenu;
|
|
88
|
+
/**
|
|
89
|
+
* A component used to render and customize the link preview.
|
|
90
|
+
*
|
|
91
|
+
* If `Link.Preview` is used without any props, it will render a preview of the `href` passed to the `Link`.
|
|
92
|
+
*
|
|
93
|
+
* If multiple `Link.Preview` components are used within a single `Link`, only the first one will be rendered.
|
|
94
|
+
*
|
|
95
|
+
* To customize the preview, you can pass custom content as children.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* <Link href="/about">
|
|
100
|
+
* <Link.Preview>
|
|
101
|
+
* <Text>Custom Preview Content</Text>
|
|
102
|
+
* </Link.Trigger>
|
|
103
|
+
* </Link>
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```tsx
|
|
108
|
+
* <Link href="/about">
|
|
109
|
+
* <Link.Preview />
|
|
110
|
+
* </Link>
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* > **Note**: You can use the alias `Link.Preview` for this component.
|
|
114
|
+
*
|
|
115
|
+
* @platform ios
|
|
116
|
+
*/
|
|
117
|
+
function LinkPreview(props) {
|
|
118
|
+
const { width, height, children } = props;
|
|
119
|
+
const internalPreviewContext = (0, react_1.use)(InternalLinkPreviewContext_1.InternalLinkPreviewContext);
|
|
120
|
+
if ((0, PreviewRouteContext_1.useIsPreview)() || process.env.EXPO_OS !== 'ios' || !internalPreviewContext) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const { isVisible, href } = internalPreviewContext;
|
|
124
|
+
const contentSize = {
|
|
125
|
+
width: width ?? 0,
|
|
126
|
+
height: height ?? 0,
|
|
127
|
+
};
|
|
128
|
+
let content;
|
|
129
|
+
if (children) {
|
|
130
|
+
content = isVisible ? children : null;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
content = isVisible ? <HrefPreview_1.HrefPreview href={href}/> : null;
|
|
134
|
+
}
|
|
135
|
+
return (<native_1.NativeLinkPreviewContent style={{
|
|
136
|
+
/* Setting default background here, so that the preview is not transparent */
|
|
137
|
+
backgroundColor: '#fff',
|
|
138
|
+
}} preferredContentSize={contentSize}>
|
|
139
|
+
{content}
|
|
140
|
+
</native_1.NativeLinkPreviewContent>);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Serves as the trigger for a link.
|
|
144
|
+
* The content inside this component will be rendered as part of the base link.
|
|
145
|
+
*
|
|
146
|
+
* If multiple `Link.Trigger` components are used within a single `Link`, only the first will be rendered.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```tsx
|
|
150
|
+
* <Link href="/about">
|
|
151
|
+
* <Link.Trigger>
|
|
152
|
+
* Trigger
|
|
153
|
+
* </Link.Trigger>
|
|
154
|
+
* </Link>
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* > **Note**: You can use the alias `Link.Trigger` for this component.
|
|
158
|
+
*
|
|
159
|
+
* @platform ios
|
|
160
|
+
*/
|
|
161
|
+
function LinkTrigger(props) {
|
|
162
|
+
if (react_1.default.Children.count(props.children) > 1 || !(0, react_1.isValidElement)(props.children)) {
|
|
163
|
+
// If onPress is passed, this means that Link passed props to this component.
|
|
164
|
+
// We can assume that asChild is used, so we throw an error, because link will not work in this case.
|
|
165
|
+
if (props && typeof props === 'object' && 'onPress' in props) {
|
|
166
|
+
throw new Error('When using Link.Trigger in an asChild Link, you must pass a single child element that will emit onPress event.');
|
|
167
|
+
}
|
|
168
|
+
return props.children;
|
|
169
|
+
}
|
|
170
|
+
return <Slot_1.Slot {...props}/>;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=elements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elements.js","sourceRoot":"","sources":["../../src/link/elements.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;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AAC;AAYD;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,WAAW,CAAC,KAAuB;IACjD,IAAI,eAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAA,sBAAc,EAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChF,6EAA6E;QAC7E,qGAAqG;QACrG,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;YAC7D,MAAM,IAAI,KAAK,CACb,gHAAgH,CACjH,CAAC;QACJ,CAAC;QACD,OAAO,KAAK,CAAC,QAAQ,CAAC;IACxB,CAAC;IACD,OAAO,CAAC,WAAI,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AAC7B,CAAC","sourcesContent":["'use client';\n\nimport React, { isValidElement, use, type PropsWithChildren, type ReactElement } from 'react';\nimport type { SFSymbol } from 'sf-symbols-typescript';\n\nimport { InternalLinkPreviewContext } from './InternalLinkPreviewContext';\nimport { HrefPreview } from './preview/HrefPreview';\nimport { useIsPreview } from './preview/PreviewRouteContext';\nimport { NativeLinkPreviewAction, NativeLinkPreviewContent } from './preview/native';\nimport { Slot } from '../ui/Slot';\n\nexport interface 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 /**\n * If `true`, the menu item will be disabled and not selectable.\n *\n * @see [Apple documentation](https://developer.apple.com/documentation/uikit/uimenuelement/attributes/disabled) for more information.\n */\n disabled?: boolean;\n /**\n * If `true`, the menu item will be displayed as destructive.\n *\n * @see [Apple documentation](https://developer.apple.com/documentation/uikit/uimenuelement/attributes/destructive) for more information.\n */\n destructive?: boolean;\n /**\n * If `true`, the menu will be kept presented after the action is selected.\n *\n * This is marked as unstable, because when action is selected it will recreate the menu,\n * which will close all opened submenus and reset the scroll position.\n *\n * @see [Apple documentation](https://developer.apple.com/documentation/uikit/uimenuelement/attributes/keepsmenupresented) for more information.\n */\n unstable_keepPresented?: boolean;\n /**\n * If `true`, the menu item will be displayed as selected.\n */\n isOn?: boolean;\n onPress: () => void;\n}\n\n/**\n * This component renders a context menu action for a link.\n * It should only be used as a child of `Link.Menu` or `LinkMenu`.\n *\n * > **Note**: You can use the alias `Link.MenuAction` for this component.\n *\n * @platform ios\n */\nexport function LinkMenuAction(props: LinkMenuActionProps) {\n if (useIsPreview() || process.env.EXPO_OS !== 'ios' || !use(InternalLinkPreviewContext)) {\n return null;\n }\n const { unstable_keepPresented, onPress, ...rest } = props;\n return (\n <NativeLinkPreviewAction\n {...rest}\n onSelected={onPress}\n keepPresented={unstable_keepPresented}\n />\n );\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 /**\n * If `true`, the menu will be displayed as a palette.\n * This means that the menu will be displayed as one row\n *\n * @see [Apple documentation](https://developer.apple.com/documentation/uikit/uimenu/options-swift.struct/displayaspalette) for more information.\n */\n displayAsPalette?: boolean;\n /**\n * If `true`, the menu will be displayed inline.\n * This means that the menu will not be collapsed\n *\n * @see [Apple documentation](https://developer.apple.com/documentation/uikit/uimenu/options-swift.struct/displayinline) for more information.\n */\n displayInline?: boolean;\n /**\n * If `true`, the menu item will be displayed as destructive.\n *\n * @see [Apple documentation](https://developer.apple.com/documentation/uikit/uimenu/options-swift.struct/destructive) for more information.\n */\n destructive?: boolean;\n children: ReactElement<LinkMenuActionProps> | ReactElement<LinkMenuActionProps>[];\n}\n\n/**\n * Groups context menu actions for a link.\n *\n * If multiple `Link.Menu` components are used within a single `Link`, only the first will be rendered.\n * Only `Link.MenuAction` and `LinkMenuAction` components are allowed as children.\n *\n * @example\n * ```tsx\n * <Link.Menu>\n * <Link.MenuAction title=\"Action 1\" onPress={() => {}} />\n * <Link.MenuAction title=\"Action 2\" onPress={() => {}} />\n * </Link.Menu>\n * ```\n *\n * > **Note**: You can use the alias `Link.Menu` for this component.\n *\n * @platform ios\n */\nexport const LinkMenu: React.FC<LinkMenuProps> = (props) => {\n if (useIsPreview() || process.env.EXPO_OS !== 'ios' || !use(InternalLinkPreviewContext)) {\n return null;\n }\n const children = React.Children.toArray(props.children).filter(\n (child) => isValidElement(child) && (child.type === LinkMenuAction || child.type === LinkMenu)\n );\n return (\n <NativeLinkPreviewAction\n {...props}\n title={props.title ?? ''}\n onSelected={() => {}}\n children={children}\n />\n );\n};\n\nexport interface 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\n/**\n * A component used to render and customize the link preview.\n *\n * If `Link.Preview` is used without any props, it will render a preview of the `href` passed to the `Link`.\n *\n * If multiple `Link.Preview` components are used within a single `Link`, only the first one will be rendered.\n *\n * To customize the preview, you can pass custom content as children.\n *\n * @example\n * ```tsx\n * <Link href=\"/about\">\n * <Link.Preview>\n * <Text>Custom Preview Content</Text>\n * </Link.Trigger>\n * </Link>\n * ```\n *\n * @example\n * ```tsx\n * <Link href=\"/about\">\n * <Link.Preview />\n * </Link>\n * ```\n *\n * > **Note**: You can use the alias `Link.Preview` for this component.\n *\n * @platform ios\n */\nexport function LinkPreview(props: LinkPreviewProps) {\n const { width, height, children } = props;\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 interface LinkTriggerProps extends PropsWithChildren {\n /**\n * Sets the corner radius of the highlight — the element that appears during a long press,\n * before the preview shows, and beside the context menu if no preview is displayed.\n *\n * @platform ios\n */\n highlightBorderRadius?: number;\n}\n\n/**\n * Serves as the trigger for a link.\n * The content inside this component will be rendered as part of the base link.\n *\n * If multiple `Link.Trigger` components are used within a single `Link`, only the first will be rendered.\n *\n * @example\n * ```tsx\n * <Link href=\"/about\">\n * <Link.Trigger>\n * Trigger\n * </Link.Trigger>\n * </Link>\n * ```\n *\n * > **Note**: You can use the alias `Link.Trigger` for this component.\n *\n * @platform ios\n */\nexport function LinkTrigger(props: LinkTriggerProps) {\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"]}
|
|
@@ -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":"AAiBA,OAAO,EAAE,IAAI,EAAuB,MAAM,aAAa,CAAC;AAKxD,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,+BAyCnD"}
|
|
@@ -4,15 +4,54 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.HrefPreview = HrefPreview;
|
|
5
5
|
const native_1 = require("@react-navigation/native");
|
|
6
6
|
const react_1 = require("react");
|
|
7
|
+
const react_native_1 = require("react-native");
|
|
7
8
|
const PreviewRouteContext_1 = require("./PreviewRouteContext");
|
|
8
9
|
const constants_1 = require("../../constants");
|
|
9
10
|
const router_store_1 = require("../../global-state/router-store");
|
|
11
|
+
const utils_1 = require("../../global-state/utils");
|
|
12
|
+
const hooks_1 = require("../../hooks");
|
|
10
13
|
const useNavigation_1 = require("../../useNavigation");
|
|
11
14
|
const useScreens_1 = require("../../useScreens");
|
|
12
15
|
const linking_1 = require("../linking");
|
|
13
16
|
function HrefPreview({ href }) {
|
|
17
|
+
const hrefState = (0, react_1.useMemo)(() => getHrefState(href), [href]);
|
|
18
|
+
const index = hrefState?.index ?? 0;
|
|
19
|
+
let isProtected = false;
|
|
20
|
+
if (hrefState?.routes[index]?.name === constants_1.INTERNAL_SLOT_NAME) {
|
|
21
|
+
let routerState = hrefState;
|
|
22
|
+
let rnState = router_store_1.store.state;
|
|
23
|
+
while (routerState && rnState) {
|
|
24
|
+
const routerRoute = routerState.routes[0];
|
|
25
|
+
// When the route we want to show is not present in react-navigation state
|
|
26
|
+
// Then most likely it is a protected route
|
|
27
|
+
if (rnState.stale === false && !rnState.routeNames?.includes(routerRoute.name)) {
|
|
28
|
+
isProtected = true;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
const rnIndex = rnState.routes.findIndex((route) => route.name === routerRoute.name);
|
|
32
|
+
if (rnIndex === -1) {
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
routerState = routerRoute.state;
|
|
36
|
+
rnState = rnState.routes[rnIndex]?.state;
|
|
37
|
+
}
|
|
38
|
+
if (!isProtected) {
|
|
39
|
+
return <PreviewForRootHrefState hrefState={hrefState} href={href}/>;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const pathname = href.toString();
|
|
43
|
+
const segments = pathname.split('/').filter(Boolean);
|
|
44
|
+
return (<PreviewRouteContext_1.PreviewRouteContext.Provider value={{
|
|
45
|
+
params: {},
|
|
46
|
+
pathname,
|
|
47
|
+
segments,
|
|
48
|
+
}}>
|
|
49
|
+
<PreviewForInternalRoutes />
|
|
50
|
+
</PreviewRouteContext_1.PreviewRouteContext.Provider>);
|
|
51
|
+
}
|
|
52
|
+
function PreviewForRootHrefState({ hrefState, href }) {
|
|
14
53
|
const navigation = (0, useNavigation_1.useNavigation)();
|
|
15
|
-
const { routeNode, params, state } = getParamsAndNodeFromHref(
|
|
54
|
+
const { routeNode, params, state } = getParamsAndNodeFromHref(hrefState);
|
|
16
55
|
const path = state ? (0, linking_1.getPathFromState)(state) : undefined;
|
|
17
56
|
const value = (0, react_1.useMemo)(() => ({
|
|
18
57
|
params,
|
|
@@ -20,7 +59,7 @@ function HrefPreview({ href }) {
|
|
|
20
59
|
segments: path?.split('/').filter(Boolean) || [],
|
|
21
60
|
}), [params, href]);
|
|
22
61
|
// This can happen in a theoretical case where the state is not yet initialized or is incorrectly initialized.
|
|
23
|
-
//
|
|
62
|
+
// This check ensures TypeScript type safety as well.
|
|
24
63
|
if (!routeNode) {
|
|
25
64
|
return null;
|
|
26
65
|
}
|
|
@@ -32,10 +71,26 @@ function HrefPreview({ href }) {
|
|
|
32
71
|
</native_1.NavigationContext>
|
|
33
72
|
</PreviewRouteContext_1.PreviewRouteContext>);
|
|
34
73
|
}
|
|
35
|
-
function
|
|
74
|
+
function PreviewForInternalRoutes() {
|
|
75
|
+
const pathname = (0, hooks_1.usePathname)();
|
|
76
|
+
return (<react_native_1.View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', gap: 8 }}>
|
|
77
|
+
<react_native_1.Text style={{ fontWeight: '600', fontSize: 24 }}>Invalid preview</react_native_1.Text>
|
|
78
|
+
<react_native_1.Text style={{ fontWeight: '200', fontSize: 14 }}>{pathname}</react_native_1.Text>
|
|
79
|
+
</react_native_1.View>);
|
|
80
|
+
}
|
|
81
|
+
function getHrefState(href) {
|
|
36
82
|
const hrefState = router_store_1.store.getStateForHref(href);
|
|
37
|
-
|
|
38
|
-
|
|
83
|
+
return hrefState;
|
|
84
|
+
}
|
|
85
|
+
function getParamsAndNodeFromHref(hrefState) {
|
|
86
|
+
const index = hrefState?.index ?? 0;
|
|
87
|
+
if (hrefState?.routes[index] && hrefState.routes[index].name !== constants_1.INTERNAL_SLOT_NAME) {
|
|
88
|
+
const name = hrefState.routes[index].name;
|
|
89
|
+
if (name === constants_1.SITEMAP_ROUTE_NAME || name === constants_1.NOT_FOUND_ROUTE_NAME) {
|
|
90
|
+
console.log(router_store_1.store.routeNode);
|
|
91
|
+
console.log(hrefState);
|
|
92
|
+
}
|
|
93
|
+
const error = `Expo Router Error: Expected navigation state to begin with one of [${(0, utils_1.getRootStackRouteNames)().join(', ')}] routes`;
|
|
39
94
|
if (process.env.NODE_ENV !== 'production') {
|
|
40
95
|
throw new Error(error);
|
|
41
96
|
}
|
|
@@ -43,8 +98,7 @@ function getParamsAndNodeFromHref(href) {
|
|
|
43
98
|
console.warn(error);
|
|
44
99
|
}
|
|
45
100
|
}
|
|
46
|
-
|
|
47
|
-
const initialState = hrefState?.routes[0]?.state;
|
|
101
|
+
const initialState = hrefState?.routes[index]?.state;
|
|
48
102
|
let state = initialState;
|
|
49
103
|
let routeNode = router_store_1.store.routeNode;
|
|
50
104
|
const params = {};
|
|
@@ -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,+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,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qB,CAAC,WAAW,CAAC;IAC7C,UAAU,EAAE,qBAAqB,CAAC,YAAY,CAAC;IAC/C,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,CAAiD;IAC7E,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;IACxB,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI;IACrB,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK;IACtB,QAAQ,EAAE,qBAAqB,CAAC,UAAU,CAAC;IAC3C,QAAQ,EAAE,qBAAqB,CAAC,UAAU,CAAC;IAC3C,MAAM,EAAE,qBAAqB,CAAC,QAAQ,CAAC;IACvC,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
|
+
{"version":3,"file":"HrefPreview.js","sourceRoot":"","sources":["../../../src/link/preview/HrefPreview.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAsBb,kCAyCC;AA7DD,qDAIkC;AAClC,iCAAgC;AAChC,+CAA0C;AAE1C,+DAA4D;AAE5D,+CAA+F;AAE/F,kEAAwD;AACxD,oDAAkE;AAClE,uCAA0C;AAE1C,uDAAoD;AACpD,iDAA8D;AAC9D,wCAA8C;AAE9C,SAAgB,WAAW,CAAC,EAAE,IAAI,EAAkB;IAClD,MAAM,SAAS,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5D,MAAM,KAAK,GAAG,SAAS,EAAE,KAAK,IAAI,CAAC,CAAC;IAEpC,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,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nimport {\n NavigationContext,\n type NavigationProp,\n type ParamListBase,\n} from '@react-navigation/native';\nimport { useMemo } from 'react';\nimport { Text, View } from 'react-native';\n\nimport { PreviewRouteContext } from './PreviewRouteContext';\nimport { RouteNode } from '../../Route';\nimport { INTERNAL_SLOT_NAME, NOT_FOUND_ROUTE_NAME, SITEMAP_ROUTE_NAME } from '../../constants';\nimport { type ResultState } from '../../exports';\nimport { store } from '../../global-state/router-store';\nimport { getRootStackRouteNames } from '../../global-state/utils';\nimport { usePathname } from '../../hooks';\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 hrefState = useMemo(() => getHrefState(href), [href]);\n const index = hrefState?.index ?? 0;\n\n let isProtected = false;\n if (hrefState?.routes[index]?.name === INTERNAL_SLOT_NAME) {\n let routerState: typeof hrefState | undefined = hrefState;\n let rnState = store.state;\n while (routerState && rnState) {\n const routerRoute: ResultState['routes'][number] = routerState.routes[0];\n // When the route we want to show is not present in react-navigation state\n // Then most likely it is a protected route\n if (rnState.stale === false && !rnState.routeNames?.includes(routerRoute.name)) {\n isProtected = true;\n break;\n }\n const rnIndex = rnState.routes.findIndex((route) => route.name === routerRoute.name);\n if (rnIndex === -1) {\n break;\n }\n routerState = routerRoute.state;\n rnState = rnState.routes[rnIndex]?.state;\n }\n if (!isProtected) {\n return <PreviewForRootHrefState hrefState={hrefState} href={href} />;\n }\n }\n\n const pathname = href.toString();\n const segments = pathname.split('/').filter(Boolean);\n\n return (\n <PreviewRouteContext.Provider\n value={{\n params: {},\n pathname,\n segments,\n }}>\n <PreviewForInternalRoutes />\n </PreviewRouteContext.Provider>\n );\n}\n\nfunction PreviewForRootHrefState({ hrefState, href }: { hrefState: ResultState; href: Href }) {\n const navigation = useNavigation();\n const { routeNode, params, state } = getParamsAndNodeFromHref(hrefState);\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 // This check ensures TypeScript type safety as well.\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 PreviewForInternalRoutes() {\n const pathname = usePathname();\n return (\n <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', gap: 8 }}>\n <Text style={{ fontWeight: '600', fontSize: 24 }}>Invalid preview</Text>\n <Text style={{ fontWeight: '200', fontSize: 14 }}>{pathname}</Text>\n </View>\n );\n}\n\nfunction getHrefState(href: Href) {\n const hrefState = store.getStateForHref(href as any);\n return hrefState;\n}\n\nfunction getParamsAndNodeFromHref(hrefState: ResultState) {\n const index = hrefState?.index ?? 0;\n if (hrefState?.routes[index] && hrefState.routes[index].name !== INTERNAL_SLOT_NAME) {\n const name = hrefState.routes[index].name;\n if (name === SITEMAP_ROUTE_NAME || name === NOT_FOUND_ROUTE_NAME) {\n console.log(store.routeNode);\n console.log(hrefState);\n }\n const error = `Expo Router Error: Expected navigation state to begin with one of [${getRootStackRouteNames().join(', ')}] routes`;\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(error);\n } else {\n console.warn(error);\n }\n }\n const initialState = hrefState?.routes[index]?.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,8 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
2
|
export declare function LinkPreviewContextProvider({ children }: PropsWithChildren): import("react").JSX.Element;
|
|
3
3
|
export declare const useLinkPreviewContext: () => {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
isStackAnimationDisabled: boolean;
|
|
5
|
+
openPreviewKey: string | undefined;
|
|
6
|
+
setOpenPreviewKey: (openPreviewKey: string | undefined) => void;
|
|
6
7
|
};
|
|
7
8
|
//# sourceMappingURL=LinkPreviewContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LinkPreviewContext.d.ts","sourceRoot":"","sources":["../../../src/link/preview/LinkPreviewContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,iBAAiB,EAAiB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"LinkPreviewContext.d.ts","sourceRoot":"","sources":["../../../src/link/preview/LinkPreviewContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,iBAAiB,EAAiB,MAAM,OAAO,CAAC;AAWxE,wBAAgB,0BAA0B,CAAC,EAAE,QAAQ,EAAE,EAAE,iBAAiB,+BASzE;AAED,eAAO,MAAM,qBAAqB;8BAlBF,OAAO;oBACjB,MAAM,GAAG,SAAS;uBACf,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI;CAwBpE,CAAC"}
|
|
@@ -5,8 +5,9 @@ exports.LinkPreviewContextProvider = LinkPreviewContextProvider;
|
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const LinkPreviewContext = (0, react_1.createContext)(undefined);
|
|
7
7
|
function LinkPreviewContextProvider({ children }) {
|
|
8
|
-
const [
|
|
9
|
-
|
|
8
|
+
const [openPreviewKey, setOpenPreviewKey] = (0, react_1.useState)(undefined);
|
|
9
|
+
const isStackAnimationDisabled = openPreviewKey !== undefined;
|
|
10
|
+
return (<LinkPreviewContext.Provider value={{ isStackAnimationDisabled, openPreviewKey, setOpenPreviewKey }}>
|
|
10
11
|
{children}
|
|
11
12
|
</LinkPreviewContext.Provider>);
|
|
12
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LinkPreviewContext.js","sourceRoot":"","sources":["../../../src/link/preview/LinkPreviewContext.tsx"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"LinkPreviewContext.js","sourceRoot":"","sources":["../../../src/link/preview/LinkPreviewContext.tsx"],"names":[],"mappings":";;;AAWA,gEASC;AApBD,iCAAwE;AAExE,MAAM,kBAAkB,GAAG,IAAA,qBAAa,EAOtC,SAAS,CAAC,CAAC;AAEb,SAAgB,0BAA0B,CAAC,EAAE,QAAQ,EAAqB;IACxE,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,IAAA,gBAAQ,EAAqB,SAAS,CAAC,CAAC;IACpF,MAAM,wBAAwB,GAAG,cAAc,KAAK,SAAS,CAAC;IAC9D,OAAO,CACL,CAAC,kBAAkB,CAAC,QAAQ,CAC1B,KAAK,CAAC,CAAC,EAAE,wBAAwB,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC,CACvE;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,kBAAkB,CAAC,QAAQ,CAAC,CAC/B,CAAC;AACJ,CAAC;AAEM,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACxC,MAAM,OAAO,GAAG,IAAA,WAAG,EAAC,kBAAkB,CAAC,CAAC;IACxC,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,8GAA8G,CAC/G,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AARW,QAAA,qBAAqB,yBAQhC","sourcesContent":["import { createContext, PropsWithChildren, use, useState } from 'react';\n\nconst LinkPreviewContext = createContext<\n | {\n isStackAnimationDisabled: boolean;\n openPreviewKey: string | undefined;\n setOpenPreviewKey: (openPreviewKey: string | undefined) => void;\n }\n | undefined\n>(undefined);\n\nexport function LinkPreviewContextProvider({ children }: PropsWithChildren) {\n const [openPreviewKey, setOpenPreviewKey] = useState<string | undefined>(undefined);\n const isStackAnimationDisabled = openPreviewKey !== undefined;\n return (\n <LinkPreviewContext.Provider\n value={{ isStackAnimationDisabled, openPreviewKey, setOpenPreviewKey }}>\n {children}\n </LinkPreviewContext.Provider>\n );\n}\n\nexport const useLinkPreviewContext = () => {\n const context = use(LinkPreviewContext);\n if (context == null) {\n throw new Error(\n 'useLinkPreviewContext must be used within a LinkPreviewContextProvider. This is likely a bug in Expo Router.'\n );\n }\n return context;\n};\n"]}
|
|
@@ -2,19 +2,27 @@ import { type ViewProps } from 'react-native';
|
|
|
2
2
|
export interface NativeLinkPreviewActionProps {
|
|
3
3
|
title: string;
|
|
4
4
|
icon?: string;
|
|
5
|
-
id: string;
|
|
6
5
|
children?: React.ReactNode;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
destructive?: boolean;
|
|
8
|
+
displayAsPalette?: boolean;
|
|
9
|
+
displayInline?: boolean;
|
|
10
|
+
isOn?: boolean;
|
|
11
|
+
keepPresented?: boolean;
|
|
12
|
+
onSelected: () => void;
|
|
7
13
|
}
|
|
8
14
|
export declare function NativeLinkPreviewAction(props: NativeLinkPreviewActionProps): import("react").JSX.Element | null;
|
|
9
15
|
export type NativeLinkPreviewTriggerProps = ViewProps;
|
|
10
16
|
export declare function NativeLinkPreviewTrigger(props: NativeLinkPreviewTriggerProps): import("react").JSX.Element | null;
|
|
17
|
+
export interface TabPath {
|
|
18
|
+
oldTabKey: string;
|
|
19
|
+
newTabKey: string;
|
|
20
|
+
}
|
|
11
21
|
export interface NativeLinkPreviewProps extends ViewProps {
|
|
12
22
|
nextScreenId: string | undefined;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
}) => void;
|
|
23
|
+
tabPath: {
|
|
24
|
+
path: TabPath[];
|
|
25
|
+
} | undefined;
|
|
18
26
|
onWillPreviewOpen?: () => void;
|
|
19
27
|
onDidPreviewOpen?: () => void;
|
|
20
28
|
onPreviewWillClose?: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/link/preview/native.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAK1D,MAAM,WAAW,4BAA4B;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/link/preview/native.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAK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BAAoB,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;;AA+Bb,0DAKC;AASD,4DAKC;AA2BD,8CAKC;AAYD,4DAWC;AAvGD,+BAAyC;AACzC,+CAA0D;AAE1D,MAAM,uBAAuB,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,KAAK,IAAI,MAAM,CAAC,aAAa,KAAK,IAAI,CAAC;AAsB/F,MAAM,2BAA2B,GAC/B,uBAAuB;IACrB,CAAC,CAAC,IAAA,wBAAiB,EAAC,6BAA6B,EAAE,6BAA6B,CAAC;IACjF,CAAC,CAAC,IAAI,CAAC;AACX,SAAgB,uBAAuB,CAAC,KAAmC;IACzE,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CAAC,2BAA2B,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACpD,CAAC;AAKD,MAAM,4BAA4B,GAChC,uBAAuB;IACrB,CAAC,CAAC,IAAA,wBAAiB,EAAC,6BAA6B,EAAE,0BAA0B,CAAC;IAC9E,CAAC,CAAC,IAAI,CAAC;AACX,SAAgB,wBAAwB,CAAC,KAAoC;IAC3E,IAAI,CAAC,4BAA4B,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CAAC,4BAA4B,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACrD,CAAC;AAuBD,MAAM,qBAAqB,GACzB,uBAAuB;IACrB,CAAC,CAAC,IAAA,wBAAiB,EAAC,6BAA6B,EAAE,uBAAuB,CAAC;IAC3E,CAAC,CAAC,IAAI,CAAC;AACX,SAAgB,iBAAiB,CAAC,KAA6B;IAC7D,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CAAC,qBAAqB,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AAC9C,CAAC;AAOD,MAAM,4BAA4B,GAChC,uBAAuB;IACrB,CAAC,CAAC,IAAA,wBAAiB,EAAC,6BAA6B,EAAE,8BAA8B,CAAC;IAClF,CAAC,CAAC,IAAI,CAAC;AAEX,SAAgB,wBAAwB,CAAC,KAAoC;IAC3E,IAAI,CAAC,4BAA4B,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,KAAK,GAAG,yBAAU,CAAC,OAAO,CAAC;QAC/B,KAAK,CAAC,KAAK;QACX;YACE,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 { StyleSheet, type ViewProps } from 'react-native';\n\nconst areNativeViewsAvailable = process.env.EXPO_OS === 'ios' && global.RN$Bridgeless === true;\n\n// #region Action View\nexport interface NativeLinkPreviewActionProps {\n title: string;\n icon?: string;\n children?: React.ReactNode;\n disabled?: boolean;\n destructive?: boolean;\n // This may lead to race conditions, when two menu actions are on at the same time.\n // The logic should be enforced in the JS code, rather than in the native code.\n // singleSelection?: boolean;\n displayAsPalette?: boolean;\n displayInline?: boolean;\n isOn?: boolean;\n // There are issues with menu state updates when keep presented is set to true.\n // When updating the context menu state, it will either not update or it will recreate the menu. The latter is a problem,\n // because it will close all opened submenus and reset the scroll position.\n // TODO: (@ubax) find a way to fix this.\n keepPresented?: boolean;\n onSelected: () => void;\n}\nconst LinkPreviewNativeActionView: React.ComponentType<NativeLinkPreviewActionProps> | null =\n areNativeViewsAvailable\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 areNativeViewsAvailable\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 TabPath {\n oldTabKey: string;\n newTabKey: string;\n}\nexport interface NativeLinkPreviewProps extends ViewProps {\n nextScreenId: string | undefined;\n tabPath:\n | {\n path: TabPath[];\n }\n | undefined;\n onWillPreviewOpen?: () => void;\n onDidPreviewOpen?: () => void;\n onPreviewWillClose?: () => void;\n onPreviewDidClose?: () => void;\n onPreviewTapped?: () => void;\n onPreviewTappedAnimationCompleted?: () => void;\n children: React.ReactNode;\n}\nconst NativeLinkPreviewView: React.ComponentType<NativeLinkPreviewProps> | null =\n areNativeViewsAvailable\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 areNativeViewsAvailable\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"]}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import { TabPath } from './native';
|
|
1
2
|
import { Href } from '../../types';
|
|
2
|
-
export declare function useNextScreenId(): [
|
|
3
|
+
export declare function useNextScreenId(): [
|
|
4
|
+
{
|
|
5
|
+
nextScreenId: string | undefined;
|
|
6
|
+
tabPath: TabPath[];
|
|
7
|
+
},
|
|
8
|
+
(href: Href) => void
|
|
9
|
+
];
|
|
3
10
|
//# sourceMappingURL=useNextScreenId.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNextScreenId.d.ts","sourceRoot":"","sources":["../../../src/link/preview/useNextScreenId.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useNextScreenId.d.ts","sourceRoot":"","sources":["../../../src/link/preview/useNextScreenId.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAInC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,wBAAgB,eAAe,IAAI;IACjC;QAAE,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,OAAO,EAAE,OAAO,EAAE,CAAA;KAAE;IACxD,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI;CACrB,CAyCA"}
|
|
@@ -2,41 +2,45 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useNextScreenId = useNextScreenId;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
+
const LinkPreviewContext_1 = require("./LinkPreviewContext");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
5
7
|
const router_store_1 = require("../../global-state/router-store");
|
|
6
|
-
const
|
|
8
|
+
const hooks_1 = require("../../hooks");
|
|
7
9
|
function useNextScreenId() {
|
|
10
|
+
const router = (0, hooks_1.useRouter)();
|
|
11
|
+
const { setOpenPreviewKey } = (0, LinkPreviewContext_1.useLinkPreviewContext)();
|
|
8
12
|
const [internalNextScreenId, internalSetNextScreenId] = (0, react_1.useState)();
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
const preloadedRoute = stackState.preloadedRoutes.find((route) => route.name === currentHrefRoute.name &&
|
|
32
|
-
(!innerRoute ||
|
|
33
|
-
(route.params && 'screen' in route.params && route.params.screen === innerRoute.name)));
|
|
34
|
-
return preloadedRoute;
|
|
13
|
+
const currentHref = (0, react_1.useRef)(undefined);
|
|
14
|
+
const [tabPath, setTabPath] = (0, react_1.useState)([]);
|
|
15
|
+
(0, react_1.useEffect)(() => {
|
|
16
|
+
// When screen is prefetched, then the root state is updated with the preloaded route.
|
|
17
|
+
return router_store_1.store.navigationRef.addListener('state', ({ data: { state } }) => {
|
|
18
|
+
// If we have the current href, it means that we prefetched the route
|
|
19
|
+
if (currentHref.current && state) {
|
|
20
|
+
const preloadedRoute = (0, utils_1.getPreloadedRouteFromRootStateByHref)(currentHref.current, state);
|
|
21
|
+
const routeKey = preloadedRoute?.key;
|
|
22
|
+
const tabPathFromRootState = (0, utils_1.getTabPathFromRootStateByHref)(currentHref.current, state);
|
|
23
|
+
// Without this timeout react-native does not have enough time to mount the new screen
|
|
24
|
+
// and thus it will not be found on the native side
|
|
25
|
+
if (routeKey || tabPathFromRootState.length) {
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
internalSetNextScreenId(routeKey);
|
|
28
|
+
setOpenPreviewKey(routeKey);
|
|
29
|
+
setTabPath(tabPathFromRootState);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// We got the preloaded state, so we can reset the currentHref
|
|
33
|
+
// to prevent unnecessary processing
|
|
34
|
+
currentHref.current = undefined;
|
|
35
35
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
});
|
|
37
|
+
}, []);
|
|
38
|
+
const prefetch = (0, react_1.useCallback)((href) => {
|
|
39
|
+
// Resetting the nextScreenId to undefined
|
|
40
|
+
internalSetNextScreenId(undefined);
|
|
41
|
+
router.prefetch(href);
|
|
42
|
+
currentHref.current = href;
|
|
43
|
+
}, [router.prefetch]);
|
|
44
|
+
return [{ nextScreenId: internalNextScreenId, tabPath }, prefetch];
|
|
41
45
|
}
|
|
42
46
|
//# sourceMappingURL=useNextScreenId.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNextScreenId.js","sourceRoot":"","sources":["../../../src/link/preview/useNextScreenId.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"useNextScreenId.js","sourceRoot":"","sources":["../../../src/link/preview/useNextScreenId.ts"],"names":[],"mappings":";;AASA,0CA4CC;AArDD,iCAAiE;AAEjE,6DAA6D;AAE7D,mCAA8F;AAC9F,kEAAwD;AACxD,uCAAwC;AAGxC,SAAgB,eAAe;IAI7B,MAAM,MAAM,GAAG,IAAA,iBAAS,GAAE,CAAC;IAC3B,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAA,0CAAqB,GAAE,CAAC;IACtD,MAAM,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,GAAG,IAAA,gBAAQ,GAAsB,CAAC;IACvF,MAAM,WAAW,GAAG,I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AC;IAC7B,CAAC,EACD,CAAC,MAAM,CAAC,QAAQ,CAAC,CAClB,CAAC;IACF,OAAO,CAAC,EAAE,YAAY,EAAE,oBAAoB,EAAE,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { useLinkPreviewContext } from './LinkPreviewContext';\nimport { TabPath } from './native';\nimport { getPreloadedRouteFromRootStateByHref, getTabPathFromRootStateByHref } from './utils';\nimport { store } from '../../global-state/router-store';\nimport { useRouter } from '../../hooks';\nimport { Href } from '../../types';\n\nexport function useNextScreenId(): [\n { nextScreenId: string | undefined; tabPath: TabPath[] },\n (href: Href) => void,\n] {\n const router = useRouter();\n const { setOpenPreviewKey } = useLinkPreviewContext();\n const [internalNextScreenId, internalSetNextScreenId] = useState<string | undefined>();\n const currentHref = useRef<Href | undefined>(undefined);\n const [tabPath, setTabPath] = useState<TabPath[]>([]);\n\n useEffect(() => {\n // When screen is prefetched, then the root state is updated with the preloaded route.\n return store.navigationRef.addListener('state', ({ data: { state } }) => {\n // If we have the current href, it means that we prefetched the route\n if (currentHref.current && state) {\n const preloadedRoute = getPreloadedRouteFromRootStateByHref(currentHref.current, state);\n const routeKey = preloadedRoute?.key;\n const tabPathFromRootState = getTabPathFromRootStateByHref(currentHref.current, state);\n // Without this timeout react-native does not have enough time to mount the new screen\n // and thus it will not be found on the native side\n if (routeKey || tabPathFromRootState.length) {\n setTimeout(() => {\n internalSetNextScreenId(routeKey);\n setOpenPreviewKey(routeKey);\n setTabPath(tabPathFromRootState);\n });\n }\n // We got the preloaded state, so we can reset the currentHref\n // to prevent unnecessary processing\n currentHref.current = undefined;\n }\n });\n }, []);\n\n const prefetch = useCallback(\n (href: Href): void => {\n // Resetting the nextScreenId to undefined\n internalSetNextScreenId(undefined);\n router.prefetch(href);\n currentHref.current = href;\n },\n [router.prefetch]\n );\n return [{ nextScreenId: internalNextScreenId, tabPath }, prefetch];\n}\n"]}
|