expo-router 3.4.7 → 3.4.8
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/build/global-state/router-store.d.ts +3 -0
- package/build/global-state/router-store.d.ts.map +1 -1
- package/build/global-state/router-store.js +3 -0
- package/build/global-state/router-store.js.map +1 -1
- package/build/global-state/routing.d.ts +3 -0
- package/build/global-state/routing.d.ts.map +1 -1
- package/build/global-state/routing.js +24 -1
- package/build/global-state/routing.js.map +1 -1
- package/build/hooks.d.ts.map +1 -1
- package/build/hooks.js +3 -0
- package/build/hooks.js.map +1 -1
- package/build/imperative-api.d.ts.map +1 -1
- package/build/imperative-api.js +3 -0
- package/build/imperative-api.js.map +1 -1
- package/build/testing-library/context-stubs.d.ts +1 -1
- package/build/testing-library/context-stubs.d.ts.map +1 -1
- package/build/testing-library/context-stubs.js +7 -2
- package/build/testing-library/context-stubs.js.map +1 -1
- package/build/testing-library/index.d.ts +8 -4
- package/build/testing-library/index.d.ts.map +1 -1
- package/build/testing-library/index.js +23 -12
- package/build/testing-library/index.js.map +1 -1
- package/build/testing-library/mocks.d.ts +0 -1
- package/build/testing-library/mocks.d.ts.map +1 -1
- package/build/testing-library/mocks.js +7 -1
- package/build/testing-library/mocks.js.map +1 -1
- package/build/types.d.ts +7 -1
- package/build/types.d.ts.map +1 -1
- package/build/types.js.map +1 -1
- package/package.json +2 -2
- package/build/utils/mockState.d.ts +0 -7
- package/build/utils/mockState.d.ts.map +0 -1
- package/build/utils/mockState.js +0 -29
- package/build/utils/mockState.js.map +0 -1
|
@@ -28,7 +28,10 @@ export declare class RouterStore {
|
|
|
28
28
|
goBack: any;
|
|
29
29
|
canGoBack: any;
|
|
30
30
|
push: any;
|
|
31
|
+
dismiss: any;
|
|
31
32
|
replace: any;
|
|
33
|
+
dismissAll: any;
|
|
34
|
+
canDismiss: any;
|
|
32
35
|
setParams: any;
|
|
33
36
|
navigate: any;
|
|
34
37
|
initialize(context: RequireContext, navigationRef: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>, initialLocation?: URL): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-store.d.ts","sourceRoot":"","sources":["../../src/global-state/router-store.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EAGlC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAiC,aAAa,EAAY,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"router-store.d.ts","sourceRoot":"","sources":["../../src/global-state/router-store.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EAGlC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAiC,aAAa,EAAY,MAAM,OAAO,CAAC;AAe/E,OAAO,EAAE,SAAS,EAAyB,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAoB,MAAM,qBAAqB,CAAC;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C;;;;GAIG;AACH,qBAAa,WAAW;IACtB,SAAS,EAAG,SAAS,GAAG,IAAI,CAAC;IAC7B,aAAa,EAAG,aAAa,CAAC;IAC9B,OAAO,EAAE,kBAAkB,GAAG,SAAS,CAAC;IACxC,OAAO,CAAC,wBAAwB,CAAkB;IAElD,YAAY,EAAE,WAAW,GAAG,SAAS,CAAC;IACtC,SAAS,EAAE,WAAW,GAAG,SAAS,CAAC;IACnC,SAAS,EAAE,WAAW,GAAG,SAAS,CAAC;IACnC,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAElC,aAAa,EAAG,iCAAiC,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;IACjF,yBAAyB,EAAG,MAAM,IAAI,CAAC;IAEvC,oBAAoB,YAAiB,IAAI,EAAI;IAC7C,gBAAgB,YAAiB,IAAI,EAAI;IAEzC,MAAM,MAAqB;IAC3B,eAAe,MAA8B;IAC7C,MAAM,MAAqB;IAC3B,SAAS,MAAwB;IACjC,IAAI,MAAmB;IACvB,OAAO,MAAsB;IAC7B,OAAO,MAAsB;IAC7B,UAAU,MAAyB;IACnC,UAAU,MAAyB;IACnC,SAAS,MAAwB;IACjC,QAAQ,MAAuB;IAE/B,UAAU,CACR,OAAO,EAAE,cAAc,EACvB,aAAa,EAAE,iCAAiC,CAAC,eAAe,CAAC,aAAa,CAAC,EAC/E,eAAe,CAAC,EAAE,GAAG;IAiGvB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,cAAQ;IAWjD,YAAY,CAAC,KAAK,EAAE,WAAW;IAgB/B,kBAAkB;IAIlB,uEAAuE;IACvE,oBAAoB,eAAgB,MAAM,IAAI,mBAG5C;IACF,gBAAgB,eAAgB,MAAM,IAAI,mBAGxC;IACF,QAAQ,aAEN;IACF,iBAAiB,oBAEf;IACF,iBAAiB,kBAEf;CACH;AAED,eAAO,MAAM,KAAK,aAAoB,CAAC;AAEvC,wBAAgB,aAAa,gBAE5B;AAYD,wBAAgB,iBAAiB,gBAOhC;AAED,wBAAgB,iBAAiB,cAOhC;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,GAAG,GAAG,SAAS,eAQhG"}
|
|
@@ -57,7 +57,10 @@ class RouterStore {
|
|
|
57
57
|
goBack = routing_1.goBack.bind(this);
|
|
58
58
|
canGoBack = routing_1.canGoBack.bind(this);
|
|
59
59
|
push = routing_1.push.bind(this);
|
|
60
|
+
dismiss = routing_1.dismiss.bind(this);
|
|
60
61
|
replace = routing_1.replace.bind(this);
|
|
62
|
+
dismissAll = routing_1.dismissAll.bind(this);
|
|
63
|
+
canDismiss = routing_1.canDismiss.bind(this);
|
|
61
64
|
setParams = routing_1.setParams.bind(this);
|
|
62
65
|
navigate = routing_1.navigate.bind(this);
|
|
63
66
|
initialize(context, navigationRef,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EAAE,eAAgC;IAC/F,MAAM,aAAa,GAAG,IAAA,kCAAyB,GAAE,CAAC;IAClD,IAAA,eAAO,EACL,GAAG,EAAE,CAAC,aAAK,CAAC,UAAU,CAAC,OAAO,EAAE,aAAa,EAAE,eAAe,CAAC,EAC/D,CAAC,OAAO,EAAE,eAAe,CAAC,CAC3B,CAAC;IACF,aAAa,EAAE,CAAC;IAChB,OAAO,aAAK,CAAC;AACf,CAAC;AARD,0DAQC","sourcesContent":["import {\n NavigationContainerRefWithCurrent,\n getPathFromState,\n useNavigationContainerRef,\n} from '@react-navigation/native';\nimport * as SplashScreen from 'expo-splash-screen';\nimport { useSyncExternalStore, useMemo, ComponentType, Fragment } from 'react';\n\nimport { canGoBack, goBack, linkTo, navigate, push, replace, setParams } from './routing';\nimport { getSortedRoutes } from './sort-routes';\nimport { UrlObject, getRouteInfoFromState } from '../LocationProvider';\nimport { RouteNode } from '../Route';\nimport { deepEqual, getPathDataFromState } from '../fork/getPathFromState';\nimport { ResultState } from '../fork/getStateFromPath';\nimport { ExpoLinkingOptions, getLinkingConfig } from '../getLinkingConfig';\nimport { getRoutes } from '../getRoutes';\nimport { RequireContext } from '../types';\nimport { getQualifiedRouteComponent } from '../useScreens';\n\n/**\n * This is the global state for the router. It is used to keep track of the current route, and to provide a way to navigate to other routes.\n *\n * There should only be one instance of this class and be initialized via `useInitializeExpoRouter`\n */\nexport class RouterStore {\n routeNode!: RouteNode | null;\n rootComponent!: ComponentType;\n linking: ExpoLinkingOptions | undefined;\n private hasAttemptedToHideSplash: boolean = false;\n\n initialState: ResultState | undefined;\n rootState: ResultState | undefined;\n nextState: ResultState | undefined;\n routeInfo?: UrlObject | undefined;\n\n navigationRef!: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;\n navigationRefSubscription!: () => void;\n\n rootStateSubscribers = new Set<() => void>();\n storeSubscribers = new Set<() => void>();\n\n linkTo = linkTo.bind(this);\n getSortedRoutes = getSortedRoutes.bind(this);\n goBack = goBack.bind(this);\n canGoBack = canGoBack.bind(this);\n push = push.bind(this);\n replace = replace.bind(this);\n setParams = setParams.bind(this);\n navigate = navigate.bind(this);\n\n initialize(\n context: RequireContext,\n navigationRef: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>,\n initialLocation?: URL\n ) {\n // Clean up any previous state\n this.initialState = undefined;\n this.rootState = undefined;\n this.nextState = undefined;\n this.routeInfo = undefined;\n this.linking = undefined;\n this.navigationRefSubscription?.();\n this.rootStateSubscribers.clear();\n this.storeSubscribers.clear();\n\n this.routeNode = getRoutes(context, { ignoreEntryPoints: true });\n\n this.rootComponent = this.routeNode ? getQualifiedRouteComponent(this.routeNode) : Fragment;\n\n // Only error in production, in development we will show the onboarding screen\n if (!this.routeNode && process.env.NODE_ENV === 'production') {\n throw new Error('No routes found');\n }\n\n this.navigationRef = navigationRef;\n\n if (this.routeNode) {\n this.linking = getLinkingConfig(this.routeNode!);\n\n if (initialLocation) {\n this.linking.getInitialURL = () => initialLocation.toString();\n this.initialState = this.linking.getStateFromPath?.(\n initialLocation.pathname + initialLocation.search,\n this.linking.config\n );\n }\n }\n\n // There is no routeNode, so we will be showing the onboarding screen\n // In the meantime, just mock the routeInfo\n if (this.initialState) {\n this.rootState = this.initialState;\n this.routeInfo = this.getRouteInfo(this.initialState);\n } else {\n this.routeInfo = {\n unstable_globalHref: '',\n pathname: '',\n isIndex: false,\n params: {},\n segments: [],\n };\n }\n\n /**\n * Counter intuitively - this fires AFTER both React Navigation's state changes and the subsequent paint.\n * This poses a couple of issues for Expo Router,\n * - Ensuring hooks (e.g. useSearchParams()) have data in the initial render\n * - Reacting to state changes after a navigation event\n *\n * This is why the initial render renders a Fragment and we wait until `onReady()` is called\n * Additionally, some hooks compare the state from both the store and the navigationRef. If the store it stale,\n * that hooks will manually update the store.\n *\n */\n this.navigationRefSubscription = navigationRef.addListener('state', (data) => {\n const state = data.data.state as ResultState;\n\n if (!this.hasAttemptedToHideSplash) {\n this.hasAttemptedToHideSplash = true;\n // NOTE(EvanBacon): `navigationRef.isReady` is sometimes not true when state is called initially.\n requestAnimationFrame(\n () =>\n // @ts-expect-error: This function is native-only and for internal-use only.\n SplashScreen._internal_maybeHideAsync?.()\n );\n }\n\n let shouldUpdateSubscribers = this.nextState === state;\n this.nextState = undefined;\n\n // This can sometimes be undefined when an error is thrown in the Root Layout Route.\n // Additionally that state may already equal the rootState if it was updated within a hook\n if (state && state !== this.rootState) {\n store.updateState(state, undefined);\n shouldUpdateSubscribers = true;\n }\n\n // If the state has changed, or was changed inside a hook we need to update the subscribers\n if (shouldUpdateSubscribers) {\n for (const subscriber of this.rootStateSubscribers) {\n subscriber();\n }\n }\n });\n\n for (const subscriber of this.storeSubscribers) {\n subscriber();\n }\n }\n\n updateState(state: ResultState, nextState = state) {\n store.rootState = state;\n store.nextState = nextState;\n\n const nextRouteInfo = store.getRouteInfo(state);\n\n if (!deepEqual(this.routeInfo, nextRouteInfo)) {\n store.routeInfo = nextRouteInfo;\n }\n }\n\n getRouteInfo(state: ResultState) {\n return getRouteInfoFromState(\n (state: Parameters<typeof getPathFromState>[0], asPath: boolean) => {\n return getPathDataFromState(state, {\n screens: [],\n ...this.linking?.config,\n preserveDynamicRoutes: asPath,\n preserveGroups: asPath,\n });\n },\n state\n );\n }\n\n // This is only used in development, to show the onboarding screen\n // In production we should have errored during the initialization\n shouldShowTutorial() {\n return !this.routeNode && process.env.NODE_ENV === 'development';\n }\n\n /** Make sure these are arrow functions so `this` is correctly bound */\n subscribeToRootState = (subscriber: () => void) => {\n this.rootStateSubscribers.add(subscriber);\n return () => this.rootStateSubscribers.delete(subscriber);\n };\n subscribeToStore = (subscriber: () => void) => {\n this.storeSubscribers.add(subscriber);\n return () => this.storeSubscribers.delete(subscriber);\n };\n snapshot = () => {\n return this;\n };\n rootStateSnapshot = () => {\n return this.rootState!;\n };\n routeInfoSnapshot = () => {\n return this.routeInfo!;\n };\n}\n\nexport const store = new RouterStore();\n\nexport function useExpoRouter() {\n return useSyncExternalStore(store.subscribeToStore, store.snapshot, store.snapshot);\n}\n\nfunction syncStoreRootState() {\n if (store.navigationRef.isReady()) {\n const currentState = store.navigationRef.getRootState() as unknown as ResultState;\n\n if (store.rootState !== currentState) {\n store.updateState(currentState);\n }\n }\n}\n\nexport function useStoreRootState() {\n syncStoreRootState();\n return useSyncExternalStore(\n store.subscribeToRootState,\n store.rootStateSnapshot,\n store.rootStateSnapshot\n );\n}\n\nexport function useStoreRouteInfo() {\n syncStoreRootState();\n return useSyncExternalStore(\n store.subscribeToRootState,\n store.routeInfoSnapshot,\n store.routeInfoSnapshot\n );\n}\n\nexport function useInitializeExpoRouter(context: RequireContext, initialLocation: URL | undefined) {\n const navigationRef = useNavigationContainerRef();\n useMemo(\n () => store.initialize(context, navigationRef, initialLocation),\n [context, initialLocation]\n );\n useExpoRouter();\n return store;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"router-store.js","sourceRoot":"","sources":["../../src/global-state/router-store.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAIkC;AAClC,iEAAmD;AACnD,iCAA+E;AAE/E,uCAWmB;AACnB,+CAAgD;AAChD,0DAAuE;AAEvE,+DAA2E;AAE3E,0DAA2E;AAC3E,4CAAyC;AAEzC,8CAA2D;AAE3D;;;;GAIG;AACH,MAAa,WAAW;IACtB,SAAS,CAAoB;IAC7B,aAAa,CAAiB;IAC9B,OAAO,CAAiC;IAChC,wBAAwB,GAAY,KAAK,CAAC;IAElD,YAAY,CAA0B;IACtC,SAAS,CAA0B;IACnC,SAAS,CAA0B;IACnC,SAAS,CAAyB;IAElC,aAAa,CAAoE;IACjF,yBAAyB,CAAc;IAEvC,oBAAoB,GAAG,IAAI,GAAG,EAAc,CAAC;IAC7C,gBAAgB,GAAG,IAAI,GAAG,EAAc,CAAC;IAEzC,MAAM,GAAG,gBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,eAAe,GAAG,6BAAe,CAAC,IAAI,CAAC,IAAI,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AED,SAAS,kBAAkB;IACzB,IAAI,aAAK,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE;QACjC,MAAM,YAAY,GAAG,aAAK,CAAC,aAAa,CAAC,YAAY,EAA4B,CAAC;QAElF,IAAI,aAAK,CAAC,SAAS,KAAK,YAAY,EAAE;YACpC,aAAK,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;SACjC;KACF;AACH,CAAC;AAED,SAAgB,iBAAiB;IAC/B,kBAAkB,EAAE,CAAC;IACrB,OAAO,IAAA,4BAAoB,EACzB,aAAK,CAAC,oBAAoB,EAC1B,aAAK,CAAC,iBAAiB,EACvB,aAAK,CAAC,iBAAiB,CACxB,CAAC;AACJ,CAAC;AAPD,8CAOC;AAED,SAAgB,iBAAiB;IAC/B,kBAAkB,EAAE,CAAC;IACrB,OAAO,IAAA,4BAAoB,EACzB,aAAK,CAAC,oBAAoB,EAC1B,aAAK,CAAC,iBAAiB,EACvB,aAAK,CAAC,iBAAiB,CACxB,CAAC;AACJ,CAAC;AAPD,8CAOC;AAED,SAAgB,uBAAuB,CAAC,OAAuB,EAAE,eAAgC;IAC/F,MAAM,aAAa,GAAG,IAAA,kCAAyB,GAAE,CAAC;IAClD,IAAA,eAAO,EACL,GAAG,EAAE,CAAC,aAAK,CAAC,UAAU,CAAC,OAAO,EAAE,aAAa,EAAE,eAAe,CAAC,EAC/D,CAAC,OAAO,EAAE,eAAe,CAAC,CAC3B,CAAC;IACF,aAAa,EAAE,CAAC;IAChB,OAAO,aAAK,CAAC;AACf,CAAC;AARD,0DAQC","sourcesContent":["import {\n NavigationContainerRefWithCurrent,\n getPathFromState,\n useNavigationContainerRef,\n} from '@react-navigation/native';\nimport * as SplashScreen from 'expo-splash-screen';\nimport { useSyncExternalStore, useMemo, ComponentType, Fragment } from 'react';\n\nimport {\n canGoBack,\n canDismiss,\n goBack,\n linkTo,\n navigate,\n dismiss,\n dismissAll,\n push,\n replace,\n setParams,\n} from './routing';\nimport { getSortedRoutes } from './sort-routes';\nimport { UrlObject, getRouteInfoFromState } from '../LocationProvider';\nimport { RouteNode } from '../Route';\nimport { deepEqual, getPathDataFromState } from '../fork/getPathFromState';\nimport { ResultState } from '../fork/getStateFromPath';\nimport { ExpoLinkingOptions, getLinkingConfig } from '../getLinkingConfig';\nimport { getRoutes } from '../getRoutes';\nimport { RequireContext } from '../types';\nimport { getQualifiedRouteComponent } from '../useScreens';\n\n/**\n * This is the global state for the router. It is used to keep track of the current route, and to provide a way to navigate to other routes.\n *\n * There should only be one instance of this class and be initialized via `useInitializeExpoRouter`\n */\nexport class RouterStore {\n routeNode!: RouteNode | null;\n rootComponent!: ComponentType;\n linking: ExpoLinkingOptions | undefined;\n private hasAttemptedToHideSplash: boolean = false;\n\n initialState: ResultState | undefined;\n rootState: ResultState | undefined;\n nextState: ResultState | undefined;\n routeInfo?: UrlObject | undefined;\n\n navigationRef!: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>;\n navigationRefSubscription!: () => void;\n\n rootStateSubscribers = new Set<() => void>();\n storeSubscribers = new Set<() => void>();\n\n linkTo = linkTo.bind(this);\n getSortedRoutes = getSortedRoutes.bind(this);\n goBack = goBack.bind(this);\n canGoBack = canGoBack.bind(this);\n push = push.bind(this);\n dismiss = dismiss.bind(this);\n replace = replace.bind(this);\n dismissAll = dismissAll.bind(this);\n canDismiss = canDismiss.bind(this);\n setParams = setParams.bind(this);\n navigate = navigate.bind(this);\n\n initialize(\n context: RequireContext,\n navigationRef: NavigationContainerRefWithCurrent<ReactNavigation.RootParamList>,\n initialLocation?: URL\n ) {\n // Clean up any previous state\n this.initialState = undefined;\n this.rootState = undefined;\n this.nextState = undefined;\n this.routeInfo = undefined;\n this.linking = undefined;\n this.navigationRefSubscription?.();\n this.rootStateSubscribers.clear();\n this.storeSubscribers.clear();\n\n this.routeNode = getRoutes(context, { ignoreEntryPoints: true });\n\n this.rootComponent = this.routeNode ? getQualifiedRouteComponent(this.routeNode) : Fragment;\n\n // Only error in production, in development we will show the onboarding screen\n if (!this.routeNode && process.env.NODE_ENV === 'production') {\n throw new Error('No routes found');\n }\n\n this.navigationRef = navigationRef;\n\n if (this.routeNode) {\n this.linking = getLinkingConfig(this.routeNode!);\n\n if (initialLocation) {\n this.linking.getInitialURL = () => initialLocation.toString();\n this.initialState = this.linking.getStateFromPath?.(\n initialLocation.pathname + initialLocation.search,\n this.linking.config\n );\n }\n }\n\n // There is no routeNode, so we will be showing the onboarding screen\n // In the meantime, just mock the routeInfo\n if (this.initialState) {\n this.rootState = this.initialState;\n this.routeInfo = this.getRouteInfo(this.initialState);\n } else {\n this.routeInfo = {\n unstable_globalHref: '',\n pathname: '',\n isIndex: false,\n params: {},\n segments: [],\n };\n }\n\n /**\n * Counter intuitively - this fires AFTER both React Navigation's state changes and the subsequent paint.\n * This poses a couple of issues for Expo Router,\n * - Ensuring hooks (e.g. useSearchParams()) have data in the initial render\n * - Reacting to state changes after a navigation event\n *\n * This is why the initial render renders a Fragment and we wait until `onReady()` is called\n * Additionally, some hooks compare the state from both the store and the navigationRef. If the store it stale,\n * that hooks will manually update the store.\n *\n */\n this.navigationRefSubscription = navigationRef.addListener('state', (data) => {\n const state = data.data.state as ResultState;\n\n if (!this.hasAttemptedToHideSplash) {\n this.hasAttemptedToHideSplash = true;\n // NOTE(EvanBacon): `navigationRef.isReady` is sometimes not true when state is called initially.\n requestAnimationFrame(\n () =>\n // @ts-expect-error: This function is native-only and for internal-use only.\n SplashScreen._internal_maybeHideAsync?.()\n );\n }\n\n let shouldUpdateSubscribers = this.nextState === state;\n this.nextState = undefined;\n\n // This can sometimes be undefined when an error is thrown in the Root Layout Route.\n // Additionally that state may already equal the rootState if it was updated within a hook\n if (state && state !== this.rootState) {\n store.updateState(state, undefined);\n shouldUpdateSubscribers = true;\n }\n\n // If the state has changed, or was changed inside a hook we need to update the subscribers\n if (shouldUpdateSubscribers) {\n for (const subscriber of this.rootStateSubscribers) {\n subscriber();\n }\n }\n });\n\n for (const subscriber of this.storeSubscribers) {\n subscriber();\n }\n }\n\n updateState(state: ResultState, nextState = state) {\n store.rootState = state;\n store.nextState = nextState;\n\n const nextRouteInfo = store.getRouteInfo(state);\n\n if (!deepEqual(this.routeInfo, nextRouteInfo)) {\n store.routeInfo = nextRouteInfo;\n }\n }\n\n getRouteInfo(state: ResultState) {\n return getRouteInfoFromState(\n (state: Parameters<typeof getPathFromState>[0], asPath: boolean) => {\n return getPathDataFromState(state, {\n screens: [],\n ...this.linking?.config,\n preserveDynamicRoutes: asPath,\n preserveGroups: asPath,\n });\n },\n state\n );\n }\n\n // This is only used in development, to show the onboarding screen\n // In production we should have errored during the initialization\n shouldShowTutorial() {\n return !this.routeNode && process.env.NODE_ENV === 'development';\n }\n\n /** Make sure these are arrow functions so `this` is correctly bound */\n subscribeToRootState = (subscriber: () => void) => {\n this.rootStateSubscribers.add(subscriber);\n return () => this.rootStateSubscribers.delete(subscriber);\n };\n subscribeToStore = (subscriber: () => void) => {\n this.storeSubscribers.add(subscriber);\n return () => this.storeSubscribers.delete(subscriber);\n };\n snapshot = () => {\n return this;\n };\n rootStateSnapshot = () => {\n return this.rootState!;\n };\n routeInfoSnapshot = () => {\n return this.routeInfo!;\n };\n}\n\nexport const store = new RouterStore();\n\nexport function useExpoRouter() {\n return useSyncExternalStore(store.subscribeToStore, store.snapshot, store.snapshot);\n}\n\nfunction syncStoreRootState() {\n if (store.navigationRef.isReady()) {\n const currentState = store.navigationRef.getRootState() as unknown as ResultState;\n\n if (store.rootState !== currentState) {\n store.updateState(currentState);\n }\n }\n}\n\nexport function useStoreRootState() {\n syncStoreRootState();\n return useSyncExternalStore(\n store.subscribeToRootState,\n store.rootStateSnapshot,\n store.rootStateSnapshot\n );\n}\n\nexport function useStoreRouteInfo() {\n syncStoreRootState();\n return useSyncExternalStore(\n store.subscribeToRootState,\n store.routeInfoSnapshot,\n store.routeInfoSnapshot\n );\n}\n\nexport function useInitializeExpoRouter(context: RequireContext, initialLocation: URL | undefined) {\n const navigationRef = useNavigationContainerRef();\n useMemo(\n () => store.initialize(context, navigationRef, initialLocation),\n [context, initialLocation]\n );\n useExpoRouter();\n return store;\n}\n"]}
|
|
@@ -2,9 +2,12 @@ import type { RouterStore } from './router-store';
|
|
|
2
2
|
import { Href } from '../link/href';
|
|
3
3
|
export declare function navigate(this: RouterStore, url: Href): any;
|
|
4
4
|
export declare function push(this: RouterStore, url: Href): any;
|
|
5
|
+
export declare function dismiss(this: RouterStore, count?: number): void;
|
|
5
6
|
export declare function replace(this: RouterStore, url: Href): any;
|
|
7
|
+
export declare function dismissAll(this: RouterStore): void;
|
|
6
8
|
export declare function goBack(this: RouterStore): void;
|
|
7
9
|
export declare function canGoBack(this: RouterStore): boolean;
|
|
10
|
+
export declare function canDismiss(this: RouterStore): boolean;
|
|
8
11
|
export declare function setParams(this: RouterStore, params?: Record<string, string | number>): any;
|
|
9
12
|
export declare function linkTo(this: RouterStore, href: string, event?: string): void;
|
|
10
13
|
//# sourceMappingURL=routing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/global-state/routing.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,IAAI,EAAe,MAAM,cAAc,CAAC;AAYjD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,OAEpD;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,OAEhD;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,OAEnD;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,QAGvC;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAUpD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAM,OAGxF;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,QAgErE"}
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/global-state/routing.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,IAAI,EAAe,MAAM,cAAc,CAAC;AAYjD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,OAEpD;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,OAEhD;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,MAAM,QAExD;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,OAEnD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,WAAW,QAE3C;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,QAGvC;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAUpD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAcrD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAM,OAGxF;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,QAgErE"}
|
|
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.linkTo = exports.setParams = exports.canGoBack = exports.goBack = exports.replace = exports.push = exports.navigate = void 0;
|
|
26
|
+
exports.linkTo = exports.setParams = exports.canDismiss = exports.canGoBack = exports.goBack = exports.dismissAll = exports.replace = exports.dismiss = exports.push = exports.navigate = void 0;
|
|
27
|
+
const native_1 = require("@react-navigation/native");
|
|
27
28
|
const Linking = __importStar(require("expo-linking"));
|
|
28
29
|
const href_1 = require("../link/href");
|
|
29
30
|
const path_1 = require("../link/path");
|
|
@@ -41,10 +42,18 @@ function push(url) {
|
|
|
41
42
|
return this.linkTo((0, href_1.resolveHref)(url), 'PUSH');
|
|
42
43
|
}
|
|
43
44
|
exports.push = push;
|
|
45
|
+
function dismiss(count) {
|
|
46
|
+
this.navigationRef?.dispatch(native_1.StackActions.pop(count));
|
|
47
|
+
}
|
|
48
|
+
exports.dismiss = dismiss;
|
|
44
49
|
function replace(url) {
|
|
45
50
|
return this.linkTo((0, href_1.resolveHref)(url), 'REPLACE');
|
|
46
51
|
}
|
|
47
52
|
exports.replace = replace;
|
|
53
|
+
function dismissAll() {
|
|
54
|
+
this.navigationRef?.dispatch(native_1.StackActions.popToTop());
|
|
55
|
+
}
|
|
56
|
+
exports.dismissAll = dismissAll;
|
|
48
57
|
function goBack() {
|
|
49
58
|
assertIsReady(this);
|
|
50
59
|
this.navigationRef?.current?.goBack();
|
|
@@ -62,6 +71,20 @@ function canGoBack() {
|
|
|
62
71
|
return this.navigationRef?.current?.canGoBack() ?? false;
|
|
63
72
|
}
|
|
64
73
|
exports.canGoBack = canGoBack;
|
|
74
|
+
function canDismiss() {
|
|
75
|
+
let state = this.rootState;
|
|
76
|
+
// Keep traversing down the state tree until we find a stack navigator that we can pop
|
|
77
|
+
while (state) {
|
|
78
|
+
if (state.type === 'stack' && state.routes.length > 1) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (state.index === undefined)
|
|
82
|
+
return false;
|
|
83
|
+
state = state.routes?.[state.index]?.state;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
exports.canDismiss = canDismiss;
|
|
65
88
|
function setParams(params = {}) {
|
|
66
89
|
assertIsReady(this);
|
|
67
90
|
return (this.navigationRef?.current?.setParams)(params);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/global-state/routing.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDAAwC;AAIxC,uCAAiD;AACjD,uCAAuC;AACvC,sCAAoD;AAEpD,SAAS,aAAa,CAAC,KAAkB;IACvC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE;QAClC,MAAM,IAAI,KAAK,CACb,gKAAgK,CACjK,CAAC;KACH;AACH,CAAC;AAED,SAAgB,QAAQ,CAAoB,GAAS;IACnD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAA,kBAAW,EAAC,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;AACnD,CAAC;AAFD,4BAEC;AAED,SAAgB,IAAI,CAAoB,GAAS;IAC/C,OAAO,IAAI,CAAC,MAAM,CAAC,IAAA,kBAAW,EAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC;AAFD,oBAEC;AAED,SAAgB,OAAO,CAAoB,GAAS;IAClD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAA,kBAAW,EAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC;AAClD,CAAC;AAFD,0BAEC;AAED,SAAgB,MAAM;IACpB,aAAa,CAAC,IAAI,CAAC,CAAC;IACpB,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACxC,CAAC;AAHD,wBAGC;AAED,SAAgB,SAAS;IACvB,oEAAoE;IACpE,2EAA2E;IAC3E,8FAA8F;IAC9F,yEAAyE;IACzE,uCAAuC;IACvC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE;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,CAAC,KAAY,EAAE,IAAI,CAAC,CAAC;KACxE;IAED,mFAAmF;IACnF,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,8BAA8B,CAAC,KAAK,CAAC,CAAC;IAEjE,IAAI,IAAI,KAAK,MAAM,IAAI,WAAW,CAAC,IAAI,KAAK,OAAO,EAAE;QACnD,IAAI,GAAG,UAAU,CAAC;KACnB;SAAM,IAAI,IAAI,KAAK,SAAS,IAAI,WAAW,CAAC,IAAI,KAAK,KAAK,EAAE;QAC3D,IAAI,GAAG,SAAS,CAAC;KAClB;IAED,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,WAAW,CAAC,GAAG;QACvB,OAAO,EAAE;YACP,IAAI,EAAE,MAAM;YACZ,MAAM;SACP;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { type NavigationState } from '@react-navigation/native';\nimport * as Linking from 'expo-linking';\n\nimport type { RouterStore } from './router-store';\nimport { ResultState } from '../fork/getStateFromPath';\nimport { Href, resolveHref } from '../link/href';\nimport { resolve } from '../link/path';\nimport { shouldLinkExternally } from '../utils/url';\n\nfunction assertIsReady(store: RouterStore) {\n if (!store.navigationRef.isReady()) {\n throw new Error(\n 'Attempted to navigate before mounting the Root Layout component. Ensure the Root Layout component is rendering a Slot, or other navigator on the first render.'\n );\n }\n}\n\nexport function navigate(this: RouterStore, url: Href) {\n return this.linkTo(resolveHref(url), 'NAVIGATE');\n}\n\nexport function push(this: RouterStore, url: Href) {\n return this.linkTo(resolveHref(url), 'PUSH');\n}\n\nexport function replace(this: RouterStore, url: Href) {\n return this.linkTo(resolveHref(url), 'REPLACE');\n}\n\nexport function goBack(this: RouterStore) {\n assertIsReady(this);\n this.navigationRef?.current?.goBack();\n}\n\nexport function canGoBack(this: RouterStore): boolean {\n // Return a default value here if the navigation hasn't mounted yet.\n // This can happen if the user calls `canGoBack` from the Root Layout route\n // before mounting a navigator. This behavior exists due to React Navigation being dynamically\n // constructed at runtime. We can get rid of this in the future if we use\n // the static configuration internally.\n if (!this.navigationRef.isReady()) {\n return false;\n }\n return this.navigationRef?.current?.canGoBack() ?? false;\n}\n\nexport function setParams(this: RouterStore, params: Record<string, string | number> = {}) {\n assertIsReady(this);\n return (this.navigationRef?.current?.setParams as any)(params);\n}\n\nexport function linkTo(this: RouterStore, href: string, event?: string) {\n if (shouldLinkExternally(href)) {\n Linking.openURL(href);\n return;\n }\n\n assertIsReady(this);\n const navigationRef = this.navigationRef.current;\n\n if (navigationRef == null) {\n throw new Error(\n \"Couldn't find a navigation object. Is your component inside NavigationContainer?\"\n );\n }\n\n if (!this.linking) {\n throw new Error('Attempted to link to route when no routes are present');\n }\n\n if (href === '..' || href === '../') {\n navigationRef.goBack();\n return;\n }\n\n const rootState = navigationRef.getRootState();\n\n if (href.startsWith('.')) {\n // Resolve base path by merging the current segments with the params\n let base =\n this.routeInfo?.segments\n ?.map((segment) => {\n if (!segment.startsWith('[')) return segment;\n\n if (segment.startsWith('[...')) {\n segment = segment.slice(4, -1);\n const params = this.routeInfo?.params?.[segment];\n if (Array.isArray(params)) {\n return params.join('/');\n } else {\n return params?.split(',')?.join('/') ?? '';\n }\n } else {\n segment = segment.slice(1, -1);\n return this.routeInfo?.params?.[segment];\n }\n })\n .filter(Boolean)\n .join('/') ?? '/';\n\n if (!this.routeInfo?.isIndex) {\n base += '/..';\n }\n\n href = resolve(base, href);\n }\n\n const state = this.linking.getStateFromPath!(href, this.linking.config);\n\n if (!state || state.routes.length === 0) {\n console.error('Could not generate a valid navigation state for the given path: ' + href);\n return;\n }\n\n return navigationRef.dispatch(getNavigateAction(state, rootState, event));\n}\n\ntype NavigationParams = Partial<{\n screen: string;\n params: NavigationParams;\n}>;\n\nfunction rewriteNavigationStateToParams(\n state?: { routes: ResultState['routes'] } | NavigationState,\n params: NavigationParams = {}\n) {\n if (!state) return params;\n // We Should always have at least one route in the state\n const lastRoute = state.routes[state.routes.length - 1]!;\n params.screen = lastRoute.name;\n // Weirdly, this always needs to be an object. If it's undefined, it won't work.\n params.params = lastRoute.params ? JSON.parse(JSON.stringify(lastRoute.params)) : {};\n\n if (lastRoute.state) {\n rewriteNavigationStateToParams(lastRoute.state, params.params);\n }\n\n return JSON.parse(JSON.stringify(params));\n}\n\nfunction getNavigateAction(state: ResultState, parentState: NavigationState, type = 'NAVIGATE') {\n const route = state.routes[state.routes.length - 1]!;\n\n const currentRoute = parentState.routes.find((parentRoute) => parentRoute.name === route.name);\n const routesAreEqual = parentState.routes[parentState.index] === currentRoute;\n\n // If there is nested state and the routes are equal, we should keep going down the tree\n if (route.state && routesAreEqual && currentRoute.state) {\n return getNavigateAction(route.state, currentRoute.state as any, type);\n }\n\n // Either we reached the bottom of the state or the point where the routes diverged\n const { screen, params } = rewriteNavigationStateToParams(state);\n\n if (type === 'PUSH' && parentState.type !== 'stack') {\n type = 'NAVIGATE';\n } else if (type === 'REPLACE' && parentState.type === 'tab') {\n type = 'JUMP_TO';\n }\n\n return {\n type,\n target: parentState.key,\n payload: {\n name: screen,\n params,\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/global-state/routing.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA8E;AAC9E,sDAAwC;AAIxC,uCAAiD;AACjD,uCAAuC;AACvC,sCAAoD;AAEpD,SAAS,aAAa,CAAC,KAAkB;IACvC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE;QAClC,MAAM,IAAI,KAAK,CACb,gKAAgK,CACjK,CAAC;KACH;AACH,CAAC;AAED,SAAgB,QAAQ,CAAoB,GAAS;IACnD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAA,kBAAW,EAAC,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;AACnD,CAAC;AAFD,4BAEC;AAED,SAAgB,IAAI,CAAoB,GAAS;IAC/C,OAAO,IAAI,CAAC,MAAM,CAAC,IAAA,kBAAW,EAAC,GAAG,CAAC,EAAE,M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AC;KACxE;IAED,mFAAmF;IACnF,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,8BAA8B,CAAC,KAAK,CAAC,CAAC;IAEjE,IAAI,IAAI,KAAK,MAAM,IAAI,WAAW,CAAC,IAAI,KAAK,OAAO,EAAE;QACnD,IAAI,GAAG,UAAU,CAAC;KACnB;SAAM,IAAI,IAAI,KAAK,SAAS,IAAI,WAAW,CAAC,IAAI,KAAK,KAAK,EAAE;QAC3D,IAAI,GAAG,SAAS,CAAC;KAClB;IAED,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,WAAW,CAAC,GAAG;QACvB,OAAO,EAAE;YACP,IAAI,EAAE,MAAM;YACZ,MAAM;SACP;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { StackActions, type NavigationState } from '@react-navigation/native';\nimport * as Linking from 'expo-linking';\n\nimport type { RouterStore } from './router-store';\nimport { ResultState } from '../fork/getStateFromPath';\nimport { Href, resolveHref } from '../link/href';\nimport { resolve } from '../link/path';\nimport { shouldLinkExternally } from '../utils/url';\n\nfunction assertIsReady(store: RouterStore) {\n if (!store.navigationRef.isReady()) {\n throw new Error(\n 'Attempted to navigate before mounting the Root Layout component. Ensure the Root Layout component is rendering a Slot, or other navigator on the first render.'\n );\n }\n}\n\nexport function navigate(this: RouterStore, url: Href) {\n return this.linkTo(resolveHref(url), 'NAVIGATE');\n}\n\nexport function push(this: RouterStore, url: Href) {\n return this.linkTo(resolveHref(url), 'PUSH');\n}\n\nexport function dismiss(this: RouterStore, count?: number) {\n this.navigationRef?.dispatch(StackActions.pop(count));\n}\n\nexport function replace(this: RouterStore, url: Href) {\n return this.linkTo(resolveHref(url), 'REPLACE');\n}\n\nexport function dismissAll(this: RouterStore) {\n this.navigationRef?.dispatch(StackActions.popToTop());\n}\n\nexport function goBack(this: RouterStore) {\n assertIsReady(this);\n this.navigationRef?.current?.goBack();\n}\n\nexport function canGoBack(this: RouterStore): boolean {\n // Return a default value here if the navigation hasn't mounted yet.\n // This can happen if the user calls `canGoBack` from the Root Layout route\n // before mounting a navigator. This behavior exists due to React Navigation being dynamically\n // constructed at runtime. We can get rid of this in the future if we use\n // the static configuration internally.\n if (!this.navigationRef.isReady()) {\n return false;\n }\n return this.navigationRef?.current?.canGoBack() ?? false;\n}\n\nexport function canDismiss(this: RouterStore): boolean {\n let state = this.rootState;\n\n // Keep traversing down the state tree until we find a stack navigator that we can pop\n while (state) {\n if (state.type === 'stack' && state.routes.length > 1) {\n return true;\n }\n if (state.index === undefined) return false;\n\n state = state.routes?.[state.index]?.state as any;\n }\n\n return false;\n}\n\nexport function setParams(this: RouterStore, params: Record<string, string | number> = {}) {\n assertIsReady(this);\n return (this.navigationRef?.current?.setParams as any)(params);\n}\n\nexport function linkTo(this: RouterStore, href: string, event?: string) {\n if (shouldLinkExternally(href)) {\n Linking.openURL(href);\n return;\n }\n\n assertIsReady(this);\n const navigationRef = this.navigationRef.current;\n\n if (navigationRef == null) {\n throw new Error(\n \"Couldn't find a navigation object. Is your component inside NavigationContainer?\"\n );\n }\n\n if (!this.linking) {\n throw new Error('Attempted to link to route when no routes are present');\n }\n\n if (href === '..' || href === '../') {\n navigationRef.goBack();\n return;\n }\n\n const rootState = navigationRef.getRootState();\n\n if (href.startsWith('.')) {\n // Resolve base path by merging the current segments with the params\n let base =\n this.routeInfo?.segments\n ?.map((segment) => {\n if (!segment.startsWith('[')) return segment;\n\n if (segment.startsWith('[...')) {\n segment = segment.slice(4, -1);\n const params = this.routeInfo?.params?.[segment];\n if (Array.isArray(params)) {\n return params.join('/');\n } else {\n return params?.split(',')?.join('/') ?? '';\n }\n } else {\n segment = segment.slice(1, -1);\n return this.routeInfo?.params?.[segment];\n }\n })\n .filter(Boolean)\n .join('/') ?? '/';\n\n if (!this.routeInfo?.isIndex) {\n base += '/..';\n }\n\n href = resolve(base, href);\n }\n\n const state = this.linking.getStateFromPath!(href, this.linking.config);\n\n if (!state || state.routes.length === 0) {\n console.error('Could not generate a valid navigation state for the given path: ' + href);\n return;\n }\n\n return navigationRef.dispatch(getNavigateAction(state, rootState, event));\n}\n\ntype NavigationParams = Partial<{\n screen: string;\n params: NavigationParams;\n}>;\n\nfunction rewriteNavigationStateToParams(\n state?: { routes: ResultState['routes'] } | NavigationState,\n params: NavigationParams = {}\n) {\n if (!state) return params;\n // We Should always have at least one route in the state\n const lastRoute = state.routes[state.routes.length - 1]!;\n params.screen = lastRoute.name;\n // Weirdly, this always needs to be an object. If it's undefined, it won't work.\n params.params = lastRoute.params ? JSON.parse(JSON.stringify(lastRoute.params)) : {};\n\n if (lastRoute.state) {\n rewriteNavigationStateToParams(lastRoute.state, params.params);\n }\n\n return JSON.parse(JSON.stringify(params));\n}\n\nfunction getNavigateAction(state: ResultState, parentState: NavigationState, type = 'NAVIGATE') {\n const route = state.routes[state.routes.length - 1]!;\n\n const currentRoute = parentState.routes.find((parentRoute) => parentRoute.name === route.name);\n const routesAreEqual = parentState.routes[parentState.index] === currentRoute;\n\n // If there is nested state and the routes are equal, we should keep going down the tree\n if (route.state && routesAreEqual && currentRoute.state) {\n return getNavigateAction(route.state, currentRoute.state as any, type);\n }\n\n // Either we reached the bottom of the state or the point where the routes diverged\n const { screen, params } = rewriteNavigationStateToParams(state);\n\n if (type === 'PUSH' && parentState.type !== 'stack') {\n type = 'NAVIGATE';\n } else if (type === 'REPLACE' && parentState.type === 'tab') {\n type = 'JUMP_TO';\n }\n\n return {\n type,\n target: parentState.key,\n payload: {\n name: screen,\n params,\n },\n };\n}\n"]}
|
package/build/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;AAEtD,wBAAgB,sBAAsB,kDAErC;AAED,wBAAgB,YAAY,2CAE3B;AAED,wFAAwF;AACxF,wBAAgB,iBAAiB,oGAEhC;AAED,uJAAuJ;AACvJ,wBAAgB,yBAAyB,wGAExC;AAED,wBAAgB,SAAS,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;AAEtD,wBAAgB,sBAAsB,kDAErC;AAED,wBAAgB,YAAY,2CAE3B;AAED,wFAAwF;AACxF,wBAAgB,iBAAiB,oGAEhC;AAED,uJAAuJ;AACvJ,wBAAgB,yBAAyB,wGAExC;AAED,wBAAgB,SAAS,IAAI,MAAM,CAgBlC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,SAAS,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,KAAK,SAAS,CAE9E;AAED,kEAAkE;AAClE,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,SAAS,YAAY,GAAG,YAAY,KACxC,OAAO,CAAC,OAAO,CAAC,CAEpB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,SAAS,YAAY,GAAG,YAAY,KACxC,OAAO,CAAC,OAAO,CAAC,CAwBpB"}
|
package/build/hooks.js
CHANGED
|
@@ -28,6 +28,9 @@ exports.useNavigationContainerRef = useNavigationContainerRef;
|
|
|
28
28
|
function useRouter() {
|
|
29
29
|
return react_1.default.useMemo(() => ({
|
|
30
30
|
push: router_store_1.store.push,
|
|
31
|
+
dismiss: router_store_1.store.dismiss,
|
|
32
|
+
dismissAll: router_store_1.store.dismissAll,
|
|
33
|
+
canDismiss: router_store_1.store.canDismiss,
|
|
31
34
|
back: router_store_1.store.goBack,
|
|
32
35
|
replace: router_store_1.store.replace,
|
|
33
36
|
setParams: router_store_1.store.setParams,
|
package/build/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAkE;AAClE,kDAA0B;AAE1B,8DAA0F;AAK1F,SAAgB,sBAAsB;IACpC,OAAO,IAAA,gCAAiB,GAAE,CAAC;AAC7B,CAAC;AAFD,wDAEC;AAED,SAAgB,YAAY;IAC1B,OAAO,IAAA,gCAAiB,GAAE,CAAC;AAC7B,CAAC;AAFD,oCAEC;AAED,wFAAwF;AACxF,SAAgB,iBAAiB;IAC/B,OAAO,oBAAK,CAAC,aAAa,CAAC,OAAO,CAAC;AACrC,CAAC;AAFD,8CAEC;AAED,uJAAuJ;AACvJ,SAAgB,yBAAyB;IACvC,OAAO,oBAAK,CAAC,aAAa,CAAC;AAC7B,CAAC;AAFD,8DAEC;AAED,SAAgB,SAAS;IACvB,OAAO,eAAK,CAAC,OAAO,CAClB,GAAG,EAAE,CAAC,CAAC;QACL,IAAI,EAAE,oBAAK,CAAC,IAAI;QAChB,IAAI,EAAE,oBAAK,CAAC,MAAM;QAClB,OAAO,EAAE,oBAAK,CAAC,OAAO;QACtB,SAAS,EAAE,oBAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,oBAAK,CAAC,SAAS;QAC1B,QAAQ,EAAE,oBAAK,CAAC,QAAQ;QACxB,gCAAgC;KACjC,CAAC,EACF,EAAE,CACH,CAAC;AACJ,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAkE;AAClE,kDAA0B;AAE1B,8DAA0F;AAK1F,SAAgB,sBAAsB;IACpC,OAAO,IAAA,gCAAiB,GAAE,CAAC;AAC7B,CAAC;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,MAA0B,CAAC;AACxD,CAAC;AAJD,sDAIC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB;IAGlC,MAAM,MAAM,GAAG,eAAK,CAAC,UAAU,CAAC,+BAAsB,CAAC,EAAE,MAAM,IAAI,EAAE,CAAC;IACtE,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACxB,OAAO;gBACL,GAAG;gBACH,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;oBACd,IAAI;wBACF,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC;qBAC9B;oBAAC,MAAM;wBACN,OAAO,CAAC,CAAC;qBACV;gBACH,CAAC,CAAC;aACH,CAAC;SACH;aAAM;YACL,IAAI;gBACF,OAAO,CAAC,GAAG,EAAE,kBAAkB,CAAC,KAAe,CAAC,CAAC,CAAC;aACnD;YAAC,MAAM;gBACN,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;aACrB;SACF;IACH,CAAC,CAAC,CACiB,CAAC;AACxB,CAAC;AA1BD,oDA0BC","sourcesContent":["import { NavigationRouteContext } from '@react-navigation/native';\nimport React from 'react';\n\nimport { store, useStoreRootState, useStoreRouteInfo } from './global-state/router-store';\nimport { Router } from './types';\n\ntype SearchParams = Record<string, string | string[]>;\n\nexport function useRootNavigationState() {\n return useStoreRootState();\n}\n\nexport function useRouteInfo() {\n return useStoreRouteInfo();\n}\n\n/** @deprecated use `useNavigationContainerRef()` instead, which returns a React ref. */\nexport function useRootNavigation() {\n return store.navigationRef.current;\n}\n\n/** @return the root `<NavigationContainer />` ref for the app. The `ref.current` may be `null` if the `<NavigationContainer />` hasn't mounted yet. */\nexport function useNavigationContainerRef() {\n return store.navigationRef;\n}\n\nexport function useRouter(): Router {\n return React.useMemo(\n () => ({\n push: store.push,\n dismiss: store.dismiss,\n dismissAll: store.dismissAll,\n canDismiss: store.canDismiss,\n back: store.goBack,\n replace: store.replace,\n setParams: store.setParams,\n canGoBack: store.canGoBack,\n navigate: store.navigate,\n // TODO(EvanBacon): add `reload`\n }),\n []\n );\n}\n\n/**\n * @private\n * @returns the current global pathname with query params attached. This may change in the future to include the hostname from a predefined universal link, i.e. `/foobar?hey=world` becomes `https://acme.dev/foobar?hey=world`\n */\nexport function useUnstableGlobalHref(): string {\n return useStoreRouteInfo().unstable_globalHref;\n}\n\n/**\n * Get a list of selected file segments for the currently selected route. Segments are not normalized, so they will be the same as the file path. e.g. /[id]?id=normal -> [\"[id]\"]\n *\n * `useSegments` can be typed using an abstract.\n * Consider the following file structure, and strictly typed `useSegments` function:\n *\n * ```md\n * - app\n * - [user]\n * - index.js\n * - followers.js\n * - settings.js\n * ```\n * This can be strictly typed using the following abstract:\n *\n * ```ts\n * const [first, second] = useSegments<['settings'] | ['[user]'] | ['[user]', 'followers']>()\n * ```\n */\nexport function useSegments<TSegments extends string[] = string[]>(): TSegments {\n return useStoreRouteInfo().segments as TSegments;\n}\n\n/** @returns global selected pathname without query parameters. */\nexport function usePathname(): string {\n return useStoreRouteInfo().pathname;\n}\n\n/**\n * Get the globally selected query parameters, including dynamic path segments. This function will update even when the route is not focused.\n * Useful for analytics or other background operations that don't draw to the screen.\n *\n * When querying search params in a stack, opt-towards using `useLocalSearchParams` as these will only\n * update when the route is focused.\n *\n * @see `useLocalSearchParams`\n */\nexport function useGlobalSearchParams<\n TParams extends SearchParams = SearchParams,\n>(): Partial<TParams> {\n return useStoreRouteInfo().params as Partial<TParams>;\n}\n\n/**\n * Returns the URL search parameters for the contextually focused route. e.g. `/acme?foo=bar` -> `{ foo: \"bar\" }`.\n * This is useful for stacks where you may push a new screen that changes the query parameters.\n *\n * To observe updates even when the invoking route is not focused, use `useGlobalSearchParams()`.\n */\nexport function useLocalSearchParams<\n TParams extends SearchParams = SearchParams,\n>(): Partial<TParams> {\n const params = React.useContext(NavigationRouteContext)?.params ?? {};\n return Object.fromEntries(\n Object.entries(params).map(([key, value]) => {\n if (Array.isArray(value)) {\n return [\n key,\n value.map((v) => {\n try {\n return decodeURIComponent(v);\n } catch {\n return v;\n }\n }),\n ];\n } else {\n try {\n return [key, decodeURIComponent(value as string)];\n } catch {\n return [key, value];\n }\n }\n })\n ) as Partial<TParams>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imperative-api.d.ts","sourceRoot":"","sources":["../src/imperative-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,eAAO,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"imperative-api.d.ts","sourceRoot":"","sources":["../src/imperative-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,eAAO,MAAM,MAAM,EAAE,MAUpB,CAAC"}
|
package/build/imperative-api.js
CHANGED
|
@@ -5,6 +5,9 @@ const router_store_1 = require("./global-state/router-store");
|
|
|
5
5
|
exports.router = {
|
|
6
6
|
navigate: (href) => router_store_1.store.navigate(href),
|
|
7
7
|
push: (href) => router_store_1.store.push(href),
|
|
8
|
+
dismiss: (count) => router_store_1.store.dismiss(count),
|
|
9
|
+
dismissAll: () => router_store_1.store.dismissAll(),
|
|
10
|
+
canDismiss: () => router_store_1.store.canDismiss(),
|
|
8
11
|
replace: (href) => router_store_1.store.replace(href),
|
|
9
12
|
back: () => router_store_1.store.goBack(),
|
|
10
13
|
canGoBack: () => router_store_1.store.canGoBack(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imperative-api.js","sourceRoot":"","sources":["../src/imperative-api.ts"],"names":[],"mappings":";;;AAAA,8DAAoD;AAGvC,QAAA,MAAM,GAAW;IAC5B,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;IACxC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAK,CAAC,IAAI,CAAC,IAAI,CAAC;IAChC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAK,CAAC,OAAO,CAAC,IAAI,CAAC;IACtC,IAAI,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,MAAM,EAAE;IAC1B,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,SAAS,EAAE;IAClC,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,oBAAK,CAAC,SAAS,CAAC,MAAM,CAAC;CAC/C,CAAC","sourcesContent":["import { store } from './global-state/router-store';\nimport { Router } from './types';\n\nexport const router: Router = {\n navigate: (href) => store.navigate(href),\n push: (href) => store.push(href),\n replace: (href) => store.replace(href),\n back: () => store.goBack(),\n canGoBack: () => store.canGoBack(),\n setParams: (params) => store.setParams(params),\n};\n"]}
|
|
1
|
+
{"version":3,"file":"imperative-api.js","sourceRoot":"","sources":["../src/imperative-api.ts"],"names":[],"mappings":";;;AAAA,8DAAoD;AAGvC,QAAA,MAAM,GAAW;IAC5B,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;IACxC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAK,CAAC,IAAI,CAAC,IAAI,CAAC;IAChC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,oBAAK,CAAC,OAAO,CAAC,KAAK,CAAC;IACxC,UAAU,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,UAAU,EAAE;IACpC,UAAU,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,UAAU,EAAE;IACpC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAK,CAAC,OAAO,CAAC,IAAI,CAAC;IACtC,IAAI,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,MAAM,EAAE;IAC1B,SAAS,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,SAAS,EAAE;IAClC,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,oBAAK,CAAC,SAAS,CAAC,MAAM,CAAC;CAC/C,CAAC","sourcesContent":["import { store } from './global-state/router-store';\nimport { Router } from './types';\n\nexport const router: Router = {\n navigate: (href) => store.navigate(href),\n push: (href) => store.push(href),\n dismiss: (count) => store.dismiss(count),\n dismissAll: () => store.dismissAll(),\n canDismiss: () => store.canDismiss(),\n replace: (href) => store.replace(href),\n back: () => store.goBack(),\n canGoBack: () => store.canGoBack(),\n setParams: (params) => store.setParams(params),\n};\n"]}
|
|
@@ -12,9 +12,9 @@ export declare function inMemoryContext(context: Record<string, FileStub>): ((id
|
|
|
12
12
|
}) | {
|
|
13
13
|
default: FileStub;
|
|
14
14
|
}) & {
|
|
15
|
-
keys: () => string[];
|
|
16
15
|
resolve: (key: string) => string;
|
|
17
16
|
id: string;
|
|
17
|
+
keys: () => string[];
|
|
18
18
|
};
|
|
19
19
|
export declare function requireContextWithOverrides(dir: string, overrides: Record<string, FileStub>): ((id: string) => any) & {
|
|
20
20
|
keys: () => string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-stubs.d.ts","sourceRoot":"","sources":["../../src/testing-library/context-stubs.ts"],"names":[],"mappings":";AAEA,OAAO,cAAc,MAAM,4BAA4B,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;AACvE,MAAM,MAAM,QAAQ,GAChB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACzB,OAAO,EAAE,cAAc,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACzC,CAAC,GACF,cAAc,CAAC;AAEnB,OAAO,EAAE,cAAc,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"context-stubs.d.ts","sourceRoot":"","sources":["../../src/testing-library/context-stubs.ts"],"names":[],"mappings":";AAEA,OAAO,cAAc,MAAM,4BAA4B,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;AACvE,MAAM,MAAM,QAAQ,GAChB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACzB,OAAO,EAAE,cAAc,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACzC,CAAC,GACF,cAAc,CAAC;AAEnB,OAAO,EAAE,cAAc,EAAE,CAAC;AAI1B,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,SAE/C,MAAM;;;;;;mBAKH,MAAM;;;EAU1B;AAED,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,SAI1E,MAAM;;mBAUH,MAAM;;EAI1B"}
|
|
@@ -7,14 +7,19 @@ exports.requireContextWithOverrides = exports.inMemoryContext = exports.requireC
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const require_context_ponyfill_1 = __importDefault(require("./require-context-ponyfill"));
|
|
9
9
|
exports.requireContext = require_context_ponyfill_1.default;
|
|
10
|
+
const validExtensions = ['.js', '.jsx', '.ts', '.tsx'];
|
|
10
11
|
function inMemoryContext(context) {
|
|
11
12
|
return Object.assign(function (id) {
|
|
12
|
-
id = id.replace(/^\.\//, '').replace(
|
|
13
|
+
id = id.replace(/^\.\//, '').replace(/\.\w*$/, '');
|
|
13
14
|
return typeof context[id] === 'function' ? { default: context[id] } : context[id];
|
|
14
15
|
}, {
|
|
15
|
-
keys: () => Object.keys(context).map((key) => './' + key + '.js'),
|
|
16
16
|
resolve: (key) => key,
|
|
17
17
|
id: '0',
|
|
18
|
+
keys: () => Object.keys(context).map((key) => {
|
|
19
|
+
const ext = path_1.default.extname(key);
|
|
20
|
+
key = key.replace(/^\.\//, '');
|
|
21
|
+
return validExtensions.includes(ext) ? `./${key}` : `./${key}.js`;
|
|
22
|
+
}),
|
|
18
23
|
});
|
|
19
24
|
}
|
|
20
25
|
exports.inMemoryContext = inMemoryContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-stubs.js","sourceRoot":"","sources":["../../src/testing-library/context-stubs.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB,0FAAwD;AAU/C,yBAVF,kCAAc,CAUE;AAEvB,SAAgB,eAAe,CAAC,OAAiC;IAC/D,OAAO,MAAM,CAAC,MAAM,CAClB,UAAU,EAAU;QAClB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"context-stubs.js","sourceRoot":"","sources":["../../src/testing-library/context-stubs.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB,0FAAwD;AAU/C,yBAVF,kCAAc,CAUE;AAEvB,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAEvD,SAAgB,eAAe,CAAC,OAAiC;IAC/D,OAAO,MAAM,CAAC,MAAM,CAClB,UAAU,EAAU;QAClB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACnD,OAAO,OAAO,OAAO,CAAC,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAA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EAAE,EAAE,GAAG;KACR,CACF,CAAC;AACJ,CAAC;AAlBD,kEAkBC","sourcesContent":["import path from 'path';\n\nimport requireContext from './require-context-ponyfill';\n\nexport type ReactComponent = () => React.ReactElement<any, any> | null;\nexport type FileStub =\n | (Record<string, unknown> & {\n default: ReactComponent;\n unstable_settings?: Record<string, any>;\n })\n | ReactComponent;\n\nexport { requireContext };\n\nconst validExtensions = ['.js', '.jsx', '.ts', '.tsx'];\n\nexport function inMemoryContext(context: Record<string, FileStub>) {\n return Object.assign(\n function (id: string) {\n id = id.replace(/^\\.\\//, '').replace(/\\.\\w*$/, '');\n return typeof context[id] === 'function' ? { default: context[id] } : context[id];\n },\n {\n resolve: (key: string) => key,\n id: '0',\n keys: () =>\n Object.keys(context).map((key) => {\n const ext = path.extname(key);\n key = key.replace(/^\\.\\//, '');\n return validExtensions.includes(ext) ? `./${key}` : `./${key}.js`;\n }),\n }\n );\n}\n\nexport function requireContextWithOverrides(dir: string, overrides: Record<string, FileStub>) {\n const existingContext = requireContext(path.resolve(process.cwd(), dir));\n\n return Object.assign(\n function (id: string) {\n if (id in overrides) {\n const route = overrides[id];\n return typeof route === 'function' ? { default: route } : route;\n } else {\n return existingContext(id);\n }\n },\n {\n keys: () => [...Object.keys(overrides), ...existingContext.keys()],\n resolve: (key: string) => key,\n id: '0',\n }\n );\n}\n"]}
|
|
@@ -11,10 +11,14 @@ type Result = ReturnType<typeof render> & {
|
|
|
11
11
|
getSegments(): string[];
|
|
12
12
|
getSearchParams(): Record<string, string | string[]>;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
15
|
-
export declare function renderRouter(context: Record<string, FileStub>, options?: RenderRouterOptions): Result;
|
|
16
|
-
export declare function renderRouter(context: {
|
|
14
|
+
export type MockContextConfig = string | string[] | Record<string, FileStub> | {
|
|
17
15
|
appDir: string;
|
|
18
16
|
overrides: Record<string, FileStub>;
|
|
19
|
-
}
|
|
17
|
+
};
|
|
18
|
+
export declare function getMockConfig(context: MockContextConfig): {
|
|
19
|
+
initialRouteName?: string | undefined;
|
|
20
|
+
screens: Record<string, import("../getReactNavigationConfig").Screen>;
|
|
21
|
+
};
|
|
22
|
+
export declare function getMockContext(context: MockContextConfig): import("../types").RequireContext;
|
|
23
|
+
export declare function renderRouter(context?: MockContextConfig, { initialUrl, ...options }?: RenderRouterOptions): Result;
|
|
20
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing-library/index.tsx"],"names":[],"mappings":"AACA,OAAO,UAAU,CAAC;AAElB,OAAO,EAAE,MAAM,EAAgB,MAAM,+BAA+B,CAAC;AAIrE,OAAO,EACL,QAAQ,EAIT,MAAM,iBAAiB,CAAC;AASzB,cAAc,+BAA+B,CAAC;AAE9C,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG;IACxD,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,KAAK,MAAM,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,GAAG;IACxC,WAAW,IAAI,MAAM,CAAC;IACtB,qBAAqB,IAAI,MAAM,CAAC;IAChC,WAAW,IAAI,MAAM,EAAE,CAAC;IACxB,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CACtD,CAAC;AAQF,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing-library/index.tsx"],"names":[],"mappings":"AACA,OAAO,UAAU,CAAC;AAElB,OAAO,EAAE,MAAM,EAAgB,MAAM,+BAA+B,CAAC;AAIrE,OAAO,EACL,QAAQ,EAIT,MAAM,iBAAiB,CAAC;AASzB,cAAc,+BAA+B,CAAC;AAE9C,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG;IACxD,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,KAAK,MAAM,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,GAAG;IACxC,WAAW,IAAI,MAAM,CAAC;IACtB,qBAAqB,IAAI,MAAM,CAAC;IAChC,WAAW,IAAI,MAAM,EAAE,CAAC;IACxB,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CACtD,CAAC;AAQF,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,MAAM,EAAE,GACR,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GACxB;IAEE,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CACrC,CAAC;AAEN,wBAAgB,aAAa,CAAC,OAAO,EAAE,iBAAiB;;;EAEvD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,iBAAiB,qCAYxD;AAED,wBAAgB,YAAY,CAC1B,OAAO,GAAE,iBAA2B,EACpC,EAAE,UAAgB,EAAE,GAAG,OAAO,EAAE,GAAE,mBAAwB,GACzD,MAAM,CAsCR"}
|
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.renderRouter = void 0;
|
|
20
|
+
exports.renderRouter = exports.getMockContext = exports.getMockConfig = void 0;
|
|
21
21
|
/// <reference types="../../types/jest" />
|
|
22
22
|
require("./expect");
|
|
23
23
|
const react_native_1 = require("@testing-library/react-native");
|
|
@@ -28,28 +28,39 @@ const mocks_1 = require("./mocks");
|
|
|
28
28
|
const ExpoRoot_1 = require("../ExpoRoot");
|
|
29
29
|
const getPathFromState_1 = __importDefault(require("../fork/getPathFromState"));
|
|
30
30
|
const getLinkingConfig_1 = require("../getLinkingConfig");
|
|
31
|
+
const getRoutes_1 = require("../getRoutes");
|
|
31
32
|
const router_store_1 = require("../global-state/router-store");
|
|
32
33
|
// re-export everything
|
|
33
34
|
__exportStar(require("@testing-library/react-native"), exports);
|
|
34
35
|
function isOverrideContext(context) {
|
|
35
36
|
return Boolean(typeof context === 'object' && 'appDir' in context);
|
|
36
37
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// Force the render to be synchronous
|
|
43
|
-
process.env.EXPO_ROUTER_IMPORT_MODE = 'sync';
|
|
38
|
+
function getMockConfig(context) {
|
|
39
|
+
return (0, getLinkingConfig_1.getNavigationConfig)((0, getRoutes_1.getExactRoutes)(getMockContext(context)));
|
|
40
|
+
}
|
|
41
|
+
exports.getMockConfig = getMockConfig;
|
|
42
|
+
function getMockContext(context) {
|
|
44
43
|
if (typeof context === 'string') {
|
|
45
|
-
|
|
44
|
+
return (0, context_stubs_1.requireContext)(path_1.default.resolve(process.cwd(), context));
|
|
45
|
+
}
|
|
46
|
+
else if (Array.isArray(context)) {
|
|
47
|
+
return (0, context_stubs_1.inMemoryContext)(Object.fromEntries(context.map((filename) => [filename, { default: () => null }])));
|
|
46
48
|
}
|
|
47
49
|
else if (isOverrideContext(context)) {
|
|
48
|
-
|
|
50
|
+
return (0, context_stubs_1.requireContextWithOverrides)(context.appDir, context.overrides);
|
|
49
51
|
}
|
|
50
52
|
else {
|
|
51
|
-
|
|
53
|
+
return (0, context_stubs_1.inMemoryContext)(context);
|
|
52
54
|
}
|
|
55
|
+
}
|
|
56
|
+
exports.getMockContext = getMockContext;
|
|
57
|
+
function renderRouter(context = './app', { initialUrl = '/', ...options } = {}) {
|
|
58
|
+
jest.useFakeTimers();
|
|
59
|
+
const mockContext = getMockContext(context);
|
|
60
|
+
// Reset the initial URL
|
|
61
|
+
(0, mocks_1.setInitialUrl)(initialUrl);
|
|
62
|
+
// Force the render to be synchronous
|
|
63
|
+
process.env.EXPO_ROUTER_IMPORT_MODE = 'sync';
|
|
53
64
|
getLinkingConfig_1.stateCache.clear();
|
|
54
65
|
let location;
|
|
55
66
|
if (typeof initialUrl === 'string') {
|
|
@@ -58,7 +69,7 @@ function renderRouter(context = './app', { initialUrl = '/', ...options } = {})
|
|
|
58
69
|
else if (initialUrl instanceof URL) {
|
|
59
70
|
location = initialUrl;
|
|
60
71
|
}
|
|
61
|
-
const result = (0, react_native_1.render)(<ExpoRoot_1.ExpoRoot context={
|
|
72
|
+
const result = (0, react_native_1.render)(<ExpoRoot_1.ExpoRoot context={mockContext} location={location}/>, {
|
|
62
73
|
...options,
|
|
63
74
|
});
|
|
64
75
|
return Object.assign(result, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing-library/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,0CAA0C;AAC1C,oBAAkB;AAElB,gEAAqE;AACrE,gDAAwB;AACxB,kDAA0B;AAE1B,mDAKyB;AACzB,mCAAwC;AACxC,0CAAuC;AACvC,gFAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing-library/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,0CAA0C;AAC1C,oBAAkB;AAElB,gEAAqE;AACrE,gDAAwB;AACxB,kDAA0B;AAE1B,mDAKyB;AACzB,mCAAwC;AACxC,0CAAuC;AACvC,gFAAwD;AACxD,0DAAsE;AACtE,4CAA8C;AAC9C,+DAAqD;AAErD,uBAAuB;AACvB,gEAA8C;AAa9C,SAAS,iBAAiB,CACxB,OAAe;IAEf,OAAO,OAAO,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,QAAQ,IAAI,OAAO,CAAC,CAAC;AACrE,CAAC;AAaD,SAAgB,aAAa,CAAC,OAA0B;IACtD,OAAO,IAAA,sCAAmB,EAAC,IAAA,0BAAc,EAAC,cAAc,CAAC,OAAO,CAAC,CAAE,CAAC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UAAU,YAAY,GAAG,EAAE;QACpC,QAAQ,GAAG,UAAU,CAAC;KACvB;IAED,MAAM,MAAM,GAAG,IAAA,qBAAM,EAAC,CAAC,mBAAQ,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAG,EAAE;QAC5E,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;QAC3B,WAAW;YACT,OAAO,oBAAK,CAAC,iBAAiB,EAAE,CAAC,QAAQ,CAAC;QAC5C,CAAC;QACD,WAAW;YACT,OAAO,oBAAK,CAAC,iBAAiB,EAAE,CAAC,QAAQ,CAAC;QAC5C,CAAC;QACD,eAAe;YACb,OAAO,oBAAK,CAAC,iBAAiB,EAAE,CAAC,MAAM,CAAC;QAC1C,CAAC;QACD,qBAAqB;YACnB,OAAO,IAAA,0BAAgB,EAAC,oBAAK,CAAC,SAAU,EAAE,oBAAK,CAAC,OAAQ,CAAC,MAAM,CAAC,CAAC;QACnE,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAzCD,oCAyCC","sourcesContent":["/// <reference types=\"../../types/jest\" />\nimport './expect';\n\nimport { render, RenderResult } from '@testing-library/react-native';\nimport path from 'path';\nimport React from 'react';\n\nimport {\n FileStub,\n inMemoryContext,\n requireContext,\n requireContextWithOverrides,\n} from './context-stubs';\nimport { setInitialUrl } from './mocks';\nimport { ExpoRoot } from '../ExpoRoot';\nimport getPathFromState from '../fork/getPathFromState';\nimport { getNavigationConfig, stateCache } from '../getLinkingConfig';\nimport { getExactRoutes } from '../getRoutes';\nimport { store } from '../global-state/router-store';\n\n// re-export everything\nexport * from '@testing-library/react-native';\n\ntype RenderRouterOptions = Parameters<typeof render>[1] & {\n initialUrl?: any;\n};\n\ntype Result = ReturnType<typeof render> & {\n getPathname(): string;\n getPathnameWithParams(): string;\n getSegments(): string[];\n getSearchParams(): Record<string, string | string[]>;\n};\n\nfunction isOverrideContext(\n context: object\n): context is { appDir: string; overrides: Record<string, FileStub> } {\n return Boolean(typeof context === 'object' && 'appDir' in context);\n}\n\nexport type MockContextConfig =\n | string // Pathname to a directory\n | string[] // Array of filenames to mock as empty components, e.g () => null\n | Record<string, FileStub> // Map of filenames and their exports\n | {\n // Directory to load as context\n appDir: string;\n // Map of filenames and their exports. Will override contents of files loaded in `appDir\n overrides: Record<string, FileStub>;\n };\n\nexport function getMockConfig(context: MockContextConfig) {\n return getNavigationConfig(getExactRoutes(getMockContext(context))!);\n}\n\nexport function getMockContext(context: MockContextConfig) {\n if (typeof context === 'string') {\n return requireContext(path.resolve(process.cwd(), context));\n } else if (Array.isArray(context)) {\n return inMemoryContext(\n Object.fromEntries(context.map((filename) => [filename, { default: () => null }]))\n );\n } else if (isOverrideContext(context)) {\n return requireContextWithOverrides(context.appDir, context.overrides);\n } else {\n return inMemoryContext(context);\n }\n}\n\nexport function renderRouter(\n context: MockContextConfig = './app',\n { initialUrl = '/', ...options }: RenderRouterOptions = {}\n): Result {\n jest.useFakeTimers();\n\n const mockContext = getMockContext(context);\n\n // Reset the initial URL\n setInitialUrl(initialUrl);\n\n // Force the render to be synchronous\n process.env.EXPO_ROUTER_IMPORT_MODE = 'sync';\n stateCache.clear();\n\n let location: URL | undefined;\n\n if (typeof initialUrl === 'string') {\n location = new URL(initialUrl, 'test://');\n } else if (initialUrl instanceof URL) {\n location = initialUrl;\n }\n\n const result = render(<ExpoRoot context={mockContext} location={location} />, {\n ...options,\n });\n\n return Object.assign(result, {\n getPathname(this: RenderResult): string {\n return store.routeInfoSnapshot().pathname;\n },\n getSegments(this: RenderResult): string[] {\n return store.routeInfoSnapshot().segments;\n },\n getSearchParams(this: RenderResult): Record<string, string | string[]> {\n return store.routeInfoSnapshot().params;\n },\n getPathnameWithParams(this: RenderResult): string {\n return getPathFromState(store.rootState!, store.linking!.config);\n },\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../src/testing-library/mocks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../src/testing-library/mocks.ts"],"names":[],"mappings":"AA2BA,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,QAE1C"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setInitialUrl = void 0;
|
|
4
|
-
|
|
4
|
+
/*
|
|
5
|
+
* Optionally enable @testing-library/jest-native/extend-expect. We use this internally for the `toBeOnTheScreen` matcher()
|
|
6
|
+
*/
|
|
7
|
+
try {
|
|
8
|
+
require('@testing-library/jest-native/extend-expect');
|
|
9
|
+
}
|
|
10
|
+
catch { }
|
|
5
11
|
// include this section and the NativeAnimatedHelper section for mocking react-native-reanimated
|
|
6
12
|
jest.mock('react-native-reanimated', () => {
|
|
7
13
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mocks.js","sourceRoot":"","sources":["../../src/testing-library/mocks.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"mocks.js","sourceRoot":"","sources":["../../src/testing-library/mocks.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAI;IACF,OAAO,CAAC,4CAA4C,CAAC,CAAC;CACvD;AAAC,MAAM,GAAE;AAEV,gGAAgG;AAChG,IAAI,CAAC,IAAI,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACxC,IAAI;QACF,MAAM,UAAU,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;QAE3D,wEAAwE;QACxE,iCAAiC;QACjC,UAAU,CAAC,OAAO,CAAC,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QAEnC,OAAO,UAAU,CAAC;KACnB;IAAC,MAAM;QACN,OAAO,EAAE,CAAC;KACX;AACH,CAAC,CAAC,CAAC;AAEH,kHAAkH;AAClH,IAAI,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;AAElE,IAAI,cAAc,GAA6B,EAAE,CAAC;AAElD,SAAgB,aAAa,CAAC,KAAa;IACzC,cAAc,GAAG,KAAK,CAAC;AACzB,CAAC;AAFD,sCAEC;AAED,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE;IAC7B,MAAM,MAAM,GAAkC;QAC5C,GAAG,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;QACrC,SAAS,CAAC,IAAY;YACpB,OAAO,eAAe,GAAG,IAAI,CAAC;QAChC,CAAC;QACD,aAAa;YACX,OAAO,YAAY,CAAC;QACtB,CAAC;QACD,gBAAgB;YACd,OAAO,EAAE,MAAM,KAAI,CAAC,EAAS,CAAC;QAChC,CAAC;QACD,KAAK,CAAC,aAAa;YACjB,OAAO,cAAc,CAAC;QACxB,CAAC;KACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC,CAAC","sourcesContent":["/*\n * Optionally enable @testing-library/jest-native/extend-expect. We use this internally for the `toBeOnTheScreen` matcher()\n */\ntry {\n require('@testing-library/jest-native/extend-expect');\n} catch {}\n\n// include this section and the NativeAnimatedHelper section for mocking react-native-reanimated\njest.mock('react-native-reanimated', () => {\n try {\n const Reanimated = require('react-native-reanimated/mock');\n\n // The mock for `call` immediately calls the callback which is incorrect\n // So we override it with a no-op\n Reanimated.default.call = () => {};\n\n return Reanimated;\n } catch {\n return {};\n }\n});\n\n// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing\njest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');\n\nlet mockInitialUrl: string | Promise<string> = '';\n\nexport function setInitialUrl(value: string) {\n mockInitialUrl = value;\n}\n\njest.mock('expo-linking', () => {\n const module: typeof import('expo-linking') = {\n ...jest.requireActual('expo-linking'),\n createURL(path: string) {\n return 'yourscheme://' + path;\n },\n resolveScheme() {\n return 'yourscheme';\n },\n addEventListener() {\n return { remove() {} } as any;\n },\n async getInitialURL() {\n return mockInitialUrl;\n },\n };\n\n return module;\n});\n"]}
|
package/build/types.d.ts
CHANGED
|
@@ -12,16 +12,22 @@ export interface RequireContext {
|
|
|
12
12
|
/** The list of input keys will become optional, everything else will remain the same. */
|
|
13
13
|
export type PickPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
14
14
|
export type Router = {
|
|
15
|
-
/** Navigate to the provided href using a
|
|
15
|
+
/** Navigate to the provided href using a dismiss operation if possible. */
|
|
16
16
|
push: (href: Href) => void;
|
|
17
|
+
/** Navigate to the provided href using a push operation if possible. */
|
|
18
|
+
dismiss: (count?: number) => void;
|
|
17
19
|
/** Navigate to the provided href. */
|
|
18
20
|
navigate: (href: Href) => void;
|
|
19
21
|
/** Navigate to route without appending to the history. */
|
|
20
22
|
replace: (href: Href) => void;
|
|
23
|
+
/** Navigate to first screen within the lowest stack */
|
|
24
|
+
dismissAll: () => void;
|
|
21
25
|
/** Go back in the history. */
|
|
22
26
|
back: () => void;
|
|
23
27
|
/** If there's history that supports invoking the `back` function. */
|
|
24
28
|
canGoBack: () => boolean;
|
|
29
|
+
/** If there's history that supports invoking the `dismiss` and `dismissAll` function. */
|
|
30
|
+
canDismiss: () => boolean;
|
|
25
31
|
/** Update the current route query params. */
|
|
26
32
|
setParams: (params?: Record<string, string>) => void;
|
|
27
33
|
};
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGxC,MAAM,WAAW,cAAc;IAC7B,4CAA4C;IAC5C,IAAI,IAAI,MAAM,EAAE,CAAC;IACjB,CAAC,EAAE,EAAE,MAAM,GAAG,GAAG,CAAC;IAClB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC;IACnB,0EAA0E;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0D;IAC1D,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC9B,uDAAuD;IACvD,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,8BAA8B;IAC9B,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,qEAAqE;IACrE,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB,yFAAyF;IACzF,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B,6CAA6C;IAC7C,SAAS,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CACtD,CAAC"}
|
package/build/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Href } from './link/href';\n\n// TODO: Use the global type\nexport interface RequireContext {\n /** Return the keys that can be resolved. */\n keys(): string[];\n (id: string): any;\n <T>(id: string): T;\n /** **Unimplemented:** Return the module identifier for a user request. */\n resolve(id: string): string;\n /** **Unimplemented:** Readable identifier for the context module. */\n id: string;\n}\n\n/** The list of input keys will become optional, everything else will remain the same. */\nexport type PickPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\nexport type Router = {\n /** Navigate to the provided href using a
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Href } from './link/href';\n\n// TODO: Use the global type\nexport interface RequireContext {\n /** Return the keys that can be resolved. */\n keys(): string[];\n (id: string): any;\n <T>(id: string): T;\n /** **Unimplemented:** Return the module identifier for a user request. */\n resolve(id: string): string;\n /** **Unimplemented:** Readable identifier for the context module. */\n id: string;\n}\n\n/** The list of input keys will become optional, everything else will remain the same. */\nexport type PickPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\nexport type Router = {\n /** Navigate to the provided href using a dismiss operation if possible. */\n push: (href: Href) => void;\n /** Navigate to the provided href using a push operation if possible. */\n dismiss: (count?: number) => void;\n /** Navigate to the provided href. */\n navigate: (href: Href) => void;\n /** Navigate to route without appending to the history. */\n replace: (href: Href) => void;\n /** Navigate to first screen within the lowest stack */\n dismissAll: () => void;\n /** Go back in the history. */\n back: () => void;\n /** If there's history that supports invoking the `back` function. */\n canGoBack: () => boolean;\n /** If there's history that supports invoking the `dismiss` and `dismissAll` function. */\n canDismiss: () => boolean;\n /** Update the current route query params. */\n setParams: (params?: Record<string, string>) => void;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-router",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.8",
|
|
4
4
|
"description": "Expo Router is a file-based router for React Native and web applications.",
|
|
5
5
|
"author": "650 Industries, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"react-helmet-async": "^1.3.0",
|
|
102
102
|
"schema-utils": "^4.0.1"
|
|
103
103
|
},
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "01bef8630cd9fd913bb465afd010d6030a9ca38f"
|
|
105
105
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { RequireContext } from '../types';
|
|
2
|
-
export declare function createMockContextModule(map?: Record<string, Record<string, any>>): RequireContext;
|
|
3
|
-
export declare function configFromFs(map?: (string | [string, object])[]): {
|
|
4
|
-
initialRouteName?: string | undefined;
|
|
5
|
-
screens: Record<string, import("../getReactNavigationConfig").Screen>;
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=mockState.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockState.d.ts","sourceRoot":"","sources":["../../src/utils/mockState.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,wBAAgB,uBAAuB,CAAC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM,kBAQpF;AAED,wBAAgB,YAAY,CAAC,GAAG,GAAE,CAAC,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAO;;;EAiBnE"}
|
package/build/utils/mockState.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.configFromFs = exports.createMockContextModule = void 0;
|
|
4
|
-
const getLinkingConfig_1 = require("../getLinkingConfig");
|
|
5
|
-
const getRoutes_1 = require("../getRoutes");
|
|
6
|
-
function createMockContextModule(map = {}) {
|
|
7
|
-
const contextModule = jest.fn((key) => map[key]);
|
|
8
|
-
Object.defineProperty(contextModule, 'keys', {
|
|
9
|
-
value: () => Object.keys(map),
|
|
10
|
-
});
|
|
11
|
-
return contextModule;
|
|
12
|
-
}
|
|
13
|
-
exports.createMockContextModule = createMockContextModule;
|
|
14
|
-
function configFromFs(map = []) {
|
|
15
|
-
const ctx = map.reduce((acc, value) => {
|
|
16
|
-
if (typeof value === 'string') {
|
|
17
|
-
acc[value] = { default: () => { } };
|
|
18
|
-
return acc;
|
|
19
|
-
}
|
|
20
|
-
acc[value[0]] = {
|
|
21
|
-
default: () => { },
|
|
22
|
-
...value[1],
|
|
23
|
-
};
|
|
24
|
-
return acc;
|
|
25
|
-
}, {});
|
|
26
|
-
return (0, getLinkingConfig_1.getNavigationConfig)((0, getRoutes_1.getExactRoutes)(createMockContextModule(ctx)));
|
|
27
|
-
}
|
|
28
|
-
exports.configFromFs = configFromFs;
|
|
29
|
-
//# sourceMappingURL=mockState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mockState.js","sourceRoot":"","sources":["../../src/utils/mockState.ts"],"names":[],"mappings":";;;AAAA,0DAA0D;AAC1D,4CAA8C;AAG9C,SAAgB,uBAAuB,CAAC,MAA2C,EAAE;IACnF,MAAM,aAAa,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAEjD,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,MAAM,EAAE;QAC3C,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;KAC9B,CAAC,CAAC;IAEH,OAAO,aAA0C,CAAC;AACpD,CAAC;AARD,0DAQC;AAED,SAAgB,YAAY,CAAC,MAAqC,EAAE;IAClE,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CACpB,CAAC,GAAG,EAAE,KAAU,EAAE,EAAE;QAClB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;YACnC,OAAO,GAAG,CAAC;SACZ;QACD,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG;YACd,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC;YACjB,GAAG,KAAK,CAAC,CAAC,CAAC;SACZ,CAAC;QACF,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAyC,CAC1C,CAAC;IAEF,OAAO,IAAA,sCAAmB,EAAC,IAAA,0BAAc,EAAC,uBAAuB,CAAC,GAAG,CAAC,CAAE,CAAC,CAAC;AAC5E,CAAC;AAjBD,oCAiBC","sourcesContent":["import { getNavigationConfig } from '../getLinkingConfig';\nimport { getExactRoutes } from '../getRoutes';\nimport { RequireContext } from '../types';\n\nexport function createMockContextModule(map: Record<string, Record<string, any>> = {}) {\n const contextModule = jest.fn((key) => map[key]);\n\n Object.defineProperty(contextModule, 'keys', {\n value: () => Object.keys(map),\n });\n\n return contextModule as unknown as RequireContext;\n}\n\nexport function configFromFs(map: (string | [string, object])[] = []) {\n const ctx = map.reduce(\n (acc, value: any) => {\n if (typeof value === 'string') {\n acc[value] = { default: () => {} };\n return acc;\n }\n acc[value[0]] = {\n default: () => {},\n ...value[1],\n };\n return acc;\n },\n {} as Record<string, Record<string, any>>\n );\n\n return getNavigationConfig(getExactRoutes(createMockContextModule(ctx))!);\n}\n"]}
|