Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.content.Context
import android.content.res.AssetManager
import android.graphics.Typeface
import android.os.Build
import android.util.Log
import android.util.SparseArray
import androidx.core.content.res.ResourcesCompat
import com.facebook.react.common.ReactConstants
Expand Down Expand Up @@ -162,6 +163,8 @@ public class ReactFontManager {
private val EXTENSIONS = arrayOf("", "_bold", "_italic", "_bold_italic")
private val FILE_EXTENSIONS = arrayOf(".ttf", ".otf")
private const val FONTS_ASSET_PATH = "fonts/"
// Android's default font family.
private const val DEFAULT_FAMILY = "sans-serif"

private val _instance = ReactFontManager()

Expand All @@ -184,7 +187,13 @@ public class ReactFontManager {
}
}
}
return Typeface.create(fontFamilyName, style)

val typeface = Typeface.create(fontFamilyName, style)
// Typeface.create returns the default typeface for unknown family names.
if (fontFamilyName != DEFAULT_FAMILY && typeface == Typeface.defaultFromStyle(style)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're now paying an extra cost to create an extra Typeface, just to log this warning. That doesn't seem like a good tradeoff.

Log.i(ReactConstants.TAG, "Unrecognized font family '$fontFamilyName'")
}
return typeface
}
}

Expand Down
Loading