From c3acbc424da9b044957d5a35c4a2d4a1254a3729 Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Fri, 27 Feb 2026 09:06:18 -0800 Subject: [PATCH] feat: enable reading fonts registered via addCustomFont (#55711) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- packages/react-native/ReactAndroid/api/ReactAndroid.api | 1 + .../java/com/facebook/react/common/assets/ReactFontManager.kt | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 2df4bc4d9ce..aa732ba8fbb 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -1667,6 +1667,7 @@ public final class com/facebook/react/common/assets/ReactFontManager { public fun ()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; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/assets/ReactFontManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/assets/ReactFontManager.kt index 8850773c4e9..c639b76c3a6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/assets/ReactFontManager.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/assets/ReactFontManager.kt @@ -33,6 +33,10 @@ public class ReactFontManager { private val fontCache: MutableMap = mutableMapOf() private val customTypefaceCache: MutableMap = mutableMapOf() + /** The set of font family names that have been registered via [addCustomFont]. */ + public val customFontFamilies: Set + get() = customTypefaceCache.keys.toSet() + public fun getTypeface( fontFamilyName: String, style: Int,