Skip to content

fix: keep navigation theme type when adapting a single theme - #5136

Open
huytdps13400 wants to merge 1 commit into
callstack:mainfrom
huytdps13400:fix/adapt-navigation-theme-single-type
Open

huytdps13400 wants to merge 1 commit into
callstack:mainfrom
huytdps13400:fix/adapt-navigation-theme-single-type

Conversation

@huytdps13400

Copy link
Copy Markdown

Motivation

adaptNavigationTheme called with only reactNavigationLight (or only reactNavigationDark) is typed to return the narrow NavigationTheme, so fonts and any extra colors of the passed theme are lost at the type level, even though they are preserved at runtime. The result can't be passed to NavigationContainer:

Property 'fonts' is missing in type 'NavigationTheme' but required in type 'Theme'. ts(2741)

Root cause: the two single-theme overloads declare LightTheme: NavigationTheme / DarkTheme: NavigationTheme, while the overload taking both themes already returns the generic input types (TLight / TDark). This PR makes the single-theme overloads return T as well. It's a type-only change; runtime behavior is unchanged. T extends NavigationTheme, so existing code that expects NavigationTheme keeps compiling.

Related issue

Fixes #4751

Screenshots / Videos

N/A (types only)

Test plan

  • Added should keep fonts and custom colors when adapting a single theme to src/core/__tests__/theming.test.tsx. It reads fonts and a custom color from the result of a light-only and a dark-only call.
    • Before: yarn typecheck fails with TS2339: Property 'fonts' does not exist on type 'NavigationTheme' (and the same for colors.secondary).
    • After: yarn typecheck passes.
  • Also checked by hand against the real React Navigation types: const t: Theme = adaptNavigationTheme({ reactNavigationLight: DefaultTheme }).LightTheme (from @react-navigation/native). It fails with the TS2741 error above on main and compiles with this change.
  • yarn typecheck, yarn lint (changed files) and yarn test all pass (54 suites, 693 tests).

Platforms affected: all (TypeScript types only).

This fix was prepared with AI assistance (Claude Code) and verified locally with the tests above.

🤖 Generated with Claude Code

The light-only and dark-only overloads of adaptNavigationTheme returned the
narrow NavigationTheme type, dropping `fonts` and custom colors from the
input theme even though they are preserved at runtime. This made the result
unassignable to React Navigation's Theme. Return the input theme type, as
the overload for both themes already does.

Fixes callstack#4751

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Found potential problems with the pull request:

  • The description is too long. Please keep it under 1000 characters.
  • Screenshot or video evidence is missing. Make sure to include one if it affects the UI.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing fonts in NavigationTheme type

1 participant