Skip to content

Apply typeface and size individually in android text appearance. #393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2025
Merged
Changes from 1 commit
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 @@ -399,27 +399,34 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
}

private fun updateTextAppearance() {
if (fontSize != null || fontFamily != null || fontWeight != null) {
val menuView = bottomNavigation.getChildAt(0) as? ViewGroup ?: return
val size = fontSize?.toFloat()?.takeIf { it > 0 } ?: 12f
val typeface = ReactFontManager.getInstance().getTypeface(
// Early return if there is no custom text appearance
if (fontSize == null && fontFamily == null && fontWeight == null) {
return
}

val typeface = if (fontFamily != null || fontWeight != null) {
ReactFontManager.getInstance().getTypeface(
fontFamily ?: "",
Utils.getTypefaceStyle(fontWeight),
context.assets
)

for (i in 0 until menuView.childCount) {
val item = menuView.getChildAt(i)
val largeLabel =
item.findViewById<TextView>(com.google.android.material.R.id.navigation_bar_item_large_label_view)
val smallLabel =
item.findViewById<TextView>(com.google.android.material.R.id.navigation_bar_item_small_label_view)

listOf(largeLabel, smallLabel).forEach { label ->
label?.apply {
} else null
val size = fontSize?.toFloat()?.takeIf { it > 0 }

val menuView = bottomNavigation.getChildAt(0) as? ViewGroup ?: return
for (i in 0 until menuView.childCount) {
val item = menuView.getChildAt(i)
val largeLabel =
item.findViewById<TextView>(com.google.android.material.R.id.navigation_bar_item_large_label_view)
val smallLabel =
item.findViewById<TextView>(com.google.android.material.R.id.navigation_bar_item_small_label_view)

listOf(largeLabel, smallLabel).forEach { label ->
label?.apply {
size?.let { size ->
setTextSize(TypedValue.COMPLEX_UNIT_SP, size)
setTypeface(typeface)
}
typeface?.let { setTypeface(it) }
}
}
}
Expand Down
Loading