Skip to content

Commit

Permalink
fix: accept partial linking.config for static navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Mar 22, 2024
1 parent b19568c commit 3825046
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
11 changes: 3 additions & 8 deletions packages/core/src/StaticNavigation.tsx
Expand Up @@ -444,6 +444,7 @@ export function createComponentForStaticNavigation(

type TreeForPathConfig = {
config: {
initialRouteName?: string;
screens?: StaticConfigScreens<
ParamListBase,
NavigationState,
Expand Down Expand Up @@ -588,21 +589,15 @@ export function createPathConfigForStaticNavigation(
);
};

const initialRouteName =
'initialRouteName' in t.config &&
typeof t.config.initialRouteName === 'string'
? t.config.initialRouteName
: undefined;

const screens = t.config.screens
? createPathConfigForScreens(t.config.screens, initialRouteName)
? createPathConfigForScreens(t.config.screens, t.config.initialRouteName)
: {};

if (t.config.groups) {
Object.entries(t.config.groups).forEach(([, group]) => {
Object.assign(
screens,
createPathConfigForScreens(group.screens, initialRouteName)
createPathConfigForScreens(group.screens, t.config.initialRouteName)
);
});
}
Expand Down
24 changes: 21 additions & 3 deletions packages/native/src/createStaticNavigation.tsx
Expand Up @@ -27,6 +27,13 @@ type Props = Omit<
* This can be overridden for specific screens by specifying `linking` for the screen.
*/
enabled?: 'auto' | true | false;
/**
* Additional configuration
*/
config?: Omit<
NonNullable<LinkingOptions<ParamListBase>['config']>,
'screens'
>;
};
};

Expand All @@ -47,14 +54,25 @@ export function createStaticNavigation(tree: StaticNavigation<any, any, any>) {
const screens = React.useMemo(() => {
if (tree.config.screens) {
return createPathConfigForStaticNavigation(
tree,
{
...tree,
...{
config: {
...tree.config,
initialRouteName:
linking?.config?.initialRouteName ??
typeof tree.config.initialRouteName,
screens: tree.config.screens,
},
},
},
linking?.enabled === 'auto',
true
);
}

return undefined;
}, [linking?.enabled]);
}, [linking?.config?.initialRouteName, linking?.enabled]);

if (linking?.enabled === true && screens == null) {
throw new Error(
Expand All @@ -78,7 +96,7 @@ export function createStaticNavigation(tree: StaticNavigation<any, any, any>) {
typeof linking.enabled === 'boolean'
? linking.enabled
: screens != null,
config: screens ? { screens } : undefined,
config: screens ? { ...linking.config, screens } : undefined,
}
: undefined
}
Expand Down

0 comments on commit 3825046

Please sign in to comment.