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 9e4726e5de0ce0..bfeb9295f1255a 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 @@ -18,7 +18,7 @@ import androidx.annotation.RequiresApi; import androidx.core.content.res.ResourcesCompat; import com.facebook.infer.annotation.Nullsafe; -import com.facebook.react.bridge.Callback; +import androidx.arch.core.util.Function; import java.io.IOException; import java.util.ArrayList; @@ -26,6 +26,19 @@ import java.util.List; import java.util.Map; +class CreateTypefaceObject { + public String fontFamilyName; + public int style; + public AssetManager assetManager; + + public CreateTypefaceObject( + String fontFamilyName, int style, AssetManager assetManager) { + this.fontFamilyName = fontFamilyName; + this.style = style; + this.assetManager = assetManager; + } +} + /** * Responsible for loading and caching Typeface objects. * @@ -43,7 +56,7 @@ */ @Nullsafe(Nullsafe.Mode.LOCAL) public class ReactFontManager { - public static Callback createAssetTypefaceOverride = null; + public static Function createAssetTypefaceOverride = null; // NOTE: Indices in `EXTENSIONS` correspond to the `TypeFace` style constants. private static final String[] EXTENSIONS = {"", "_bold", "_italic", "_bold_italic"}; @@ -153,7 +166,9 @@ public void setTypeface(String fontFamilyName, int style, Typeface typeface) { private static Typeface createAssetTypeface( String fontFamilyName, int style, AssetManager assetManager) { if (createAssetTypefaceOverride != null) { - return createAssetTypefaceOverride.invoke(fontFamilyName, style, assetManager); + return createAssetTypefaceOverride.apply( + new CreateTypefaceObject(fontFamilyName, style, assetManager) + ); } String extension = EXTENSIONS[style];