Skip to content

Commit 44dd50d

Browse files
Apply typeface and size individually in android text appearance. (#393)
* Apply typeface and size individually in android text appearance. * Create bright-windows-sip.md --------- Co-authored-by: Oskar Kwaśniewski <oskarkwasniewski@icloud.com>
1 parent 27e5fa2 commit 44dd50d

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

.changeset/bright-windows-sip.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-native-bottom-tabs": patch
3+
---
4+
5+
fix: apply typeface and size individually in android text appearance.

packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabView.kt

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -399,27 +399,34 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
399399
}
400400

401401
private fun updateTextAppearance() {
402-
if (fontSize != null || fontFamily != null || fontWeight != null) {
403-
val menuView = bottomNavigation.getChildAt(0) as? ViewGroup ?: return
404-
val size = fontSize?.toFloat()?.takeIf { it > 0 } ?: 12f
405-
val typeface = ReactFontManager.getInstance().getTypeface(
402+
// Early return if there is no custom text appearance
403+
if (fontSize == null && fontFamily == null && fontWeight == null) {
404+
return
405+
}
406+
407+
val typeface = if (fontFamily != null || fontWeight != null) {
408+
ReactFontManager.getInstance().getTypeface(
406409
fontFamily ?: "",
407410
Utils.getTypefaceStyle(fontWeight),
408411
context.assets
409412
)
410-
411-
for (i in 0 until menuView.childCount) {
412-
val item = menuView.getChildAt(i)
413-
val largeLabel =
414-
item.findViewById<TextView>(com.google.android.material.R.id.navigation_bar_item_large_label_view)
415-
val smallLabel =
416-
item.findViewById<TextView>(com.google.android.material.R.id.navigation_bar_item_small_label_view)
417-
418-
listOf(largeLabel, smallLabel).forEach { label ->
419-
label?.apply {
413+
} else null
414+
val size = fontSize?.toFloat()?.takeIf { it > 0 }
415+
416+
val menuView = bottomNavigation.getChildAt(0) as? ViewGroup ?: return
417+
for (i in 0 until menuView.childCount) {
418+
val item = menuView.getChildAt(i)
419+
val largeLabel =
420+
item.findViewById<TextView>(com.google.android.material.R.id.navigation_bar_item_large_label_view)
421+
val smallLabel =
422+
item.findViewById<TextView>(com.google.android.material.R.id.navigation_bar_item_small_label_view)
423+
424+
listOf(largeLabel, smallLabel).forEach { label ->
425+
label?.apply {
426+
size?.let { size ->
420427
setTextSize(TypedValue.COMPLEX_UNIT_SP, size)
421-
setTypeface(typeface)
422428
}
429+
typeface?.let { setTypeface(it) }
423430
}
424431
}
425432
}

0 commit comments

Comments
 (0)