Skip to content
Closed
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,9 +11,11 @@ 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
import com.facebook.react.common.build.ReactBuildConfig

/**
* Responsible for loading and caching Typeface objects.
Expand Down Expand Up @@ -162,6 +164,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 +188,16 @@ public class ReactFontManager {
}
}
}
return Typeface.create(fontFamilyName, style)

val typeface = Typeface.create(fontFamilyName, style)
// Like RCTLogInfo on iOS, only log in debug builds.
if (ReactBuildConfig.DEBUG) {
// Typeface.create returns the default typeface for unknown family names.
if (fontFamilyName != DEFAULT_FAMILY && typeface == Typeface.defaultFromStyle(style)) {
Log.i(ReactConstants.TAG, "Unrecognized font family '$fontFamilyName'")
}
}
return typeface
}
}

Expand Down
Loading