diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 56ae22217e9..061741e9d4d 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -7302,14 +7302,20 @@ public abstract class com/facebook/react/views/text/ReactBaseTextShadowNode : co protected fun spannedFromShadowNode (Lcom/facebook/react/views/text/ReactBaseTextShadowNode;Ljava/lang/String;ZLcom/facebook/react/uimanager/NativeViewHierarchyOptimizer;)Landroid/text/Spannable; } -public class com/facebook/react/views/text/ReactFontManager { - public fun addCustomFont (Landroid/content/Context;Ljava/lang/String;I)V - public fun addCustomFont (Ljava/lang/String;Landroid/graphics/Typeface;)V - public static fun getInstance ()Lcom/facebook/react/views/text/ReactFontManager; - public fun getTypeface (Ljava/lang/String;IILandroid/content/res/AssetManager;)Landroid/graphics/Typeface; - public fun getTypeface (Ljava/lang/String;ILandroid/content/res/AssetManager;)Landroid/graphics/Typeface; - public fun getTypeface (Ljava/lang/String;IZLandroid/content/res/AssetManager;)Landroid/graphics/Typeface; - public fun setTypeface (Ljava/lang/String;ILandroid/graphics/Typeface;)V +public final class com/facebook/react/views/text/ReactFontManager { + public static final field Companion Lcom/facebook/react/views/text/ReactFontManager$Companion; + public synthetic fun (Lcom/facebook/react/views/text/ReactFontManager;Lkotlin/jvm/internal/DefaultConstructorMarker;)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 static final fun getInstance ()Lcom/facebook/react/views/text/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; + public final fun getTypeface (Ljava/lang/String;IZLandroid/content/res/AssetManager;)Landroid/graphics/Typeface; + public final fun setTypeface (Ljava/lang/String;ILandroid/graphics/Typeface;)V +} + +public final class com/facebook/react/views/text/ReactFontManager$Companion { + public final fun getInstance ()Lcom/facebook/react/views/text/ReactFontManager; } public class com/facebook/react/views/text/ReactRawTextManager : com/facebook/react/uimanager/ViewManager { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java deleted file mode 100644 index 0b3310e3f1b..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.views.text; - -import android.content.Context; -import android.content.res.AssetManager; -import android.graphics.Typeface; -import androidx.annotation.Nullable; -import com.facebook.infer.annotation.Nullsafe; - -/** - * Responsible for loading and caching Typeface objects. - * - * @deprecated This class is deprecated and it will be deleted in the near future. Please use {@link - * com.facebook.react.common.assets.ReactFontManager} instead. - */ -@Nullsafe(Nullsafe.Mode.LOCAL) -@Deprecated -public class ReactFontManager { - - private static ReactFontManager sReactFontManagerInstance; - private final com.facebook.react.common.assets.ReactFontManager mDelegate; - - private ReactFontManager(com.facebook.react.common.assets.ReactFontManager delegate) { - mDelegate = delegate; - } - - public static ReactFontManager getInstance() { - if (sReactFontManagerInstance == null) { - sReactFontManagerInstance = - new ReactFontManager(com.facebook.react.common.assets.ReactFontManager.getInstance()); - } - return sReactFontManagerInstance; - } - - public Typeface getTypeface(String fontFamilyName, int style, AssetManager assetManager) { - return mDelegate.getTypeface(fontFamilyName, style, assetManager); - } - - public Typeface getTypeface( - String fontFamilyName, int weight, boolean italic, AssetManager assetManager) { - return mDelegate.getTypeface(fontFamilyName, weight, italic, assetManager); - } - - public Typeface getTypeface( - String fontFamilyName, int style, int weight, AssetManager assetManager) { - return mDelegate.getTypeface(fontFamilyName, style, weight, assetManager); - } - - public void addCustomFont(Context context, String fontFamily, int fontId) { - mDelegate.addCustomFont(context, fontFamily, fontId); - } - - public void addCustomFont(String fontFamily, @Nullable Typeface font) { - mDelegate.addCustomFont(fontFamily, font); - } - - public void setTypeface(String fontFamilyName, int style, Typeface typeface) { - mDelegate.setTypeface(fontFamilyName, style, typeface); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.kt new file mode 100644 index 00000000000..313967c597f --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.kt @@ -0,0 +1,58 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.views.text + +import android.content.Context +import android.content.res.AssetManager +import android.graphics.Typeface + +/** Responsible for loading and caching Typeface objects. */ +@Deprecated( + message = + "This class is deprecated and will be deleted in the near future. Please use [com.facebook.react.common.assets.ReactFontManager] instead.") +@Suppress("DEPRECATION") +public class ReactFontManager private constructor(private val delegate: ReactFontManager) { + + public fun getTypeface(fontFamilyName: String, style: Int, assetManager: AssetManager): Typeface = + delegate.getTypeface(fontFamilyName, style, assetManager) + + public fun getTypeface( + fontFamilyName: String, + weight: Int, + italic: Boolean, + assetManager: AssetManager + ): Typeface = delegate.getTypeface(fontFamilyName, weight, italic, assetManager) + + public fun getTypeface( + fontFamilyName: String, + style: Int, + weight: Int, + assetManager: AssetManager + ): Typeface = delegate.getTypeface(fontFamilyName, style, weight, assetManager) + + public fun addCustomFont(context: Context, fontFamily: String, fontId: Int) { + delegate.addCustomFont(context, fontFamily, fontId) + } + + public fun addCustomFont(fontFamily: String, font: Typeface?) { + delegate.addCustomFont(fontFamily, font) + } + + public fun setTypeface(fontFamilyName: String, style: Int, typeface: Typeface) { + delegate.setTypeface(fontFamilyName, style, typeface) + } + + public companion object { + private var instance: ReactFontManager? = null + + @JvmStatic + public fun getInstance(): ReactFontManager { + return instance ?: ReactFontManager(ReactFontManager.getInstance()).also { instance = it } + } + } +}