Skip to content

feat: enable reading fonts registered via addCustomFont#55711

Closed
vonovak wants to merge 1 commit intofacebook:mainfrom
vonovak:vonovak_feat_enable_reading_fonts_registered_via_addcustomfont
Closed

feat: enable reading fonts registered via addCustomFont#55711
vonovak wants to merge 1 commit intofacebook:mainfrom
vonovak:vonovak_feat_enable_reading_fonts_registered_via_addcustomfont

Conversation

@vonovak
Copy link
Copy Markdown
Contributor

@vonovak vonovak commented Feb 24, 2026

Summary:

ReactFontManager has a write-only API for custom fonts — you can register fonts but there's no way to query what's been registered. This asymmetry means a library that needs to know about font availability needs to use reflection on the private customTypefaceCache map, or maintain a custom registry that can easily go out of sync.

This becomes a problem when multiple libraries need to cooperate around fonts. Today when a library registers a font, there's no clean way for another library to discover what the first one registered.

This adds a customFontFamilies property that returns the set of font family names currently in the custom typeface cache.

Only customTypefaceCache is exposed in this PR because it contains fonts explicitly registered by library code via addCustomFont(), whereas fontCache is lazily populated as a side effect of getTypeface() calls and its contents depend on what has been requested so far rather than what is available.

Asset-based fonts (in assets/fonts/) already have a discoverable source of truth - the filesystem.

Changelog:

[ANDROID] [ADDED] - ReactFontManager.customFontFamilies property to query registered custom font family names

Test Plan:

  • tested ok by adding
    val customFonts = ReactFontManager.getInstance().customFontFamilies
    Log.d("RNTesterApplication", "customFontFamilies: $customFonts")

prints: customFontFamilies: [Rubik, FiraCode]

here

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 24, 2026
@vonovak vonovak marked this pull request as ready for review February 26, 2026 11:38
@github-actions
Copy link
Copy Markdown

Warning

JavaScript API change detected

This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API.

  • Please include a clear changelog message.
  • This change will be subject to additional review.

This change was flagged as: POTENTIALLY_BREAKING

@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Feb 26, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Feb 27, 2026

@javache has imported this pull request. If you are a Meta employee, you can view this in D94665574.

Copy link
Copy Markdown
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync Bot closed this in c3acbc4 Feb 27, 2026
@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Feb 27, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Feb 27, 2026

@javache merged this pull request in c3acbc4.

@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @vonovak in c3acbc4

When will my fix make it into a release? | How to file a pick request?

zoontek pushed a commit to zoontek/react-native that referenced this pull request Mar 9, 2026
Summary:
`ReactFontManager` has a write-only API for custom fonts — you can register fonts but there's no way to query what's been registered. This asymmetry means a library that needs to know about font availability needs to use reflection on the private `customTypefaceCache` map, or maintain a custom registry that can easily go out of sync.

This becomes a problem when multiple libraries need to cooperate around fonts. Today when a library registers a font,  there's no clean way for another library to discover what the first one registered.

This adds a `customFontFamilies` property that returns the set of font family names currently in the custom typeface cache.

Only `customTypefaceCache` is exposed in this PR because it contains fonts explicitly registered by library code  via `addCustomFont()`, whereas `fontCache` is lazily populated as a side effect of `getTypeface()` calls  and its contents depend on what has been requested so far rather than what is available.

Asset-based fonts (in `assets/fonts/`) already have a discoverable source of truth - the filesystem.

## Changelog:

[ANDROID] [ADDED] - `ReactFontManager.customFontFamilies` property to query registered custom font family names

Pull Request resolved: facebook#55711

Test Plan:
- tested ok by adding
```kt
    val customFonts = ReactFontManager.getInstance().customFontFamilies
    Log.d("RNTesterApplication", "customFontFamilies: $customFonts")
```

prints: `customFontFamilies: [Rubik, FiraCode]`

[here](https://github.com/facebook/react-native/blob/9353eb55b877e6e51c35c6041eebd72971c6b9a5/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.kt#L123)

Reviewed By: cortinico

Differential Revision: D94665574

Pulled By: javache

fbshipit-source-id: 07d802ac98f4a738858038a2af6ce8d85c28b5ce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Expo Partner: Expo Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants