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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
Vojtech Novak authored and meta-codesync[bot] committed 2026-02-27 09:06:18 -08:00
1 parent f88946d2a2
commit c3acbc424d
2 files changed
+5

No files matched your search

@@ -1667,6 +1667,7 @@ public final class com/facebook/react/common/assets/ReactFontManager {
public fun <init> ()V
public final fun addCustomFont (Landroid/content/Context;Ljava/lang/String;I)V
public final fun addCustomFont (Ljava/lang/String;Landroid/graphics/Typeface;)V
public final fun getCustomFontFamilies ()Ljava/util/Set;
public static final fun getInstance ()Lcom/facebook/react/common/assets/ReactFontManager;
public final fun getTypeface (Ljava/lang/String;IILandroid/content/res/AssetManager;)Landroid/graphics/Typeface;
public final fun getTypeface (Ljava/lang/String;ILandroid/content/res/AssetManager;)Landroid/graphics/Typeface;
@@ -33,6 +33,10 @@ public class ReactFontManager {
private val fontCache: MutableMap<String, AssetFontFamily> = mutableMapOf()
private val customTypefaceCache: MutableMap<String, Typeface> = mutableMapOf()
/** The set of font family names that have been registered via [addCustomFont]. */
public val customFontFamilies: Set<String>
get() = customTypefaceCache.keys.toSet()
public fun getTypeface(
fontFamilyName: String,
style: Int,