Skip to content

Commit 57c90f4

Browse files
committed
TabsContainer refactor
now, instead of keeping a Component in state, we find one in routeConfigs prop, basing on routeKey
1 parent 8bf9850 commit 57c90f4

5 files changed

Lines changed: 27 additions & 5 deletions

File tree

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,27 @@ export function TabsContainer(props: TabsContainerProps) {
8484
const pendingForUpdate =
8585
route.routeKey === tabsNavState.suggestedState.selectedRouteKey;
8686

87-
return <TabsContainerItem key={route.routeKey} route={route} navMethods={navMethods} isSelected={isSelected} pendingForUpdate={pendingForUpdate} />
87+
const matchingConfig = routeConfigs.find(
88+
config => config.name === route.routeKey,
89+
);
90+
if (!matchingConfig) {
91+
throw new Error(
92+
`[Tabs] None config matches the "${route.routeKey}" routeKey`,
93+
);
94+
}
95+
96+
const Component = matchingConfig.Component;
97+
98+
return (
99+
<TabsContainerItem
100+
key={route.routeKey}
101+
route={route}
102+
navMethods={navMethods}
103+
isSelected={isSelected}
104+
pendingForUpdate={pendingForUpdate}
105+
Component={Component}
106+
/>
107+
);
88108
})}
89109
</Tabs.Host>
90110
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export type TabRouteConfig = {
2727
/**
2828
* Runtime instance of a tab route. Created from a TabRouteConfig blueprint.
2929
*/
30-
export type TabRoute = TabRouteConfig & {
30+
export type TabRoute = Omit<TabRouteConfig, 'Component'> & {
3131
routeKey: string;
3232
};
3333

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function TabsContainerItemImpl(props: TabsContainerItemProps) {
3737
{...nativeOptions}
3838
screenKey={screenKey}>
3939
<TabsNavigationContext value={tabsNavigationContext}>
40-
{getContent(props.route.Component, safeAreaConfiguration)}
40+
{getContent(props.Component, safeAreaConfiguration)}
4141
</TabsNavigationContext>
4242
</Tabs.Screen>
4343
);

apps/src/shared/gamma/containers/tabs/TabsContainerItem.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ export type TabsContainerItemProps = {
55
navMethods: TabsNavigationMethods;
66
isSelected: boolean;
77
pendingForUpdate: boolean;
8+
Component: React.ComponentType;
89
}
910

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@ function tabsActionSetOptionsHandler(
135135
}
136136

137137
function createTabRouteFromConfig(config: TabRouteConfig): TabRoute {
138+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
139+
const { Component, ...rest } = config;
138140
return {
139-
...config,
141+
...rest,
140142
// Tab names are required to be unique (enforced by useSanitizeRouteConfigs),
141143
// so the name itself serves as a stable unique key.
142144
routeKey: config.name,
@@ -205,4 +207,3 @@ function navStateWithConfirmedState(
205207
suggestedState: state.suggestedState,
206208
};
207209
}
208-

0 commit comments

Comments
 (0)