diff --git a/.changeset/bright-windows-sip.md b/.changeset/bright-windows-sip.md new file mode 100644 index 00000000..8108d184 --- /dev/null +++ b/.changeset/bright-windows-sip.md @@ -0,0 +1,5 @@ +--- +"react-native-bottom-tabs": patch +--- + +fix: apply typeface and size individually in android text appearance. diff --git a/packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabView.kt b/packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabView.kt index 41547fd1..1e1040eb 100644 --- a/packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabView.kt +++ b/packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabView.kt @@ -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(com.google.android.material.R.id.navigation_bar_item_large_label_view) - val smallLabel = - item.findViewById(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(com.google.android.material.R.id.navigation_bar_item_large_label_view) + val smallLabel = + item.findViewById(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) } } } }