From e2dd2e2a6ed17b366a3e2ec0942ea1d82a404c5d Mon Sep 17 00:00:00 2001 From: Derek Thurn Date: Fri, 13 May 2022 12:42:32 -0700 Subject: [PATCH] Allows a Typeface object to be added to ReactFontManager Summary: Currently on Android, React Native can only accept font resource IDs which it internally converts into Typeface objects. This change allows ReactFontManager to be passed a Typeface at runtime to enable e.g. downloading fonts on demand. Changelog: [Android][Added] - Ability to pass a Typeface object to ReactFontManager in addition to a font resource ID Reviewed By: makovkastar Differential Revision: D36138123 fbshipit-source-id: b314e8c7fc28174b5caa017076b6eb3d4f6dbaa8 --- .../facebook/react/views/text/ReactFontManager.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java index d81490fd82cb25..c7dc9b34265a4e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java @@ -110,6 +110,16 @@ public void addCustomFont(Context context, String fontFamily, int fontId) { } } + /** + * Equivalent method to {@see addCustomFont(Context, String, int)} which accepts a Typeface + * object. + */ + public void addCustomFont(String fontFamily, @Nullable Typeface font) { + if (font != null) { + mCustomTypefaceCache.put(fontFamily, font); + } + } + /** * Add additional font family, or replace the exist one in the font memory cache. *