one 1.1.370 → 1.1.372
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/cli/runAndroid.js.map +1 -1
- package/dist/cjs/cli/runAndroid.native.js.map +1 -1
- package/dist/cjs/createApp.native.js +6 -2
- package/dist/cjs/createApp.native.js.map +2 -2
- package/dist/cjs/fork/NavigationContainer.cjs +39 -37
- package/dist/cjs/fork/NavigationContainer.js +20 -26
- package/dist/cjs/fork/NavigationContainer.js.map +1 -1
- package/dist/cjs/fork/NavigationContainer.native.js +35 -34
- package/dist/cjs/fork/NavigationContainer.native.js.map +3 -3
- package/dist/cjs/fork/getPathFromState.cjs +7 -4
- package/dist/cjs/fork/getPathFromState.js +7 -4
- package/dist/cjs/fork/getPathFromState.js.map +1 -1
- package/dist/cjs/fork/getPathFromState.native.js +7 -4
- package/dist/cjs/fork/getPathFromState.native.js.map +1 -1
- package/dist/cjs/fork/useBackButton.cjs +26 -0
- package/dist/cjs/fork/useBackButton.js +22 -0
- package/dist/cjs/fork/useBackButton.js.map +6 -0
- package/dist/cjs/fork/useBackButton.native.js +47 -0
- package/dist/cjs/fork/useBackButton.native.js.map +6 -0
- package/dist/cjs/fork/useDocumentTitle.cjs +54 -0
- package/dist/cjs/fork/useDocumentTitle.js +47 -0
- package/dist/cjs/fork/useDocumentTitle.js.map +6 -0
- package/dist/cjs/fork/useDocumentTitle.native.js +27 -0
- package/dist/cjs/fork/useDocumentTitle.native.js.map +6 -0
- package/dist/cjs/fork/useLinking.cjs +1 -1
- package/dist/cjs/fork/useLinking.js +1 -1
- package/dist/cjs/fork/useLinking.js.map +1 -1
- package/dist/cjs/fork/useLinking.native.js +6 -3
- package/dist/cjs/fork/useLinking.native.js.map +2 -2
- package/dist/cjs/fork/useThenable.cjs +59 -0
- package/dist/cjs/fork/useThenable.js +50 -0
- package/dist/cjs/fork/useThenable.js.map +6 -0
- package/dist/cjs/fork/useThenable.native.js +66 -0
- package/dist/cjs/fork/useThenable.native.js.map +6 -0
- package/dist/cjs/layouts/Tabs.cjs +19 -2
- package/dist/cjs/layouts/Tabs.js +16 -2
- package/dist/cjs/layouts/Tabs.js.map +1 -1
- package/dist/cjs/layouts/Tabs.native.js +16 -1
- package/dist/cjs/layouts/Tabs.native.js.map +2 -2
- package/dist/cjs/layouts/withLayoutContext.cjs +3 -4
- package/dist/cjs/layouts/withLayoutContext.js +3 -6
- package/dist/cjs/layouts/withLayoutContext.js.map +1 -1
- package/dist/cjs/layouts/withLayoutContext.native.js +8 -10
- package/dist/cjs/layouts/withLayoutContext.native.js.map +2 -2
- package/dist/cjs/setup.cjs +2 -8
- package/dist/cjs/setup.js +2 -10
- package/dist/cjs/setup.js.map +1 -1
- package/dist/cjs/vite/build.cjs +5 -5
- package/dist/cjs/vite/build.js +3 -3
- package/dist/cjs/vite/build.js.map +1 -1
- package/dist/cjs/vite/build.native.js +3 -3
- package/dist/cjs/vite/build.native.js.map +1 -1
- package/dist/cjs/vite/loadConfig.cjs +44 -0
- package/dist/cjs/vite/loadConfig.js +41 -0
- package/dist/cjs/vite/loadConfig.js.map +6 -0
- package/dist/cjs/vite/loadConfig.native.js +48 -0
- package/dist/cjs/vite/loadConfig.native.js.map +6 -0
- package/dist/cjs/vite/one.cjs +64 -38
- package/dist/cjs/vite/one.js +65 -45
- package/dist/cjs/vite/one.js.map +1 -1
- package/dist/cjs/vite/one.native.js +67 -47
- package/dist/cjs/vite/one.native.js.map +2 -2
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.cjs +4 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js +4 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +4 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +2 -2
- package/dist/cjs/vite/plugins/reactCompilerPlugin.cjs +8 -5
- package/dist/cjs/vite/plugins/reactCompilerPlugin.js +8 -5
- package/dist/cjs/vite/plugins/reactCompilerPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/reactCompilerPlugin.native.js +26 -21
- package/dist/cjs/vite/plugins/reactCompilerPlugin.native.js.map +2 -2
- package/dist/esm/cli/runAndroid.js.map +1 -1
- package/dist/esm/cli/runAndroid.mjs.map +1 -1
- package/dist/esm/cli/runAndroid.native.js.map +1 -1
- package/dist/esm/createApp.native.js +6 -1
- package/dist/esm/createApp.native.js.map +2 -2
- package/dist/esm/fork/NavigationContainer.js +22 -25
- package/dist/esm/fork/NavigationContainer.js.map +1 -1
- package/dist/esm/fork/NavigationContainer.mjs +35 -33
- package/dist/esm/fork/NavigationContainer.mjs.map +1 -1
- package/dist/esm/fork/NavigationContainer.native.js +31 -29
- package/dist/esm/fork/NavigationContainer.native.js.map +3 -3
- package/dist/esm/fork/getPathFromState.js +7 -4
- package/dist/esm/fork/getPathFromState.js.map +1 -1
- package/dist/esm/fork/getPathFromState.mjs +7 -4
- package/dist/esm/fork/getPathFromState.mjs.map +1 -1
- package/dist/esm/fork/getPathFromState.native.js +7 -4
- package/dist/esm/fork/getPathFromState.native.js.map +1 -1
- package/dist/esm/fork/useBackButton.js +6 -0
- package/dist/esm/fork/useBackButton.js.map +6 -0
- package/dist/esm/fork/useBackButton.mjs +3 -0
- package/dist/esm/fork/useBackButton.mjs.map +1 -0
- package/dist/esm/fork/useBackButton.native.js +19 -0
- package/dist/esm/fork/useBackButton.native.js.map +6 -0
- package/dist/esm/fork/useDocumentTitle.js +23 -0
- package/dist/esm/fork/useDocumentTitle.js.map +6 -0
- package/dist/esm/fork/useDocumentTitle.mjs +20 -0
- package/dist/esm/fork/useDocumentTitle.mjs.map +1 -0
- package/dist/esm/fork/useDocumentTitle.native.js +6 -0
- package/dist/esm/fork/useDocumentTitle.native.js.map +6 -0
- package/dist/esm/fork/useLinking.js +3 -2
- package/dist/esm/fork/useLinking.js.map +1 -1
- package/dist/esm/fork/useLinking.mjs +2 -2
- package/dist/esm/fork/useLinking.mjs.map +1 -1
- package/dist/esm/fork/useLinking.native.js +7 -4
- package/dist/esm/fork/useLinking.native.js.map +2 -2
- package/dist/esm/fork/useThenable.js +26 -0
- package/dist/esm/fork/useThenable.js.map +6 -0
- package/dist/esm/fork/useThenable.mjs +25 -0
- package/dist/esm/fork/useThenable.mjs.map +1 -0
- package/dist/esm/fork/useThenable.native.js +37 -0
- package/dist/esm/fork/useThenable.native.js.map +6 -0
- package/dist/esm/layouts/Drawer.js.map +1 -1
- package/dist/esm/layouts/Drawer.mjs.map +1 -1
- package/dist/esm/layouts/Drawer.native.js.map +1 -1
- package/dist/esm/layouts/Tabs.js +18 -3
- package/dist/esm/layouts/Tabs.js.map +1 -1
- package/dist/esm/layouts/Tabs.mjs +20 -3
- package/dist/esm/layouts/Tabs.mjs.map +1 -1
- package/dist/esm/layouts/Tabs.native.js +17 -2
- package/dist/esm/layouts/Tabs.native.js.map +2 -2
- package/dist/esm/layouts/withLayoutContext.js +2 -5
- package/dist/esm/layouts/withLayoutContext.js.map +1 -1
- package/dist/esm/layouts/withLayoutContext.mjs +3 -5
- package/dist/esm/layouts/withLayoutContext.mjs.map +1 -1
- package/dist/esm/layouts/withLayoutContext.native.js +8 -10
- package/dist/esm/layouts/withLayoutContext.native.js.map +2 -2
- package/dist/esm/setup.js +2 -10
- package/dist/esm/setup.js.map +1 -1
- package/dist/esm/setup.mjs +2 -8
- package/dist/esm/setup.mjs.map +1 -1
- package/dist/esm/vite/build.js +3 -3
- package/dist/esm/vite/build.js.map +1 -1
- package/dist/esm/vite/build.mjs +3 -3
- package/dist/esm/vite/build.mjs.map +1 -1
- package/dist/esm/vite/build.native.js +3 -3
- package/dist/esm/vite/build.native.js.map +2 -2
- package/dist/esm/vite/loadConfig.js +26 -0
- package/dist/esm/vite/loadConfig.js.map +6 -0
- package/dist/esm/vite/loadConfig.mjs +20 -0
- package/dist/esm/vite/loadConfig.mjs.map +1 -0
- package/dist/esm/vite/loadConfig.native.js +27 -0
- package/dist/esm/vite/loadConfig.native.js.map +6 -0
- package/dist/esm/vite/one.js +65 -45
- package/dist/esm/vite/one.js.map +1 -1
- package/dist/esm/vite/one.mjs +65 -38
- package/dist/esm/vite/one.mjs.map +1 -1
- package/dist/esm/vite/one.native.js +67 -46
- package/dist/esm/vite/one.native.js.map +2 -2
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js +4 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs +4 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +4 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +2 -2
- package/dist/esm/vite/plugins/reactCompilerPlugin.js +8 -5
- package/dist/esm/vite/plugins/reactCompilerPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/reactCompilerPlugin.mjs +8 -5
- package/dist/esm/vite/plugins/reactCompilerPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/reactCompilerPlugin.native.js +26 -21
- package/dist/esm/vite/plugins/reactCompilerPlugin.native.js.map +2 -2
- package/package.json +49 -48
- package/src/cli/runAndroid.ts +0 -2
- package/src/cli/runIos.ts +1 -1
- package/src/createApp.native.tsx +13 -1
- package/src/fork/NavigationContainer.tsx +42 -45
- package/src/fork/getPathFromState.ts +10 -4
- package/src/fork/useBackButton.native.tsx +20 -0
- package/src/fork/useBackButton.tsx +5 -0
- package/src/fork/useDocumentTitle.native.tsx +6 -0
- package/src/fork/useDocumentTitle.tsx +40 -0
- package/src/fork/useLinking.native.ts +40 -42
- package/src/fork/useLinking.ts +4 -4
- package/src/fork/useThenable.tsx +43 -0
- package/src/interfaces/router.ts +3 -2
- package/src/layouts/Drawer.tsx +2 -2
- package/src/layouts/Tabs.tsx +27 -2
- package/src/layouts/withLayoutContext.tsx +3 -3
- package/src/setup.ts +2 -10
- package/src/vite/build.ts +3 -3
- package/src/vite/loadConfig.ts +31 -0
- package/src/vite/one.ts +95 -49
- package/src/vite/plugins/fileSystemRouterPlugin.tsx +4 -1
- package/src/vite/plugins/reactCompilerPlugin.ts +12 -5
- package/src/vite/types.ts +21 -14
- package/types/cli/runAndroid.d.ts.map +1 -1
- package/types/createApp.native.d.ts.map +1 -1
- package/types/fork/NavigationContainer.d.ts +5 -5
- package/types/fork/NavigationContainer.d.ts.map +1 -1
- package/types/fork/createMemoryHistory.d.ts.map +1 -1
- package/types/fork/getPathFromState.d.ts.map +1 -1
- package/types/fork/useBackButton.d.ts +3 -0
- package/types/fork/useBackButton.d.ts.map +1 -0
- package/types/fork/useBackButton.native.d.ts +2 -0
- package/types/fork/useBackButton.native.d.ts.map +1 -0
- package/types/fork/useDocumentTitle.d.ts +12 -0
- package/types/fork/useDocumentTitle.d.ts.map +1 -0
- package/types/fork/useDocumentTitle.native.d.ts +5 -0
- package/types/fork/useDocumentTitle.native.d.ts.map +1 -0
- package/types/fork/useLinking.d.ts +2 -4
- package/types/fork/useLinking.d.ts.map +1 -1
- package/types/fork/useLinking.native.d.ts +3 -19
- package/types/fork/useLinking.native.d.ts.map +1 -1
- package/types/fork/useThenable.d.ts +2 -0
- package/types/fork/useThenable.d.ts.map +1 -0
- package/types/import-mode/index.native.d.ts.map +1 -1
- package/types/interfaces/router.d.ts +2 -2
- package/types/interfaces/router.d.ts.map +1 -1
- package/types/layouts/Drawer.d.ts +76 -80
- package/types/layouts/Drawer.d.ts.map +1 -1
- package/types/layouts/Stack.d.ts +68 -80
- package/types/layouts/Stack.d.ts.map +1 -1
- package/types/layouts/Tabs.d.ts +72 -127
- package/types/layouts/Tabs.d.ts.map +1 -1
- package/types/layouts/withLayoutContext.d.ts +3 -1
- package/types/layouts/withLayoutContext.d.ts.map +1 -1
- package/types/setup.d.ts +1 -1
- package/types/setup.d.ts.map +1 -1
- package/types/useScreens.d.ts +1 -17
- package/types/useScreens.d.ts.map +1 -1
- package/types/vite/loadConfig.d.ts +5 -0
- package/types/vite/loadConfig.d.ts.map +1 -0
- package/types/vite/one.d.ts +1 -2
- package/types/vite/one.d.ts.map +1 -1
- package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
- package/types/vite/plugins/reactCompilerPlugin.d.ts.map +1 -1
- package/types/vite/types.d.ts +30 -25
- package/types/vite/types.d.ts.map +1 -1
- package/src/fork/NavigationContainer.native.tsx +0 -147
- package/types/fork/NavigationContainer.native.d.ts +0 -15
- package/types/fork/NavigationContainer.native.d.ts.map +0 -1
@@ -0,0 +1,40 @@
|
|
1
|
+
// No change just vendored to avoid import issue with RR7
|
2
|
+
|
3
|
+
import type { NavigationContainerRef, ParamListBase, Route } from '@react-navigation/core'
|
4
|
+
import * as React from 'react'
|
5
|
+
|
6
|
+
type DocumentTitleOptions = {
|
7
|
+
enabled?: boolean
|
8
|
+
formatter?: (options: Record<string, any> | undefined, route: Route<string> | undefined) => string
|
9
|
+
}
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Set the document title for the active screen
|
13
|
+
*/
|
14
|
+
export function useDocumentTitle(
|
15
|
+
ref: React.RefObject<NavigationContainerRef<ParamListBase>>,
|
16
|
+
{
|
17
|
+
enabled = true,
|
18
|
+
formatter = (options, route) => options?.title ?? route?.name,
|
19
|
+
}: DocumentTitleOptions = {}
|
20
|
+
) {
|
21
|
+
React.useEffect(() => {
|
22
|
+
if (!enabled) {
|
23
|
+
return
|
24
|
+
}
|
25
|
+
|
26
|
+
const navigation = ref.current
|
27
|
+
|
28
|
+
if (navigation) {
|
29
|
+
const title = formatter(navigation.getCurrentOptions(), navigation.getCurrentRoute())
|
30
|
+
|
31
|
+
document.title = title
|
32
|
+
}
|
33
|
+
|
34
|
+
return navigation?.addListener('options', (e) => {
|
35
|
+
const title = formatter(e.data.options, navigation?.getCurrentRoute())
|
36
|
+
|
37
|
+
document.title = title
|
38
|
+
})
|
39
|
+
})
|
40
|
+
}
|
@@ -7,6 +7,7 @@ import {
|
|
7
7
|
type ParamListBase,
|
8
8
|
getActionFromState as getActionFromStateDefault,
|
9
9
|
getStateFromPath as getStateFromPathDefault,
|
10
|
+
useNavigationIndependentTree,
|
10
11
|
} from '@react-navigation/core'
|
11
12
|
import type { LinkingOptions } from '@react-navigation/native'
|
12
13
|
import * as React from 'react'
|
@@ -51,55 +52,52 @@ export default function useLinking(
|
|
51
52
|
getActionFromState = getActionFromStateDefault,
|
52
53
|
}: Options
|
53
54
|
) {
|
54
|
-
|
55
|
+
const independent = useNavigationIndependentTree()
|
55
56
|
|
56
|
-
React.useEffect(
|
57
|
-
()
|
58
|
-
|
59
|
-
|
60
|
-
}
|
57
|
+
React.useEffect(() => {
|
58
|
+
if (process.env.NODE_ENV === 'production') {
|
59
|
+
return undefined
|
60
|
+
}
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
if (
|
67
|
-
// enabled !== false &&
|
68
|
-
linkingHandlers.length
|
69
|
-
) {
|
70
|
-
console.error(
|
71
|
-
[
|
72
|
-
'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:',
|
73
|
-
"- You don't have multiple NavigationContainers in the app each with 'linking' enabled",
|
74
|
-
'- Only a single instance of the root component is rendered',
|
75
|
-
Platform.OS === 'android'
|
76
|
-
? "- You have set 'android:launchMode=singleTask' in the '<activity />' section of the 'AndroidManifest.xml' file to avoid launching multiple instances"
|
77
|
-
: '',
|
78
|
-
]
|
79
|
-
.join('\n')
|
80
|
-
.trim()
|
81
|
-
)
|
82
|
-
}
|
62
|
+
if (independent) {
|
63
|
+
return
|
64
|
+
}
|
83
65
|
|
84
|
-
|
66
|
+
if (
|
67
|
+
// enabled !== false &&
|
68
|
+
linkingHandlers.length
|
69
|
+
) {
|
70
|
+
console.error(
|
71
|
+
[
|
72
|
+
'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:',
|
73
|
+
"- You don't have multiple NavigationContainers in the app each with 'linking' enabled",
|
74
|
+
'- Only a single instance of the root component is rendered',
|
75
|
+
Platform.OS === 'android'
|
76
|
+
? "- You have set 'android:launchMode=singleTask' in the '<activity />' section of the 'AndroidManifest.xml' file to avoid launching multiple instances"
|
77
|
+
: '',
|
78
|
+
]
|
79
|
+
.join('\n')
|
80
|
+
.trim()
|
81
|
+
)
|
82
|
+
}
|
85
83
|
|
86
|
-
|
87
|
-
linkingHandlers.push(handler)
|
88
|
-
// }
|
84
|
+
const handler = Symbol()
|
89
85
|
|
90
|
-
|
91
|
-
|
86
|
+
// if (enabled !== false) {
|
87
|
+
linkingHandlers.push(handler)
|
88
|
+
// }
|
92
89
|
|
93
|
-
|
94
|
-
|
95
|
-
|
90
|
+
return () => {
|
91
|
+
const index = linkingHandlers.indexOf(handler)
|
92
|
+
|
93
|
+
if (index > -1) {
|
94
|
+
linkingHandlers.splice(index, 1)
|
96
95
|
}
|
97
|
-
}
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
)
|
96
|
+
}
|
97
|
+
}, [
|
98
|
+
// enabled,
|
99
|
+
independent,
|
100
|
+
])
|
103
101
|
|
104
102
|
// We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners
|
105
103
|
// This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`
|
package/src/fork/useLinking.ts
CHANGED
@@ -7,6 +7,7 @@ import {
|
|
7
7
|
getActionFromState as getActionFromStateDefault,
|
8
8
|
getPathFromState as getPathFromStateDefault,
|
9
9
|
getStateFromPath as getStateFromPathDefault,
|
10
|
+
useNavigationIndependentTree,
|
10
11
|
type NavigationContainerRef,
|
11
12
|
type NavigationState,
|
12
13
|
type ParamListBase,
|
@@ -88,14 +89,11 @@ export const series = (cb: () => Promise<void>) => {
|
|
88
89
|
|
89
90
|
let linkingHandlers: Symbol[] = []
|
90
91
|
|
91
|
-
type Options = LinkingOptions<ParamListBase>
|
92
|
-
independent?: boolean
|
93
|
-
}
|
92
|
+
type Options = LinkingOptions<ParamListBase>
|
94
93
|
|
95
94
|
export default function useLinking(
|
96
95
|
ref: React.RefObject<NavigationContainerRef<ParamListBase>>,
|
97
96
|
{
|
98
|
-
independent,
|
99
97
|
enabled = true,
|
100
98
|
config,
|
101
99
|
getStateFromPath = getStateFromPathDefault,
|
@@ -103,6 +101,8 @@ export default function useLinking(
|
|
103
101
|
getActionFromState = getActionFromStateDefault,
|
104
102
|
}: Options
|
105
103
|
) {
|
104
|
+
const independent = useNavigationIndependentTree()
|
105
|
+
|
106
106
|
React.useEffect(() => {
|
107
107
|
if (process.env.NODE_ENV === 'production') {
|
108
108
|
return undefined
|
@@ -0,0 +1,43 @@
|
|
1
|
+
// No change just vendored to avoid import issue with RR7
|
2
|
+
import * as React from 'react'
|
3
|
+
|
4
|
+
export function useThenable<T>(create: () => PromiseLike<T>) {
|
5
|
+
const [promise] = React.useState(create)
|
6
|
+
|
7
|
+
let initialState: [boolean, T | undefined] = [false, undefined]
|
8
|
+
|
9
|
+
// Check if our thenable is synchronous
|
10
|
+
// eslint-disable-next-line promise/catch-or-return, promise/always-return
|
11
|
+
promise.then((result) => {
|
12
|
+
initialState = [true, result]
|
13
|
+
})
|
14
|
+
|
15
|
+
const [state, setState] = React.useState(initialState)
|
16
|
+
const [resolved] = state
|
17
|
+
|
18
|
+
React.useEffect(() => {
|
19
|
+
let cancelled = false
|
20
|
+
|
21
|
+
const resolve = async () => {
|
22
|
+
let result
|
23
|
+
|
24
|
+
try {
|
25
|
+
result = await promise
|
26
|
+
} finally {
|
27
|
+
if (!cancelled) {
|
28
|
+
setState([true, result])
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
if (!resolved) {
|
34
|
+
resolve()
|
35
|
+
}
|
36
|
+
|
37
|
+
return () => {
|
38
|
+
cancelled = true
|
39
|
+
}
|
40
|
+
}, [promise, resolved])
|
41
|
+
|
42
|
+
return state
|
43
|
+
}
|
package/src/interfaces/router.ts
CHANGED
@@ -4,7 +4,7 @@ import type {
|
|
4
4
|
PartialState,
|
5
5
|
} from '@react-navigation/core'
|
6
6
|
import type { ReactNode } from 'react'
|
7
|
-
import type { TextProps, GestureResponderEvent } from 'react-native'
|
7
|
+
import type { TextProps, GestureResponderEvent, PressableProps } from 'react-native'
|
8
8
|
|
9
9
|
export namespace OneRouter {
|
10
10
|
export interface __routes<T extends string = string> extends Record<string, unknown> {}
|
@@ -305,7 +305,8 @@ export namespace OneRouter {
|
|
305
305
|
}
|
306
306
|
|
307
307
|
export interface LinkProps<T extends string | object>
|
308
|
-
extends Omit<TextProps, 'href'>,
|
308
|
+
extends Omit<TextProps, 'href' | 'disabled' | 'onLongPress' | 'onPressIn' | 'onPressOut'>,
|
309
|
+
Pick<PressableProps, 'disabled' | 'onLongPress' | 'onPressIn' | 'onPressOut'>,
|
309
310
|
WebAnchorProps {
|
310
311
|
/** Path to route to. */
|
311
312
|
href: Href<T>
|
package/src/layouts/Drawer.tsx
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import {
|
2
|
-
type DrawerNavigationEventMap,
|
3
|
-
type DrawerNavigationOptions,
|
4
2
|
createDrawerNavigator,
|
3
|
+
type DrawerNavigationOptions,
|
4
|
+
type DrawerNavigationEventMap,
|
5
5
|
} from '@react-navigation/drawer'
|
6
6
|
import type { DrawerNavigationState, ParamListBase } from '@react-navigation/native'
|
7
7
|
|
package/src/layouts/Tabs.tsx
CHANGED
@@ -2,6 +2,8 @@ import {
|
|
2
2
|
createBottomTabNavigator,
|
3
3
|
type BottomTabNavigationEventMap,
|
4
4
|
type BottomTabNavigationOptions,
|
5
|
+
BottomTabBar,
|
6
|
+
type BottomTabBarProps,
|
5
7
|
} from '@react-navigation/bottom-tabs'
|
6
8
|
import type { ParamListBase, TabNavigationState } from '@react-navigation/native'
|
7
9
|
import { Platform, Pressable } from 'react-native'
|
@@ -10,11 +12,34 @@ import type { OneRouter } from '../interfaces/router'
|
|
10
12
|
import { Link } from '../link/Link'
|
11
13
|
import { withLayoutContext } from './withLayoutContext'
|
12
14
|
|
15
|
+
const TabBar = ({ state, ...restProps }: BottomTabBarProps) => {
|
16
|
+
/**
|
17
|
+
* With React Navigation v7, spacial routes such as +not-found and _sitemap are being added to `state.routes`, but we don't want them to be shown in the tab bar.
|
18
|
+
*/
|
19
|
+
const filteredRoutes = state.routes.filter(
|
20
|
+
(r) => r.name !== '+not-found' && !r.name.startsWith('_sitemap')
|
21
|
+
)
|
22
|
+
|
23
|
+
return (
|
24
|
+
<BottomTabBar
|
25
|
+
state={{
|
26
|
+
...state,
|
27
|
+
routes: filteredRoutes,
|
28
|
+
}}
|
29
|
+
{...restProps}
|
30
|
+
/>
|
31
|
+
)
|
32
|
+
}
|
33
|
+
|
13
34
|
// This is the only way to access the navigator.
|
14
35
|
const BottomTabNavigator = createBottomTabNavigator().Navigator
|
15
36
|
|
37
|
+
type BottomTabNavigationOptionsWithHref = BottomTabNavigationOptions & {
|
38
|
+
href?: OneRouter.Href | null
|
39
|
+
}
|
40
|
+
|
16
41
|
export const Tabs = withLayoutContext<
|
17
|
-
|
42
|
+
BottomTabNavigationOptionsWithHref,
|
18
43
|
typeof BottomTabNavigator,
|
19
44
|
TabNavigationState<ParamListBase>,
|
20
45
|
BottomTabNavigationEventMap
|
@@ -52,6 +77,6 @@ export const Tabs = withLayoutContext<
|
|
52
77
|
}
|
53
78
|
return screen
|
54
79
|
})
|
55
|
-
})
|
80
|
+
}, { props: { tabBar: TabBar } })
|
56
81
|
|
57
82
|
export default Tabs
|
@@ -71,7 +71,8 @@ export function withLayoutContext<
|
|
71
71
|
Nav: T,
|
72
72
|
processor?: (
|
73
73
|
options: ScreenProps<TOptions, State, EventMap>[]
|
74
|
-
) => ScreenProps<TOptions, State, EventMap>[]
|
74
|
+
) => ScreenProps<TOptions, State, EventMap>[],
|
75
|
+
options?: { props: any }
|
75
76
|
): React.ForwardRefExoticComponent<
|
76
77
|
React.PropsWithoutRef<PickPartial<React.ComponentProps<T>, 'children'>> &
|
77
78
|
React.RefAttributes<unknown>
|
@@ -96,8 +97,7 @@ export function withLayoutContext<
|
|
96
97
|
}
|
97
98
|
|
98
99
|
return (
|
99
|
-
|
100
|
-
<Nav {...props} id={contextKey} ref={ref}>
|
100
|
+
<Nav {...props} {...options?.props} id={contextKey} ref={ref}>
|
101
101
|
{sorted}
|
102
102
|
</Nav>
|
103
103
|
)
|
package/src/setup.ts
CHANGED
@@ -2,18 +2,10 @@
|
|
2
2
|
import { scan } from 'react-scan'
|
3
3
|
|
4
4
|
if (process.env.ONE_ENABLE_REACT_SCAN) {
|
5
|
-
|
6
|
-
scan(
|
7
|
-
val === true
|
8
|
-
? {
|
9
|
-
enabled: true,
|
10
|
-
showToolbar: false,
|
11
|
-
}
|
12
|
-
: val
|
13
|
-
)
|
5
|
+
scan(JSON.parse(process.env.ONE_ENABLE_REACT_SCAN))
|
14
6
|
}
|
15
7
|
|
16
8
|
// fixes bad import error in expo-modules-core
|
17
9
|
// without this you run into error loading web immediately
|
18
10
|
// where globalThis.expo is not defined
|
19
|
-
import 'expo-modules-core/
|
11
|
+
import 'expo-modules-core/src/web/index.web.ts'
|
package/src/vite/build.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import * as constants from '../constants'
|
2
1
|
import FSExtra from 'fs-extra'
|
3
2
|
import MicroMatch from 'micromatch'
|
4
3
|
import { createRequire } from 'node:module'
|
@@ -15,10 +14,11 @@ import {
|
|
15
14
|
} from 'vxrn'
|
16
15
|
import { getLoaderPath, getPreloadPath } from '../cleanUrl'
|
17
16
|
import { labelProcess } from '../cli/label-process'
|
17
|
+
import * as constants from '../constants'
|
18
18
|
import type { RouteInfo } from '../server/createRoutesManifest'
|
19
19
|
import type { LoaderProps, RenderApp } from '../types'
|
20
20
|
import { getManifest } from './getManifest'
|
21
|
-
import { loadUserOneOptions } from './
|
21
|
+
import { loadUserOneOptions } from './loadConfig'
|
22
22
|
import { replaceLoader } from './replaceLoader'
|
23
23
|
import type { One } from './types'
|
24
24
|
|
@@ -527,7 +527,7 @@ ${JSON.stringify(params || null, null, 2)}`
|
|
527
527
|
await FSExtra.writeFile(
|
528
528
|
join(options.root, 'dist', 'index.js'),
|
529
529
|
`import { serve } from 'one/serve'
|
530
|
-
const handler = await serve()
|
530
|
+
export const handler = await serve()
|
531
531
|
export const { GET, POST, PUT, PATCH, OPTIONS } = handler`
|
532
532
|
)
|
533
533
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { loadConfigFromFile } from 'vite'
|
2
|
+
import '../polyfills-server'
|
3
|
+
import type { One } from './types'
|
4
|
+
|
5
|
+
// globalThis, otherwise we get issues with duplicates due to however vite calls loadConfigFromFile
|
6
|
+
|
7
|
+
export function setOneOptions(next: One.PluginOptions) {
|
8
|
+
globalThis.__oneOptions = next
|
9
|
+
}
|
10
|
+
|
11
|
+
async function getUserOneOptions(command?: 'serve' | 'build') {
|
12
|
+
if (!globalThis.__oneOptions) {
|
13
|
+
throw new Error(`One not loaded properly, is the one() plugin in your vite.config.ts?`)
|
14
|
+
}
|
15
|
+
return globalThis.__oneOptions
|
16
|
+
}
|
17
|
+
|
18
|
+
export async function loadUserOneOptions(command: 'serve' | 'build') {
|
19
|
+
const found = await loadConfigFromFile({
|
20
|
+
mode: 'prod',
|
21
|
+
command,
|
22
|
+
})
|
23
|
+
if (!found) {
|
24
|
+
throw new Error(`No config found in ${process.cwd()}. Is this the correct directory?`)
|
25
|
+
}
|
26
|
+
const foundOptions = getUserOneOptions(command)
|
27
|
+
if (!foundOptions) {
|
28
|
+
throw new Error(`No One plugin found in this vite.config`)
|
29
|
+
}
|
30
|
+
return foundOptions
|
31
|
+
}
|
package/src/vite/one.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { resolvePath } from '@vxrn/resolve'
|
2
2
|
import events from 'node:events'
|
3
3
|
import path, { dirname, resolve } from 'node:path'
|
4
|
-
import {
|
4
|
+
import type { Plugin, PluginOption, UserConfig } from 'vite'
|
5
5
|
import tsconfigPaths from 'vite-tsconfig-paths'
|
6
6
|
import {
|
7
7
|
autoPreBundleDepsForSsrPlugin,
|
@@ -14,6 +14,7 @@ import { CACHE_KEY } from '../constants'
|
|
14
14
|
import '../polyfills-server'
|
15
15
|
import { existsAsync } from '../utils/existsAsync'
|
16
16
|
import { ensureTSConfig } from './ensureTsConfig'
|
17
|
+
import { setOneOptions } from './loadConfig'
|
17
18
|
import { clientTreeShakePlugin } from './plugins/clientTreeShakePlugin'
|
18
19
|
import { createFileSystemRouterPlugin } from './plugins/fileSystemRouterPlugin'
|
19
20
|
import { fixDependenciesPlugin } from './plugins/fixDependenciesPlugin'
|
@@ -22,6 +23,14 @@ import { createReactCompilerPlugin } from './plugins/reactCompilerPlugin'
|
|
22
23
|
import { SSRCSSPlugin } from './plugins/SSRCSSPlugin'
|
23
24
|
import { createVirtualEntry, virtualEntryId } from './plugins/virtualEntryPlugin'
|
24
25
|
import type { One } from './types'
|
26
|
+
// import { barrel } from 'vite-plugin-barrel'
|
27
|
+
|
28
|
+
/**
|
29
|
+
* This needs a big refactor!
|
30
|
+
* I guess these plugins are all being loaded by native??
|
31
|
+
* At least the react compiler plugin is applying to native, so the entire premise of some things
|
32
|
+
* here are wrong. we can probably refactor and merge all the stuff
|
33
|
+
*/
|
25
34
|
|
26
35
|
events.setMaxListeners(1_000)
|
27
36
|
|
@@ -29,7 +38,7 @@ events.setMaxListeners(1_000)
|
|
29
38
|
globalThis.__vxrnEnableNativeEnv = true
|
30
39
|
|
31
40
|
export function one(options: One.PluginOptions = {}): PluginOption {
|
32
|
-
|
41
|
+
setOneOptions(options)
|
33
42
|
|
34
43
|
// ensure tsconfig
|
35
44
|
if (options.config?.ensureTSConfig !== false) {
|
@@ -59,6 +68,14 @@ export function one(options: One.PluginOptions = {}): PluginOption {
|
|
59
68
|
__get: options,
|
60
69
|
},
|
61
70
|
|
71
|
+
// stopped working on new version
|
72
|
+
// barrel({
|
73
|
+
// packages: ['@tamagui/lucide-icons', '@mui/material', '@mui/icons-material'],
|
74
|
+
// // experimental: {
|
75
|
+
// // integration: 'plugin-react-swc',
|
76
|
+
// // },
|
77
|
+
// }) as any,
|
78
|
+
|
62
79
|
{
|
63
80
|
name: 'one-define-env',
|
64
81
|
async config() {
|
@@ -178,6 +195,7 @@ export function one(options: One.PluginOptions = {}): PluginOption {
|
|
178
195
|
define: {
|
179
196
|
'process.env.VITE_ENVIRONMENT': '"client"',
|
180
197
|
'import.meta.env.VITE_ENVIRONMENT': '"client"',
|
198
|
+
'process.env.EXPO_OS': '"web"',
|
181
199
|
},
|
182
200
|
},
|
183
201
|
|
@@ -185,6 +203,7 @@ export function one(options: One.PluginOptions = {}): PluginOption {
|
|
185
203
|
define: {
|
186
204
|
'process.env.VITE_ENVIRONMENT': '"ssr"',
|
187
205
|
'import.meta.env.VITE_ENVIRONMENT': '"ssr"',
|
206
|
+
'process.env.EXPO_OS': '"web"',
|
188
207
|
},
|
189
208
|
},
|
190
209
|
|
@@ -192,6 +211,7 @@ export function one(options: One.PluginOptions = {}): PluginOption {
|
|
192
211
|
define: {
|
193
212
|
'process.env.VITE_ENVIRONMENT': '"ios"',
|
194
213
|
'import.meta.env.VITE_ENVIRONMENT': '"ios"',
|
214
|
+
'process.env.EXPO_OS': '"ios"',
|
195
215
|
},
|
196
216
|
},
|
197
217
|
|
@@ -199,6 +219,7 @@ export function one(options: One.PluginOptions = {}): PluginOption {
|
|
199
219
|
define: {
|
200
220
|
'process.env.VITE_ENVIRONMENT': '"android"',
|
201
221
|
'import.meta.env.VITE_ENVIRONMENT': '"android"',
|
222
|
+
'process.env.EXPO_OS': '"android"',
|
202
223
|
},
|
203
224
|
},
|
204
225
|
},
|
@@ -249,30 +270,85 @@ export function one(options: One.PluginOptions = {}): PluginOption {
|
|
249
270
|
// react scan
|
250
271
|
const scan = options.react?.scan
|
251
272
|
|
252
|
-
//
|
253
|
-
|
254
|
-
|
273
|
+
// do it here because it gets called a few times
|
274
|
+
const reactScanConfig = ((): UserConfig => {
|
275
|
+
const stringify = (obj: Object) => JSON.stringify(JSON.stringify(obj))
|
255
276
|
|
256
|
-
|
257
|
-
|
277
|
+
const configs = {
|
278
|
+
disabled: {
|
279
|
+
define: {
|
280
|
+
'process.env.ONE_ENABLE_REACT_SCAN': 'false',
|
281
|
+
},
|
282
|
+
},
|
283
|
+
enabled: {
|
284
|
+
define: {
|
285
|
+
'process.env.ONE_ENABLE_REACT_SCAN': stringify({
|
286
|
+
enabled: true,
|
287
|
+
animationSpeed: 'slow',
|
288
|
+
showToolbar: false,
|
289
|
+
}),
|
290
|
+
},
|
291
|
+
},
|
292
|
+
} satisfies Record<string, UserConfig>
|
293
|
+
|
294
|
+
const getConfigFor = (platform: 'ios' | 'android' | 'client'): UserConfig => {
|
295
|
+
if (!scan) {
|
296
|
+
return configs.disabled
|
297
|
+
}
|
298
|
+
if (scan === true) {
|
299
|
+
return configs.enabled
|
300
|
+
}
|
301
|
+
if (typeof scan === 'string') {
|
302
|
+
if (scan === 'native' && platform === 'client') {
|
303
|
+
return configs.disabled
|
304
|
+
}
|
305
|
+
if (scan === 'web' && platform !== 'client') {
|
306
|
+
return configs.disabled
|
307
|
+
}
|
308
|
+
return configs.enabled
|
309
|
+
}
|
258
310
|
|
311
|
+
const defaultConfig = scan.options || configs.enabled
|
312
|
+
const perPlatformConfig =
|
313
|
+
platform === 'ios' || platform === 'android' ? scan.native : scan.web
|
314
|
+
|
315
|
+
return {
|
316
|
+
define: {
|
317
|
+
'process.env.ONE_ENABLE_REACT_SCAN': stringify({
|
318
|
+
...defaultConfig,
|
319
|
+
...perPlatformConfig,
|
320
|
+
}),
|
321
|
+
},
|
322
|
+
}
|
323
|
+
}
|
324
|
+
|
325
|
+
return {
|
326
|
+
environments: {
|
327
|
+
client: getConfigFor('client'),
|
328
|
+
ios: getConfigFor('ios'),
|
329
|
+
android: getConfigFor('android'),
|
330
|
+
},
|
331
|
+
}
|
332
|
+
})()
|
333
|
+
|
334
|
+
// TODO move to single config and through environments
|
335
|
+
const nativeWebDevAndProdPlugsin: Plugin[] = [
|
336
|
+
clientTreeShakePlugin(),
|
259
337
|
{
|
260
338
|
name: `one:react-scan`,
|
261
339
|
config() {
|
262
|
-
return
|
263
|
-
environments: {
|
264
|
-
// only in client
|
265
|
-
client: {
|
266
|
-
define: {
|
267
|
-
'process.env.ONE_ENABLE_REACT_SCAN': JSON.stringify(
|
268
|
-
typeof scan === 'boolean' ? `${scan}` : scan
|
269
|
-
),
|
270
|
-
},
|
271
|
-
},
|
272
|
-
},
|
273
|
-
}
|
340
|
+
return reactScanConfig
|
274
341
|
},
|
275
342
|
},
|
343
|
+
]
|
344
|
+
|
345
|
+
// TODO make this passed into vxrn through real API
|
346
|
+
globalThis.__vxrnAddNativePlugins = nativeWebDevAndProdPlugsin
|
347
|
+
globalThis.__vxrnAddWebPluginsProd = devAndProdPlugins
|
348
|
+
|
349
|
+
return [
|
350
|
+
...devAndProdPlugins,
|
351
|
+
...nativeWebDevAndProdPlugsin,
|
276
352
|
|
277
353
|
/**
|
278
354
|
* This is really the meat of one, where it handles requests:
|
@@ -281,8 +357,6 @@ export function one(options: One.PluginOptions = {}): PluginOption {
|
|
281
357
|
|
282
358
|
generateFileSystemRouteTypesPlugin(options),
|
283
359
|
|
284
|
-
clientTreeShakePlugin(),
|
285
|
-
|
286
360
|
fixDependenciesPlugin(options.deps),
|
287
361
|
|
288
362
|
createVirtualEntry({
|
@@ -370,31 +444,3 @@ export function one(options: One.PluginOptions = {}): PluginOption {
|
|
370
444
|
}),
|
371
445
|
]
|
372
446
|
}
|
373
|
-
|
374
|
-
let oneOptions: One.PluginOptions | null = null
|
375
|
-
|
376
|
-
async function getUserOneOptions(command?: 'serve' | 'build') {
|
377
|
-
if (!oneOptions) {
|
378
|
-
if (!command) throw new Error(`Options not loaded and no command given`)
|
379
|
-
await loadUserOneOptions(command)
|
380
|
-
}
|
381
|
-
if (!oneOptions) {
|
382
|
-
throw new Error(`No One options were loaded`)
|
383
|
-
}
|
384
|
-
return oneOptions
|
385
|
-
}
|
386
|
-
|
387
|
-
export async function loadUserOneOptions(command: 'serve' | 'build') {
|
388
|
-
const found = await loadConfigFromFile({
|
389
|
-
mode: 'prod',
|
390
|
-
command,
|
391
|
-
})
|
392
|
-
if (!found) {
|
393
|
-
throw new Error(`No config found in ${process.cwd()}. Is this the correct directory?`)
|
394
|
-
}
|
395
|
-
const foundOptions = getUserOneOptions()
|
396
|
-
if (!foundOptions) {
|
397
|
-
throw new Error(`No One plugin found in this vite.config`)
|
398
|
-
}
|
399
|
-
return foundOptions
|
400
|
-
}
|
@@ -352,7 +352,10 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
|
|
352
352
|
|
353
353
|
if (reply.body) {
|
354
354
|
if (reply.body.locked) {
|
355
|
-
console.warn(`Body is locked
|
355
|
+
console.warn(`Body is locked??`, req.url)
|
356
|
+
res.write(``)
|
357
|
+
res.end()
|
358
|
+
return
|
356
359
|
}
|
357
360
|
}
|
358
361
|
|
@@ -3,12 +3,12 @@ import { relative } from 'node:path'
|
|
3
3
|
import type { Plugin } from 'vite'
|
4
4
|
|
5
5
|
export const createReactCompilerPlugin = (root: string): Plugin => {
|
6
|
-
const
|
6
|
+
const getBabelConfig = (target: '18' | '19') => ({
|
7
7
|
babelrc: false,
|
8
8
|
configFile: false,
|
9
9
|
presets: ['@babel/preset-typescript'],
|
10
|
-
plugins: [['babel-plugin-react-compiler', { target
|
11
|
-
}
|
10
|
+
plugins: [['babel-plugin-react-compiler', { target }]],
|
11
|
+
})
|
12
12
|
|
13
13
|
const filter = /.*(.tsx?)$/
|
14
14
|
|
@@ -19,10 +19,17 @@ export const createReactCompilerPlugin = (root: string): Plugin => {
|
|
19
19
|
async transform(codeIn, id) {
|
20
20
|
const shouldTransform = filter.test(id)
|
21
21
|
if (!shouldTransform) return
|
22
|
-
const
|
22
|
+
const env = this.environment.name
|
23
|
+
const target = env === 'ios' || env === 'android' ? '18' : '19'
|
24
|
+
|
25
|
+
if (codeIn.startsWith('// disable-compiler')) {
|
26
|
+
return
|
27
|
+
}
|
28
|
+
|
29
|
+
const result = await babel.transformAsync(codeIn, { filename: id, ...getBabelConfig(target) })
|
23
30
|
const code = result?.code ?? ''
|
24
31
|
|
25
|
-
if (code.includes(`react/compiler-runtime`)) {
|
32
|
+
if (code.includes(target === '18' ? `react-compiler-runtime` : `react/compiler-runtime`)) {
|
26
33
|
console.info(` 🪄 ${relative(root, id)}`)
|
27
34
|
}
|
28
35
|
|