Commit c3acbc4
feat: enable reading fonts registered via addCustomFont (#55711)
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: #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: 07d802ac98f4a738858038a2af6ce8d85c28b5ce1 parent f88946d commit c3acbc4
2 files changed
Lines changed: 5 additions & 0 deletions
File tree
- packages/react-native/ReactAndroid
- api
- src/main/java/com/facebook/react/common/assets
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1667 | 1667 | | |
1668 | 1668 | | |
1669 | 1669 | | |
| 1670 | + | |
1670 | 1671 | | |
1671 | 1672 | | |
1672 | 1673 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
| |||
0 commit comments