Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apps/src/shared/gamma/containers/shared/use-components-by-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { useMemo } from 'react';
import type { StackRouteConfig } from '../stack';
import type { TabRouteConfig } from '../tabs';

export const useComponentsByName = (
routeConfigs: StackRouteConfig[] | TabRouteConfig[],
) => {
return useMemo(() => {
const map = new Map<string, React.ComponentType>();

for (const config of routeConfigs) {
map.set(config.name, config.Component);
}

return map;
}, [routeConfigs]);
};
12 changes: 11 additions & 1 deletion apps/src/shared/gamma/containers/stack/StackContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ import {
useRenderDebugInfo,
} from 'react-native-screens/private';
import { useParentNavigationEffect } from './hooks/useParentNavigationEffect';
import { useComponentsByName } from '../shared/use-components-by-name';

export function StackContainer({ routeConfigs }: StackContainerProps) {
useSanitizeRouteConfigs(routeConfigs);

const componentsByName = useComponentsByName(routeConfigs);

const [stackNavState, navActionDispatch]: [
StackNavigationState,
React.Dispatch<NavigationAction>,
Expand Down Expand Up @@ -62,7 +65,7 @@ export function StackContainer({ routeConfigs }: StackContainerProps) {
return (
<Stack.Host ref={hostRef}>
{stackNavState.stack.map(
({ Component, options: { headerConfig, ...options }, activityMode, routeKey }) => {
({ options: { headerConfig, ...options }, activityMode, routeKey, name }) => {
const stackNavigationContext: StackNavigationContextPayload = {
routeKey,
routeOptions: { ...options },
Expand All @@ -73,6 +76,13 @@ export function StackContainer({ routeConfigs }: StackContainerProps) {
setRouteOptions: navMethods.setRouteOptions,
};

const Component = componentsByName.get(name);
if (!Component) {
throw new Error(
`[Stack] No config matches the "${name}" route name`,
);
}

return (
<Stack.Screen
key={routeKey}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export type StackRouteConfig = {
options: StackRouteOptions;
};

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

/// StackContainer props
Expand Down
4 changes: 3 additions & 1 deletion apps/src/shared/gamma/containers/stack/reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,10 @@ function createRouteFromConfig(
config: StackRouteConfig,
activityMode: StackScreenActivityMode = 'detached',
): StackRoute {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { Component, ...rest } = config;
Comment on lines +273 to +274
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid the eslint-disable here; it’s better to omit Component without disabling lint (e.g., rename the destructured field to an ignored identifier per lint rules, or explicitly consume it) while still returning ...rest.

Suggested change
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { Component, ...rest } = config;
const { Component: _Component, ...rest } = config;

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave it in the current form, because it's on the example app's side and we also did the same in other places.

return {
...config,
...rest,
activityMode,
routeKey: generateRouteKeyForRouteName(config.name),
isMarkedForDismissal: false,
Expand Down
21 changes: 20 additions & 1 deletion apps/src/shared/gamma/containers/tabs/TabsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from './reducer';
import { RNSLog } from 'react-native-screens/private';
import { TabsContainerItem } from './TabsContainerItem';
import { useComponentsByName } from '../shared/use-components-by-name';

export function TabsContainer(props: TabsContainerProps) {
RNSLog.info('TabsContainer render');
Expand All @@ -34,6 +35,8 @@ export function TabsContainer(props: TabsContainerProps) {

useSanitizeRouteConfigs(routeConfigs);

const componentsByName = useComponentsByName(routeConfigs);

const [tabsNavState, dispatch]: [
TabsContainerState,
React.Dispatch<TabsNavigationAction>,
Expand Down Expand Up @@ -84,7 +87,23 @@ export function TabsContainer(props: TabsContainerProps) {
const pendingForUpdate =
route.routeKey === tabsNavState.suggestedState.selectedRouteKey;

return <TabsContainerItem key={route.routeKey} route={route} navMethods={navMethods} isSelected={isSelected} pendingForUpdate={pendingForUpdate} />
const Component = componentsByName.get(route.name);
if (!Component) {
throw new Error(
`[Tabs] No route config matches the "${route.name}" route name`,
);
}

return (
<TabsContainerItem
key={route.routeKey}
route={route}
navMethods={navMethods}
isSelected={isSelected}
pendingForUpdate={pendingForUpdate}
Component={Component}
/>
);
})}
</Tabs.Host>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type TabRouteConfig = {
/**
* Runtime instance of a tab route. Created from a TabRouteConfig blueprint.
*/
export type TabRoute = TabRouteConfig & {
export type TabRoute = Omit<TabRouteConfig, 'Component'> & {
routeKey: string;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function TabsContainerItemImpl(props: TabsContainerItemProps) {
{...nativeOptions}
screenKey={screenKey}>
<TabsNavigationContext value={tabsNavigationContext}>
{getContent(props.route.Component, safeAreaConfiguration)}
{getContent(props.Component, safeAreaConfiguration)}
</TabsNavigationContext>
</Tabs.Screen>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { TabRoute, TabsNavigationMethods } from './TabsContainer.types';
import React from 'react';

export type TabsContainerItemProps = {
route: TabRoute;
navMethods: TabsNavigationMethods;
isSelected: boolean;
pendingForUpdate: boolean;
}

Component: React.ComponentType;
};
5 changes: 3 additions & 2 deletions apps/src/shared/gamma/containers/tabs/reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ function tabsActionSetOptionsHandler(
}

function createTabRouteFromConfig(config: TabRouteConfig): TabRoute {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { Component, ...rest } = config;
Comment on lines +138 to +139
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using eslint-disable to drop Component from the returned route. A small refactor can keep linting enabled (e.g., rename the destructured field to an underscore-prefixed identifier if that's allowed by the lint config, or explicitly consume it with void), while still omitting it from rest.

Suggested change
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { Component, ...rest } = config;
const { Component, ...rest } = config;
void Component;

Copilot uses AI. Check for mistakes.
return {
...config,
...rest,
// Tab names are required to be unique (enforced by useSanitizeRouteConfigs),
// so the name itself serves as a stable unique key.
routeKey: config.name,
Expand Down Expand Up @@ -205,4 +207,3 @@ function navStateWithConfirmedState(
suggestedState: state.suggestedState,
};
}

Loading