Skip to content

Commit 1d462c0

Browse files
committed
StackContainer refactor analagous to TabsContainer
also small change in TabsContainer
1 parent e0bb90f commit 1d462c0

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

apps/src/shared/gamma/containers/stack/StackContainer.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function StackContainer({ routeConfigs }: StackContainerProps) {
6262
return (
6363
<Stack.Host ref={hostRef}>
6464
{stackNavState.stack.map(
65-
({ Component, options: { headerConfig, ...options }, activityMode, routeKey }) => {
65+
({ options: { headerConfig, ...options }, activityMode, routeKey, name }) => {
6666
const stackNavigationContext: StackNavigationContextPayload = {
6767
routeKey,
6868
routeOptions: { ...options },
@@ -73,6 +73,17 @@ export function StackContainer({ routeConfigs }: StackContainerProps) {
7373
setRouteOptions: navMethods.setRouteOptions,
7474
};
7575

76+
const matchingConfig = routeConfigs.find(
77+
config => config.name === name,
78+
);
79+
if (!matchingConfig) {
80+
throw new Error(
81+
`[Stack] No config matches the "${name}" route name`,
82+
);
83+
}
84+
85+
const Component = matchingConfig.Component;
86+
7687
return (
7788
<Stack.Screen
7889
key={routeKey}

apps/src/shared/gamma/containers/stack/StackContainer.types.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export type StackRouteConfig = {
2222
options: StackRouteOptions;
2323
};
2424

25-
export type StackRoute = StackRouteConfig & {
25+
export type StackRoute = Omit<StackRouteConfig, 'Component'> & {
2626
activityMode: StackScreenProps['activityMode'];
2727
routeKey: StackScreenProps['screenKey'];
2828
isMarkedForDismissal: Boolean; // whether this route is during or after dismissal process

apps/src/shared/gamma/containers/stack/reducer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,10 @@ function createRouteFromConfig(
270270
config: StackRouteConfig,
271271
activityMode: StackScreenActivityMode = 'detached',
272272
): StackRoute {
273+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
274+
const { Component, ...rest } = config;
273275
return {
274-
...config,
276+
...rest,
275277
activityMode,
276278
routeKey: generateRouteKeyForRouteName(config.name),
277279
isMarkedForDismissal: false,

apps/src/shared/gamma/containers/tabs/TabsContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ export function TabsContainer(props: TabsContainerProps) {
8585
route.routeKey === tabsNavState.suggestedState.selectedRouteKey;
8686

8787
const matchingConfig = routeConfigs.find(
88-
config => config.name === route.routeKey,
88+
config => config.name === route.name,
8989
);
9090
if (!matchingConfig) {
9191
throw new Error(
92-
`[Tabs] None config matches the "${route.routeKey}" routeKey`,
92+
`[Tabs] None config matches the "${route.name}" route name`,
9393
);
9494
}
9595

0 commit comments

Comments
 (0)