one 1.1.390 → 1.1.392
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/dist/cjs/Root.cjs +6 -17
- package/dist/cjs/Root.js +9 -13
- package/dist/cjs/Root.js.map +1 -1
- package/dist/cjs/Root.native.js +4 -12
- package/dist/cjs/Root.native.js.map +1 -1
- package/dist/cjs/cli/build.cjs +2 -3
- package/dist/cjs/cli/build.js +2 -3
- package/dist/cjs/cli/build.js.map +1 -1
- package/dist/cjs/cli/build.native.js +2 -3
- package/dist/cjs/cli/build.native.js.map +2 -2
- package/dist/cjs/constants.cjs +9 -1
- package/dist/cjs/constants.js +7 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/constants.native.js +9 -1
- package/dist/cjs/constants.native.js.map +2 -2
- package/dist/cjs/fork/NavigationContainer.cjs +49 -31
- package/dist/cjs/fork/NavigationContainer.js +40 -21
- package/dist/cjs/fork/NavigationContainer.js.map +2 -2
- package/dist/cjs/fork/NavigationContainer.native.js +51 -29
- package/dist/cjs/fork/NavigationContainer.native.js.map +2 -2
- package/dist/cjs/fork/createMemoryHistory.cjs +4 -3
- package/dist/cjs/fork/createMemoryHistory.js +3 -2
- package/dist/cjs/fork/createMemoryHistory.js.map +1 -1
- package/dist/cjs/fork/createMemoryHistory.native.js +8 -4
- package/dist/cjs/fork/createMemoryHistory.native.js.map +2 -2
- package/dist/cjs/fork/extractPathFromURL.cjs +48 -28
- package/dist/cjs/fork/extractPathFromURL.js +44 -21
- package/dist/cjs/fork/extractPathFromURL.js.map +2 -2
- package/dist/cjs/fork/extractPathFromURL.native.js +58 -26
- package/dist/cjs/fork/extractPathFromURL.native.js.map +2 -2
- package/dist/cjs/fork/findFocusedRoute.js.map +1 -1
- package/dist/cjs/fork/findFocusedRoute.native.js.map +1 -1
- package/dist/cjs/fork/getPathFromState-mods.cjs +65 -0
- package/dist/cjs/fork/getPathFromState-mods.js +56 -0
- package/dist/cjs/fork/getPathFromState-mods.js.map +6 -0
- package/dist/cjs/fork/getPathFromState-mods.native.js +70 -0
- package/dist/cjs/fork/getPathFromState-mods.native.js.map +6 -0
- package/dist/cjs/fork/getPathFromState.cjs +75 -224
- package/dist/cjs/fork/getPathFromState.js +68 -223
- package/dist/cjs/fork/getPathFromState.js.map +2 -2
- package/dist/cjs/fork/getPathFromState.native.js +79 -261
- package/dist/cjs/fork/getPathFromState.native.js.map +2 -2
- package/dist/cjs/fork/getStateFromPath-mods.cjs +187 -0
- package/dist/cjs/fork/getStateFromPath-mods.js +199 -0
- package/dist/cjs/fork/getStateFromPath-mods.js.map +6 -0
- package/dist/cjs/fork/getStateFromPath-mods.native.js +284 -0
- package/dist/cjs/fork/getStateFromPath-mods.native.js.map +6 -0
- package/dist/cjs/fork/getStateFromPath.cjs +181 -263
- package/dist/cjs/fork/getStateFromPath.js +148 -264
- package/dist/cjs/fork/getStateFromPath.js.map +2 -2
- package/dist/cjs/fork/getStateFromPath.native.js +164 -304
- package/dist/cjs/fork/getStateFromPath.native.js.map +2 -2
- package/dist/cjs/fork/useBackButton.js.map +1 -1
- package/dist/cjs/fork/useBackButton.native.js.map +1 -1
- package/dist/cjs/fork/useDocumentTitle.js +4 -1
- package/dist/cjs/fork/useDocumentTitle.js.map +1 -1
- package/dist/cjs/fork/useDocumentTitle.native.js +1 -1
- package/dist/cjs/fork/useDocumentTitle.native.js.map +2 -2
- package/dist/cjs/fork/useLinking.cjs +21 -24
- package/dist/cjs/fork/useLinking.js +21 -25
- package/dist/cjs/fork/useLinking.js.map +2 -2
- package/dist/cjs/fork/useLinking.native.js +68 -66
- package/dist/cjs/fork/useLinking.native.js.map +2 -2
- package/dist/cjs/fork/useThenable.js.map +1 -1
- package/dist/cjs/fork/useThenable.native.js.map +1 -1
- package/dist/cjs/fork/validatePathConfig.cjs +32 -11
- package/dist/cjs/fork/validatePathConfig.js +41 -11
- package/dist/cjs/fork/validatePathConfig.js.map +1 -1
- package/dist/cjs/fork/validatePathConfig.native.js +47 -18
- package/dist/cjs/fork/validatePathConfig.native.js.map +2 -2
- package/dist/cjs/layouts/withLayoutContext.cjs +1 -1
- package/dist/cjs/layouts/withLayoutContext.js +1 -1
- package/dist/cjs/layouts/withLayoutContext.js.map +1 -1
- package/dist/cjs/layouts/withLayoutContext.native.js +1 -1
- package/dist/cjs/layouts/withLayoutContext.native.js.map +1 -1
- package/dist/cjs/link/linking.cjs +4 -4
- package/dist/cjs/link/linking.js +3 -3
- package/dist/cjs/link/linking.js.map +2 -2
- package/dist/cjs/link/linking.native.js +3 -3
- package/dist/cjs/link/linking.native.js.map +1 -1
- package/dist/cjs/link/useLinkTo.cjs +2 -2
- package/dist/cjs/link/useLinkTo.js +2 -2
- package/dist/cjs/link/useLinkTo.js.map +1 -1
- package/dist/cjs/link/useLinkTo.native.js +2 -2
- package/dist/cjs/link/useLinkTo.native.js.map +1 -1
- package/dist/cjs/router/getNormalizedStatePath.cjs +2 -2
- package/dist/cjs/router/getNormalizedStatePath.js +2 -2
- package/dist/cjs/router/getNormalizedStatePath.js.map +1 -1
- package/dist/cjs/router/getNormalizedStatePath.native.js +2 -2
- package/dist/cjs/router/getNormalizedStatePath.native.js.map +1 -1
- package/dist/cjs/router/router.cjs +19 -3
- package/dist/cjs/router/router.js +25 -3
- package/dist/cjs/router/router.js.map +1 -1
- package/dist/cjs/router/router.native.js +39 -3
- package/dist/cjs/router/router.native.js.map +2 -2
- package/dist/cjs/utils/serverContext.cjs +7 -7
- package/dist/cjs/utils/serverContext.js +7 -7
- package/dist/cjs/utils/serverContext.js.map +1 -1
- package/dist/cjs/utils/serverContext.native.js +5 -5
- package/dist/cjs/utils/serverContext.native.js.map +2 -2
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.cjs +6 -6
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js +3 -4
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js.map +2 -2
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +3 -4
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +2 -2
- package/dist/esm/Root.js +6 -2
- package/dist/esm/Root.js.map +1 -1
- package/dist/esm/Root.mjs +1 -1
- package/dist/esm/Root.mjs.map +1 -1
- package/dist/esm/Root.native.js +1 -1
- package/dist/esm/Root.native.js.map +2 -2
- package/dist/esm/cli/build.js +2 -3
- package/dist/esm/cli/build.js.map +1 -1
- package/dist/esm/cli/build.mjs +2 -3
- package/dist/esm/cli/build.mjs.map +1 -1
- package/dist/esm/cli/build.native.js +2 -3
- package/dist/esm/cli/build.native.js.map +2 -2
- package/dist/esm/constants.js +7 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/constants.mjs +8 -2
- package/dist/esm/constants.mjs.map +1 -1
- package/dist/esm/constants.native.js +7 -1
- package/dist/esm/constants.native.js.map +2 -2
- package/dist/esm/fork/NavigationContainer.js +43 -20
- package/dist/esm/fork/NavigationContainer.js.map +1 -1
- package/dist/esm/fork/NavigationContainer.mjs +42 -24
- package/dist/esm/fork/NavigationContainer.mjs.map +1 -1
- package/dist/esm/fork/NavigationContainer.native.js +44 -24
- package/dist/esm/fork/NavigationContainer.native.js.map +2 -2
- package/dist/esm/fork/createMemoryHistory.js +3 -2
- package/dist/esm/fork/createMemoryHistory.js.map +1 -1
- package/dist/esm/fork/createMemoryHistory.mjs +4 -3
- package/dist/esm/fork/createMemoryHistory.mjs.map +1 -1
- package/dist/esm/fork/createMemoryHistory.native.js +4 -4
- package/dist/esm/fork/createMemoryHistory.native.js.map +2 -2
- package/dist/esm/fork/extractPathFromURL.js +42 -11
- package/dist/esm/fork/extractPathFromURL.js.map +1 -1
- package/dist/esm/fork/extractPathFromURL.mjs +39 -11
- package/dist/esm/fork/extractPathFromURL.mjs.map +1 -1
- package/dist/esm/fork/extractPathFromURL.native.js +52 -15
- package/dist/esm/fork/extractPathFromURL.native.js.map +2 -2
- package/dist/esm/fork/findFocusedRoute.js.map +1 -1
- package/dist/esm/fork/findFocusedRoute.mjs.map +1 -1
- package/dist/esm/fork/findFocusedRoute.native.js.map +1 -1
- package/dist/esm/fork/getPathFromState-mods.js +40 -0
- package/dist/esm/fork/getPathFromState-mods.js.map +6 -0
- package/dist/esm/fork/getPathFromState-mods.mjs +40 -0
- package/dist/esm/fork/getPathFromState-mods.mjs.map +1 -0
- package/dist/esm/fork/getPathFromState-mods.native.js +47 -0
- package/dist/esm/fork/getPathFromState-mods.native.js.map +6 -0
- package/dist/esm/fork/getPathFromState.js +71 -228
- package/dist/esm/fork/getPathFromState.js.map +2 -2
- package/dist/esm/fork/getPathFromState.mjs +73 -221
- package/dist/esm/fork/getPathFromState.mjs.map +1 -1
- package/dist/esm/fork/getPathFromState.native.js +79 -260
- package/dist/esm/fork/getPathFromState.native.js.map +2 -2
- package/dist/esm/fork/getStateFromPath-mods.js +176 -0
- package/dist/esm/fork/getStateFromPath-mods.js.map +6 -0
- package/dist/esm/fork/getStateFromPath-mods.mjs +143 -0
- package/dist/esm/fork/getStateFromPath-mods.mjs.map +1 -0
- package/dist/esm/fork/getStateFromPath-mods.native.js +246 -0
- package/dist/esm/fork/getStateFromPath-mods.native.js.map +6 -0
- package/dist/esm/fork/getStateFromPath.js +160 -265
- package/dist/esm/fork/getStateFromPath.js.map +2 -2
- package/dist/esm/fork/getStateFromPath.mjs +181 -260
- package/dist/esm/fork/getStateFromPath.mjs.map +1 -1
- package/dist/esm/fork/getStateFromPath.native.js +164 -302
- package/dist/esm/fork/getStateFromPath.native.js.map +2 -2
- package/dist/esm/fork/useBackButton.js.map +1 -1
- package/dist/esm/fork/useBackButton.mjs.map +1 -1
- package/dist/esm/fork/useBackButton.native.js.map +1 -1
- package/dist/esm/fork/useDocumentTitle.js +4 -1
- package/dist/esm/fork/useDocumentTitle.js.map +1 -1
- package/dist/esm/fork/useDocumentTitle.mjs.map +1 -1
- package/dist/esm/fork/useDocumentTitle.native.js +1 -1
- package/dist/esm/fork/useDocumentTitle.native.js.map +2 -2
- package/dist/esm/fork/useLinking.js +22 -26
- package/dist/esm/fork/useLinking.js.map +1 -1
- package/dist/esm/fork/useLinking.mjs +20 -23
- package/dist/esm/fork/useLinking.mjs.map +1 -1
- package/dist/esm/fork/useLinking.native.js +65 -67
- package/dist/esm/fork/useLinking.native.js.map +2 -2
- package/dist/esm/fork/useThenable.js.map +1 -1
- package/dist/esm/fork/useThenable.mjs.map +1 -1
- package/dist/esm/fork/useThenable.native.js.map +1 -1
- package/dist/esm/fork/validatePathConfig.js +41 -11
- package/dist/esm/fork/validatePathConfig.js.map +1 -1
- package/dist/esm/fork/validatePathConfig.mjs +32 -11
- package/dist/esm/fork/validatePathConfig.mjs.map +1 -1
- package/dist/esm/fork/validatePathConfig.native.js +43 -18
- package/dist/esm/fork/validatePathConfig.native.js.map +2 -2
- package/dist/esm/layouts/withLayoutContext.js +1 -1
- package/dist/esm/layouts/withLayoutContext.js.map +1 -1
- package/dist/esm/layouts/withLayoutContext.mjs +1 -1
- package/dist/esm/layouts/withLayoutContext.mjs.map +1 -1
- package/dist/esm/layouts/withLayoutContext.native.js +1 -1
- package/dist/esm/layouts/withLayoutContext.native.js.map +1 -1
- package/dist/esm/link/linking.js +2 -2
- package/dist/esm/link/linking.js.map +1 -1
- package/dist/esm/link/linking.mjs +2 -2
- package/dist/esm/link/linking.mjs.map +1 -1
- package/dist/esm/link/linking.native.js +2 -2
- package/dist/esm/link/linking.native.js.map +1 -1
- package/dist/esm/link/useLinkTo.js +1 -1
- package/dist/esm/link/useLinkTo.mjs +1 -1
- package/dist/esm/link/useLinkTo.native.js +1 -1
- package/dist/esm/router/getNormalizedStatePath.js +1 -1
- package/dist/esm/router/getNormalizedStatePath.mjs +1 -1
- package/dist/esm/router/getNormalizedStatePath.native.js +1 -1
- package/dist/esm/router/router.js +24 -2
- package/dist/esm/router/router.js.map +1 -1
- package/dist/esm/router/router.mjs +18 -2
- package/dist/esm/router/router.mjs.map +1 -1
- package/dist/esm/router/router.native.js +38 -2
- package/dist/esm/router/router.native.js.map +2 -2
- package/dist/esm/utils/serverContext.js +2 -1
- package/dist/esm/utils/serverContext.js.map +1 -1
- package/dist/esm/utils/serverContext.mjs +1 -1
- package/dist/esm/utils/serverContext.mjs.map +1 -1
- package/dist/esm/utils/serverContext.native.js +2 -1
- package/dist/esm/utils/serverContext.native.js.map +2 -2
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js +3 -3
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs +3 -3
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +3 -3
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +2 -2
- package/package.json +8 -9
- package/src/Root.tsx +6 -2
- package/src/cli/build.ts +2 -3
- package/src/constants.ts +8 -0
- package/src/fork/NavigationContainer.tsx +101 -39
- package/src/fork/createMemoryHistory.tsx +15 -13
- package/src/fork/extractPathFromURL.ts +85 -40
- package/src/fork/findFocusedRoute.tsx +9 -1
- package/src/fork/getPathFromState-mods.ts +142 -0
- package/src/fork/getPathFromState.ts +244 -501
- package/src/fork/getStateFromPath-mods.ts +400 -0
- package/src/fork/getStateFromPath.ts +447 -538
- package/src/fork/useBackButton.native.tsx +16 -2
- package/src/fork/useBackButton.tsx +11 -2
- package/src/fork/useDocumentTitle.native.tsx +9 -4
- package/src/fork/useDocumentTitle.tsx +12 -7
- package/src/fork/useLinking.native.ts +71 -63
- package/src/fork/useLinking.ts +75 -40
- package/src/fork/useThenable.tsx +7 -1
- package/src/fork/validatePathConfig.ts +64 -12
- package/src/layouts/withLayoutContext.tsx +1 -1
- package/src/link/linking.ts +2 -2
- package/src/link/useLinkTo.tsx +1 -1
- package/src/router/getNormalizedStatePath.tsx +1 -1
- package/src/router/router.ts +41 -2
- package/src/utils/serverContext.tsx +3 -1
- package/src/vite/plugins/fileSystemRouterPlugin.tsx +3 -3
- package/types/Root.d.ts.map +1 -1
- package/types/cli/build.d.ts.map +1 -1
- package/types/constants.d.ts +2 -0
- package/types/constants.d.ts.map +1 -1
- package/types/fork/NavigationContainer.d.ts +19 -8
- package/types/fork/NavigationContainer.d.ts.map +1 -1
- package/types/fork/createMemoryHistory.d.ts +10 -1
- package/types/fork/createMemoryHistory.d.ts.map +1 -1
- package/types/fork/extractPathFromURL.d.ts +7 -1
- package/types/fork/extractPathFromURL.d.ts.map +1 -1
- package/types/fork/findFocusedRoute.d.ts +9 -0
- package/types/fork/findFocusedRoute.d.ts.map +1 -1
- package/types/fork/getPathFromState-mods.d.ts +23 -0
- package/types/fork/getPathFromState-mods.d.ts.map +1 -0
- package/types/fork/getPathFromState.d.ts +15 -14
- package/types/fork/getPathFromState.d.ts.map +1 -1
- package/types/fork/getStateFromPath-mods.d.ts +58 -0
- package/types/fork/getStateFromPath-mods.d.ts.map +1 -0
- package/types/fork/getStateFromPath.d.ts +28 -29
- package/types/fork/getStateFromPath.d.ts.map +1 -1
- package/types/fork/useBackButton.d.ts +6 -0
- package/types/fork/useBackButton.d.ts.map +1 -1
- package/types/fork/useBackButton.native.d.ts +9 -1
- package/types/fork/useBackButton.native.d.ts.map +1 -1
- package/types/fork/useDocumentTitle.d.ts +8 -6
- package/types/fork/useDocumentTitle.d.ts.map +1 -1
- package/types/fork/useDocumentTitle.native.d.ts +5 -2
- package/types/fork/useDocumentTitle.native.d.ts.map +1 -1
- package/types/fork/useLinking.d.ts +8 -1
- package/types/fork/useLinking.d.ts.map +1 -1
- package/types/fork/useLinking.native.d.ts +9 -2
- package/types/fork/useLinking.native.d.ts.map +1 -1
- package/types/fork/useThenable.d.ts +6 -0
- package/types/fork/useThenable.d.ts.map +1 -1
- package/types/fork/validatePathConfig.d.ts +8 -1
- package/types/fork/validatePathConfig.d.ts.map +1 -1
- package/types/link/linking.d.ts +2 -2
- package/types/link/linking.d.ts.map +1 -1
- package/types/utils/serverContext.d.ts.map +1 -1
- package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
@@ -1,20 +1,34 @@
|
|
1
|
-
|
1
|
+
/**
|
2
|
+
* This file is copied from the react-navigation repo:
|
3
|
+
* https://github.com/react-navigation/react-navigation/blob/%40react-navigation/core%407.1.2/packages/native/src/useBackButton.native.tsx
|
4
|
+
*
|
5
|
+
* No changes are made except of formatting.
|
6
|
+
*/
|
2
7
|
|
8
|
+
import type { NavigationContainerRef, ParamListBase } from '@react-navigation/core'
|
3
9
|
import * as React from 'react'
|
4
10
|
import { BackHandler } from 'react-native'
|
5
|
-
|
11
|
+
|
12
|
+
export function useBackButton(
|
13
|
+
ref: React.RefObject<NavigationContainerRef<ParamListBase>>
|
14
|
+
) {
|
6
15
|
React.useEffect(() => {
|
7
16
|
const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
|
8
17
|
const navigation = ref.current
|
18
|
+
|
9
19
|
if (navigation == null) {
|
10
20
|
return false
|
11
21
|
}
|
22
|
+
|
12
23
|
if (navigation.canGoBack()) {
|
13
24
|
navigation.goBack()
|
25
|
+
|
14
26
|
return true
|
15
27
|
}
|
28
|
+
|
16
29
|
return false
|
17
30
|
})
|
31
|
+
|
18
32
|
return () => subscription.remove()
|
19
33
|
}, [ref])
|
20
34
|
}
|
@@ -1,5 +1,14 @@
|
|
1
|
-
|
1
|
+
/**
|
2
|
+
* This file is copied from the react-navigation repo:
|
3
|
+
* https://github.com/react-navigation/react-navigation/blob/%40react-navigation/core%407.1.2/packages/native/src/useBackButton.tsx
|
4
|
+
*
|
5
|
+
* No changes are made except of formatting.
|
6
|
+
*/
|
2
7
|
|
3
8
|
import type { NavigationContainerRef, ParamListBase } from '@react-navigation/core'
|
4
9
|
|
5
|
-
|
10
|
+
// eslint-disable-next-line @eslint-react/hooks-extra/ensure-custom-hooks-using-other-hooks
|
11
|
+
export function useBackButton(_: React.RefObject<NavigationContainerRef<ParamListBase>>) {
|
12
|
+
// No-op
|
13
|
+
// BackHandler is not available on web
|
14
|
+
}
|
@@ -1,6 +1,11 @@
|
|
1
|
-
// No change just vendored to avoid import issue with RR7
|
2
|
-
|
3
1
|
/**
|
4
|
-
*
|
2
|
+
* This file is copied from the react-navigation repo:
|
3
|
+
* https://github.com/react-navigation/react-navigation/blob/%40react-navigation/core%407.1.2/packages/native/src/useDocumentTitle.native.tsx
|
4
|
+
*
|
5
|
+
* No changes are made except of formatting.
|
5
6
|
*/
|
6
|
-
|
7
|
+
|
8
|
+
// eslint-disable-next-line @eslint-react/hooks-extra/ensure-custom-hooks-using-other-hooks
|
9
|
+
export function useDocumentTitle() {
|
10
|
+
// Noop for native platforms
|
11
|
+
}
|
@@ -1,12 +1,14 @@
|
|
1
|
-
|
1
|
+
/**
|
2
|
+
* This file is copied from the react-navigation repo:
|
3
|
+
* https://github.com/react-navigation/react-navigation/blob/%40react-navigation/core%407.1.2/packages/native/src/useDocumentTitle.tsx
|
4
|
+
*
|
5
|
+
* No changes are made except of formatting and updating the imports.
|
6
|
+
*/
|
2
7
|
|
3
|
-
import type { NavigationContainerRef, ParamListBase
|
8
|
+
import type { NavigationContainerRef, ParamListBase } from '@react-navigation/core'
|
4
9
|
import * as React from 'react'
|
5
10
|
|
6
|
-
type DocumentTitleOptions
|
7
|
-
enabled?: boolean
|
8
|
-
formatter?: (options: Record<string, any> | undefined, route: Route<string> | undefined) => string
|
9
|
-
}
|
11
|
+
import type { DocumentTitleOptions } from '@react-navigation/native'
|
10
12
|
|
11
13
|
/**
|
12
14
|
* Set the document title for the active screen
|
@@ -26,7 +28,10 @@ export function useDocumentTitle(
|
|
26
28
|
const navigation = ref.current
|
27
29
|
|
28
30
|
if (navigation) {
|
29
|
-
const title = formatter(
|
31
|
+
const title = formatter(
|
32
|
+
navigation.getCurrentOptions(),
|
33
|
+
navigation.getCurrentRoute()
|
34
|
+
)
|
30
35
|
|
31
36
|
document.title = title
|
32
37
|
}
|
@@ -1,19 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
/**
|
2
|
+
* This file is copied from the react-navigation repo:
|
3
|
+
* https://github.com/react-navigation/react-navigation/blob/%40react-navigation/core%407.1.2/packages/native/src/useLinking.native.tsx
|
4
|
+
*
|
5
|
+
* Please refrain from making changes to this file, as it will make merging updates from the upstream harder.
|
6
|
+
* All modifications except formatting should be marked with `// @modified` comment.
|
7
|
+
*/
|
8
|
+
|
5
9
|
import {
|
6
|
-
type NavigationContainerRef,
|
7
|
-
type ParamListBase,
|
8
10
|
getActionFromState as getActionFromStateDefault,
|
9
11
|
getStateFromPath as getStateFromPathDefault,
|
12
|
+
type NavigationContainerRef,
|
13
|
+
type ParamListBase,
|
10
14
|
useNavigationIndependentTree,
|
11
15
|
} from '@react-navigation/core'
|
12
|
-
import type { LinkingOptions } from '@react-navigation/native'
|
13
16
|
import * as React from 'react'
|
14
17
|
import { Linking, Platform } from 'react-native'
|
15
18
|
|
16
|
-
import {
|
19
|
+
import { extractPathFromURL } from './extractPathFromURL'
|
20
|
+
import type { LinkingOptions } from '@react-navigation/native' // @modified: import from @react-navigation/native
|
17
21
|
|
18
22
|
type ResultState = ReturnType<typeof getStateFromPathDefault>
|
19
23
|
|
@@ -21,21 +25,21 @@ type Options = LinkingOptions<ParamListBase>
|
|
21
25
|
|
22
26
|
const linkingHandlers: symbol[] = []
|
23
27
|
|
24
|
-
export
|
28
|
+
export function useLinking(
|
25
29
|
ref: React.RefObject<NavigationContainerRef<ParamListBase>>,
|
26
30
|
{
|
27
|
-
|
28
|
-
|
31
|
+
enabled = true,
|
32
|
+
prefixes,
|
29
33
|
filter,
|
30
34
|
config,
|
31
35
|
getInitialURL = () =>
|
32
36
|
Promise.race([
|
33
37
|
Linking.getInitialURL(),
|
34
|
-
new Promise<undefined>((resolve) =>
|
38
|
+
new Promise<undefined>((resolve) => {
|
35
39
|
// Timeout in 150ms if `getInitialState` doesn't resolve
|
36
40
|
// Workaround for https://github.com/facebook/react-native/issues/25675
|
37
41
|
setTimeout(resolve, 150)
|
38
|
-
),
|
42
|
+
}),
|
39
43
|
]),
|
40
44
|
subscribe = (listener) => {
|
41
45
|
const callback = ({ url }: { url: string }) => listener(url)
|
@@ -44,13 +48,23 @@ export default function useLinking(
|
|
44
48
|
| { remove(): void }
|
45
49
|
| undefined
|
46
50
|
|
51
|
+
// Storing this in a local variable stops Jest from complaining about import after teardown
|
52
|
+
// @ts-expect-error: removeEventListener is not present in newer RN versions
|
53
|
+
const removeEventListener = Linking.removeEventListener?.bind(Linking)
|
54
|
+
|
47
55
|
return () => {
|
48
|
-
|
56
|
+
// https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7
|
57
|
+
if (subscription?.remove) {
|
58
|
+
subscription.remove()
|
59
|
+
} else {
|
60
|
+
removeEventListener?.('url', callback)
|
61
|
+
}
|
49
62
|
}
|
50
63
|
},
|
51
64
|
getStateFromPath = getStateFromPathDefault,
|
52
65
|
getActionFromState = getActionFromStateDefault,
|
53
|
-
}: Options
|
66
|
+
}: Options,
|
67
|
+
onUnhandledLinking: (lastUnhandledLining: string | undefined) => void
|
54
68
|
) {
|
55
69
|
const independent = useNavigationIndependentTree()
|
56
70
|
|
@@ -60,13 +74,10 @@ export default function useLinking(
|
|
60
74
|
}
|
61
75
|
|
62
76
|
if (independent) {
|
63
|
-
return
|
77
|
+
return undefined
|
64
78
|
}
|
65
79
|
|
66
|
-
if (
|
67
|
-
// enabled !== false &&
|
68
|
-
linkingHandlers.length
|
69
|
-
) {
|
80
|
+
if (enabled !== false && linkingHandlers.length) {
|
70
81
|
console.error(
|
71
82
|
[
|
72
83
|
'Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:',
|
@@ -83,9 +94,9 @@ export default function useLinking(
|
|
83
94
|
|
84
95
|
const handler = Symbol()
|
85
96
|
|
86
|
-
|
87
|
-
|
88
|
-
|
97
|
+
if (enabled !== false) {
|
98
|
+
linkingHandlers.push(handler)
|
99
|
+
}
|
89
100
|
|
90
101
|
return () => {
|
91
102
|
const index = linkingHandlers.indexOf(handler)
|
@@ -94,16 +105,13 @@ export default function useLinking(
|
|
94
105
|
linkingHandlers.splice(index, 1)
|
95
106
|
}
|
96
107
|
}
|
97
|
-
}, [
|
98
|
-
// enabled,
|
99
|
-
independent,
|
100
|
-
])
|
108
|
+
}, [enabled, independent])
|
101
109
|
|
102
110
|
// We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners
|
103
111
|
// This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`
|
104
112
|
// Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect
|
105
|
-
|
106
|
-
|
113
|
+
const enabledRef = React.useRef(enabled)
|
114
|
+
const prefixesRef = React.useRef(prefixes)
|
107
115
|
const filterRef = React.useRef(filter)
|
108
116
|
const configRef = React.useRef(config)
|
109
117
|
const getInitialURLRef = React.useRef(getInitialURL)
|
@@ -111,8 +119,8 @@ export default function useLinking(
|
|
111
119
|
const getActionFromStateRef = React.useRef(getActionFromState)
|
112
120
|
|
113
121
|
React.useEffect(() => {
|
114
|
-
|
115
|
-
|
122
|
+
enabledRef.current = enabled
|
123
|
+
prefixesRef.current = prefixes
|
116
124
|
filterRef.current = filter
|
117
125
|
configRef.current = config
|
118
126
|
getInitialURLRef.current = getInitialURL
|
@@ -125,33 +133,42 @@ export default function useLinking(
|
|
125
133
|
return undefined
|
126
134
|
}
|
127
135
|
|
128
|
-
|
129
|
-
const path = extractExpoPathFromURL(url)
|
136
|
+
const path = extractPathFromURL(prefixesRef.current, url)
|
130
137
|
|
131
138
|
return path !== undefined ? getStateFromPathRef.current(path, configRef.current) : undefined
|
132
139
|
}, [])
|
133
140
|
|
134
141
|
const getInitialState = React.useCallback(() => {
|
135
|
-
|
136
|
-
// if (enabledRef.current) {
|
137
|
-
const url = getInitialURLRef.current()
|
142
|
+
let state: ResultState | undefined
|
138
143
|
|
139
|
-
if (
|
140
|
-
|
141
|
-
const state = getStateFromURL(url)
|
144
|
+
if (enabledRef.current) {
|
145
|
+
const url = getInitialURLRef.current()
|
142
146
|
|
143
|
-
|
144
|
-
|
145
|
-
|
147
|
+
if (url != null) {
|
148
|
+
if (typeof url !== 'string') {
|
149
|
+
return url.then((url) => {
|
150
|
+
const state = getStateFromURL(url)
|
151
|
+
|
152
|
+
if (typeof url === 'string') {
|
153
|
+
// If the link were handled, it gets cleared in NavigationContainer
|
154
|
+
onUnhandledLinking(extractPathFromURL(prefixes, url))
|
155
|
+
}
|
156
|
+
|
157
|
+
return state
|
158
|
+
})
|
159
|
+
// biome-ignore lint/style/noUselessElse: don't check copied code
|
160
|
+
} else {
|
161
|
+
onUnhandledLinking(extractPathFromURL(prefixes, url))
|
162
|
+
}
|
163
|
+
}
|
146
164
|
|
147
|
-
|
148
|
-
|
165
|
+
state = getStateFromURL(url)
|
166
|
+
}
|
149
167
|
|
150
168
|
const thenable = {
|
151
|
-
// biome-ignore lint/suspicious/noThenProperty:
|
169
|
+
// biome-ignore lint/suspicious/noThenProperty: don't check copied code
|
152
170
|
then(onfulfilled?: (state: ResultState | undefined) => void) {
|
153
|
-
onfulfilled
|
154
|
-
return thenable
|
171
|
+
return Promise.resolve(onfulfilled ? onfulfilled(state) : state)
|
155
172
|
},
|
156
173
|
catch() {
|
157
174
|
return thenable
|
@@ -159,26 +176,22 @@ export default function useLinking(
|
|
159
176
|
}
|
160
177
|
|
161
178
|
return thenable as PromiseLike<ResultState | undefined>
|
162
|
-
}, [getStateFromURL])
|
179
|
+
}, [getStateFromURL, onUnhandledLinking, prefixes])
|
163
180
|
|
164
181
|
React.useEffect(() => {
|
165
182
|
const listener = (url: string) => {
|
166
|
-
|
167
|
-
|
168
|
-
|
183
|
+
if (!enabled) {
|
184
|
+
return
|
185
|
+
}
|
169
186
|
|
170
187
|
const navigation = ref.current
|
171
188
|
const state = navigation ? getStateFromURL(url) : undefined
|
172
189
|
|
173
190
|
if (navigation && state) {
|
174
|
-
//
|
175
|
-
|
191
|
+
// If the link were handled, it gets cleared in NavigationContainer
|
192
|
+
onUnhandledLinking(extractPathFromURL(prefixes, url))
|
176
193
|
const rootState = navigation.getRootState()
|
177
|
-
|
178
194
|
if (state.routes.some((r) => !rootState?.routeNames.includes(r.name))) {
|
179
|
-
console.warn(
|
180
|
-
"The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration."
|
181
|
-
)
|
182
195
|
return
|
183
196
|
}
|
184
197
|
|
@@ -203,12 +216,7 @@ export default function useLinking(
|
|
203
216
|
}
|
204
217
|
|
205
218
|
return subscribe(listener)
|
206
|
-
}, [
|
207
|
-
// enabled,
|
208
|
-
getStateFromURL,
|
209
|
-
ref,
|
210
|
-
subscribe,
|
211
|
-
])
|
219
|
+
}, [enabled, getStateFromURL, onUnhandledLinking, prefixes, ref, subscribe])
|
212
220
|
|
213
221
|
return {
|
214
222
|
getInitialState,
|
package/src/fork/useLinking.ts
CHANGED
@@ -1,41 +1,34 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
/**
|
2
|
+
* This file is copied from the react-navigation repo:
|
3
|
+
* https://github.com/react-navigation/react-navigation/blob/%40react-navigation/core%407.1.2/packages/native/src/useLinking.tsx
|
4
|
+
*
|
5
|
+
* Please refrain from making changes to this file, as it will make merging updates from the upstream harder.
|
6
|
+
* All modifications except formatting should be marked with `// @modified` comment.
|
7
|
+
*/
|
4
8
|
|
5
9
|
import {
|
6
10
|
findFocusedRoute,
|
7
11
|
getActionFromState as getActionFromStateDefault,
|
8
12
|
getPathFromState as getPathFromStateDefault,
|
9
13
|
getStateFromPath as getStateFromPathDefault,
|
10
|
-
useNavigationIndependentTree,
|
11
14
|
type NavigationContainerRef,
|
12
15
|
type NavigationState,
|
13
16
|
type ParamListBase,
|
17
|
+
useNavigationIndependentTree,
|
14
18
|
} from '@react-navigation/core'
|
15
19
|
import isEqual from 'fast-deep-equal'
|
16
20
|
import * as React from 'react'
|
17
21
|
|
18
|
-
|
19
|
-
//
|
20
|
-
import
|
21
|
-
|
22
|
-
// This was removed as we don't use ServerContext
|
23
|
-
// import ServerContext from './ServerContext';
|
22
|
+
import { createMemoryHistory } from './createMemoryHistory'
|
23
|
+
// @modified - start
|
24
|
+
// import { ServerContext } from '@react-navigation/web';
|
24
25
|
import { ServerLocationContext } from '../router/serverLocationContext'
|
25
|
-
|
26
|
-
import type { LinkingOptions } from '@react-navigation/native'
|
27
|
-
import { appendBaseUrl } from './getPathFromState'
|
26
|
+
// @modified - end
|
27
|
+
import type { LinkingOptions } from '@react-navigation/native' // @modified: change import path
|
28
|
+
import { appendBaseUrl } from './getPathFromState-mods'
|
28
29
|
|
29
30
|
type ResultState = ReturnType<typeof getStateFromPathDefault>
|
30
31
|
|
31
|
-
const historyGlobal = createMemoryHistory()
|
32
|
-
|
33
|
-
if (typeof window !== 'undefined') {
|
34
|
-
historyGlobal.listen(() => {
|
35
|
-
globalThis['__vxrntodopath'] = window.location.pathname
|
36
|
-
})
|
37
|
-
}
|
38
|
-
|
39
32
|
/**
|
40
33
|
* Find the matching navigation state that changed between 2 navigation states
|
41
34
|
* e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state
|
@@ -82,16 +75,17 @@ const findMatchingState = <T extends NavigationState>(
|
|
82
75
|
export const series = (cb: () => Promise<void>) => {
|
83
76
|
let queue = Promise.resolve()
|
84
77
|
const callback = () => {
|
78
|
+
// eslint-disable-next-line promise/no-callback-in-promise
|
85
79
|
queue = queue.then(cb)
|
86
80
|
}
|
87
81
|
return callback
|
88
82
|
}
|
89
83
|
|
90
|
-
|
84
|
+
const linkingHandlers: symbol[] = []
|
91
85
|
|
92
86
|
type Options = LinkingOptions<ParamListBase>
|
93
87
|
|
94
|
-
export
|
88
|
+
export function useLinking(
|
95
89
|
ref: React.RefObject<NavigationContainerRef<ParamListBase>>,
|
96
90
|
{
|
97
91
|
enabled = true,
|
@@ -99,7 +93,8 @@ export default function useLinking(
|
|
99
93
|
getStateFromPath = getStateFromPathDefault,
|
100
94
|
getPathFromState = getPathFromStateDefault,
|
101
95
|
getActionFromState = getActionFromStateDefault,
|
102
|
-
}: Options
|
96
|
+
}: Options,
|
97
|
+
onUnhandledLinking: (lastUnhandledLining: string | undefined) => void
|
103
98
|
) {
|
104
99
|
const independent = useNavigationIndependentTree()
|
105
100
|
|
@@ -139,7 +134,7 @@ export default function useLinking(
|
|
139
134
|
}
|
140
135
|
}, [enabled, independent])
|
141
136
|
|
142
|
-
const [history] = React.useState(
|
137
|
+
const [history] = React.useState(createMemoryHistory)
|
143
138
|
|
144
139
|
// We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners
|
145
140
|
// This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`
|
@@ -158,12 +153,24 @@ export default function useLinking(
|
|
158
153
|
getActionFromStateRef.current = getActionFromState
|
159
154
|
})
|
160
155
|
|
161
|
-
|
156
|
+
const validateRoutesNotExistInRootState = React.useCallback(
|
157
|
+
(state: ResultState) => {
|
158
|
+
const navigation = ref.current
|
159
|
+
const rootState = navigation?.getRootState()
|
160
|
+
// Make sure that the routes in the state exist in the root navigator
|
161
|
+
// Otherwise there's an error in the linking configuration
|
162
|
+
return state?.routes.some((r) => !rootState?.routeNames.includes(r.name))
|
163
|
+
},
|
164
|
+
[ref]
|
165
|
+
)
|
166
|
+
|
167
|
+
// @modified - start
|
162
168
|
// ServerContext is used inside ServerContainer to set the location during SSR: https://github.com/react-navigation/react-navigation/blob/13d4aa270b301faf07960b4cd861ffc91e9b2c46/packages/native/src/ServerContainer.tsx#L50-L54
|
163
169
|
// One uses the `initialLocation` prop to set the initial location during SSR:
|
170
|
+
// const server = React.useContext(ServerContext)
|
164
171
|
const location = React.useContext(ServerLocationContext)
|
165
172
|
const server = { location }
|
166
|
-
|
173
|
+
// @modified - end
|
167
174
|
|
168
175
|
const getInitialState = React.useCallback(() => {
|
169
176
|
let value: ResultState | undefined
|
@@ -177,10 +184,13 @@ export default function useLinking(
|
|
177
184
|
if (path) {
|
178
185
|
value = getStateFromPathRef.current(path, configRef.current)
|
179
186
|
}
|
187
|
+
|
188
|
+
// If the link were handled, it gets cleared in NavigationContainer
|
189
|
+
onUnhandledLinking(path)
|
180
190
|
}
|
181
191
|
|
182
192
|
const thenable = {
|
183
|
-
// biome-ignore lint/suspicious/noThenProperty:
|
193
|
+
// biome-ignore lint/suspicious/noThenProperty: don't check copied code
|
184
194
|
then(onfulfilled?: (state: ResultState | undefined) => void) {
|
185
195
|
return Promise.resolve(onfulfilled ? onfulfilled(value) : value)
|
186
196
|
},
|
@@ -232,18 +242,19 @@ export default function useLinking(
|
|
232
242
|
// We should only dispatch an action when going forward
|
233
243
|
// Otherwise the action will likely add items to history, which would mess things up
|
234
244
|
if (state) {
|
245
|
+
// If the link were handled, it gets cleared in NavigationContainer
|
246
|
+
onUnhandledLinking(path)
|
235
247
|
// Make sure that the routes in the state exist in the root navigator
|
236
248
|
// Otherwise there's an error in the linking configuration
|
237
|
-
|
238
|
-
|
239
|
-
if (state.routes.some((r) => !rootState?.routeNames.includes(r.name))) {
|
240
|
-
console.warn(
|
241
|
-
"The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration."
|
242
|
-
)
|
249
|
+
if (validateRoutesNotExistInRootState(state)) {
|
243
250
|
return
|
244
251
|
}
|
245
252
|
|
246
|
-
|
253
|
+
// @modified: workaround to make react-navigation handle hash changes
|
254
|
+
if (
|
255
|
+
index > previousIndex ||
|
256
|
+
(index === previousIndex && (!record || `${record?.path}${location.hash}` === path))
|
257
|
+
) {
|
247
258
|
const action = getActionFromStateRef.current(state, configRef.current)
|
248
259
|
|
249
260
|
if (action !== undefined) {
|
@@ -269,7 +280,7 @@ export default function useLinking(
|
|
269
280
|
navigation.resetRoot(state)
|
270
281
|
}
|
271
282
|
})
|
272
|
-
}, [enabled, history, ref])
|
283
|
+
}, [enabled, history, onUnhandledLinking, ref, validateRoutesNotExistInRootState])
|
273
284
|
|
274
285
|
React.useEffect(() => {
|
275
286
|
if (!enabled) {
|
@@ -280,6 +291,8 @@ export default function useLinking(
|
|
280
291
|
route: ReturnType<typeof findFocusedRoute>,
|
281
292
|
state: NavigationState
|
282
293
|
): string => {
|
294
|
+
let path
|
295
|
+
|
283
296
|
// If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match
|
284
297
|
// This makes sure that we preserve the original URL for wildcard routes
|
285
298
|
if (route?.path) {
|
@@ -293,14 +306,36 @@ export default function useLinking(
|
|
293
306
|
focusedRoute.name === route.name &&
|
294
307
|
isEqual(focusedRoute.params, route.params)
|
295
308
|
) {
|
296
|
-
|
297
|
-
|
298
|
-
|
309
|
+
// @modified - start
|
310
|
+
// path = route.path
|
311
|
+
path = appendBaseUrl(route.path)
|
312
|
+
// @modified - end
|
299
313
|
}
|
300
314
|
}
|
301
315
|
}
|
302
316
|
|
303
|
-
|
317
|
+
if (path == null) {
|
318
|
+
path = getPathFromStateRef.current(state, configRef.current)
|
319
|
+
}
|
320
|
+
|
321
|
+
// @modified - start: One will handle hashes itself, so these lines are not needed
|
322
|
+
// const previousRoute = previousStateRef.current
|
323
|
+
// ? findFocusedRoute(previousStateRef.current)
|
324
|
+
// : undefined
|
325
|
+
|
326
|
+
// // Preserve the hash if the route didn't change
|
327
|
+
// if (
|
328
|
+
// previousRoute &&
|
329
|
+
// route &&
|
330
|
+
// 'key' in previousRoute &&
|
331
|
+
// 'key' in route &&
|
332
|
+
// previousRoute.key === route.key
|
333
|
+
// ) {
|
334
|
+
// path = path + location.hash
|
335
|
+
// }
|
336
|
+
// @modified - end
|
337
|
+
|
338
|
+
return path
|
304
339
|
}
|
305
340
|
|
306
341
|
if (ref.current) {
|
package/src/fork/useThenable.tsx
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
|
1
|
+
/**
|
2
|
+
* This file is copied from the react-navigation repo:
|
3
|
+
* https://github.com/react-navigation/react-navigation/blob/%40react-navigation/core%407.1.2/packages/native/src/useThenable.tsx
|
4
|
+
*
|
5
|
+
* No changes are made except of formatting.
|
6
|
+
*/
|
7
|
+
|
2
8
|
import * as React from 'react'
|
3
9
|
|
4
10
|
export function useThenable<T>(create: () => PromiseLike<T>) {
|