Skip to content

Commit

Permalink
fix: cr
Browse files Browse the repository at this point in the history
  • Loading branch information
osdnk committed Oct 14, 2023
1 parent 2249935 commit 03e25b0
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 136 deletions.
6 changes: 5 additions & 1 deletion packages/core/src/getStateFromPath.tsx
Expand Up @@ -7,7 +7,7 @@ import escape from 'escape-string-regexp';
import * as queryString from 'query-string';

import { findFocusedRoute } from './findFocusedRoute';
import type { PathConfigMap, ResultState } from './types';
import type { PathConfigMap } from './types';
import { validatePathConfig } from './validatePathConfig';

type Options<ParamList extends {}> = {
Expand All @@ -32,6 +32,10 @@ type InitialRouteConfig = {
parentScreens: string[];
};

type ResultState = PartialState<NavigationState> & {
state?: ResultState;
};

type ParsedRoute = {
name: string;
path?: string;
Expand Down
7 changes: 2 additions & 5 deletions packages/core/src/types.tsx
Expand Up @@ -298,7 +298,8 @@ type NavigationHelpersCommon<
*/
getState(): State;
/**
* Schedules the next navigation state on route names change.
* Schedules the given state to be used as navigation state when the list of screens defined in the navigator changes
* instead of automatically calculating the new state, e.g. due to conditional rendering or dynamically defining screens.
*
* @param state Navigation state object.
*/
Expand Down Expand Up @@ -794,7 +795,3 @@ export type PathConfigMap<ParamList extends {}> = {
? string | PathConfig<T>
: string | Omit<PathConfig<{}>, 'screens' | 'initialRouteName'>;
};

export type ResultState = PartialState<NavigationState> & {
state?: ResultState;
};
2 changes: 1 addition & 1 deletion packages/core/src/useNavigationBuilder.tsx
Expand Up @@ -658,6 +658,7 @@ export function useNavigationBuilder<
routeGetIdList,
},
emitter,
stateForNextRouteNamesChange: navigatorStateForNextRouteNamesChange,
});

const onRouteFocus = useOnRouteFocus({
Expand Down Expand Up @@ -710,7 +711,6 @@ export function useNavigationBuilder<
router,
// @ts-expect-error: this should have both core and custom events, but too much work right now
emitter,
setNavigatorStateForNextRouteNamesChange,
});

useCurrentRender({
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/useOnAction.tsx
Expand Up @@ -26,6 +26,7 @@ type Options = {
beforeRemoveListeners: Record<string, ChildBeforeRemoveListener | undefined>;
routerConfigOptions: RouterConfigOptions;
emitter: NavigationEventEmitter<EventMapCore<any>>;
stateForNextRouteNamesChange: PartialState<NavigationState> | null;
};

/**
Expand All @@ -46,6 +47,7 @@ export function useOnAction({
beforeRemoveListeners,
routerConfigOptions,
emitter,
stateForNextRouteNamesChange,
}: Options) {
const {
onAction: onActionParent,
Expand All @@ -69,6 +71,11 @@ export function useOnAction({
action: NavigationAction,
visitedNavigators: Set<string> = new Set<string>()
) => {
if (stateForNextRouteNamesChange) {
console.warn(
'Other navigation was invoked before we handling the unhandled deeplink (requested by invoking handleOnNextRouteNamesChange)'
);
}
const state = getState();

// Since actions can bubble both up and down, they could come to the same navigator again
Expand Down Expand Up @@ -157,6 +164,7 @@ export function useOnAction({
onRouteFocusParent,
router,
setState,
stateForNextRouteNamesChange,
]
);

Expand Down
3 changes: 1 addition & 2 deletions packages/native/src/LinkingContext.tsx
@@ -1,8 +1,7 @@
import type { ParamListBase } from '@react-navigation/core';
import type { LinkingOptions } from '@react-navigation/native/src/types';
import * as React from 'react';

import type { LinkingOptions } from './types';

const MISSING_CONTEXT_ERROR = "Couldn't find a LinkingContext context.";

export const LinkingContext = React.createContext<{
Expand Down

0 comments on commit 03e25b0

Please sign in to comment.