diff --git a/.changeset/fix-android-badge-colors.md b/.changeset/fix-android-badge-colors.md new file mode 100644 index 00000000..9fdd545f --- /dev/null +++ b/.changeset/fix-android-badge-colors.md @@ -0,0 +1,5 @@ +--- +"react-native-bottom-tabs": patch +--- + +fix(android): add missing badgeBackgroundColor and badgeTextColor to TabInfo data class 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 9ed6de7a..23cd8759 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 @@ -256,31 +256,9 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) { if (item.badge != " ") { badge.text = item.badge } - // Apply badge colors if provided, or reset to theme defaults if null - if (item.badgeBackgroundColor != null) { - badge.backgroundColor = item.badgeBackgroundColor - } else { - // Reset to theme default color by resolving the colorError attribute - val typedValue = TypedValue() - context.theme.resolveAttribute( - com.google.android.material.R.attr.colorError, - typedValue, - true - ) - badge.backgroundColor = typedValue.data - } - if (item.badgeTextColor != null) { - badge.badgeTextColor = item.badgeTextColor - } else { - // Reset to theme default text color by resolving the colorOnError attribute - val typedValue = TypedValue() - context.theme.resolveAttribute( - com.google.android.material.R.attr.colorOnError, - typedValue, - true - ) - badge.badgeTextColor = typedValue.data - } + // Apply badge colors if provided (Material will use its default theme colors otherwise) + item.badgeBackgroundColor?.let { badge.backgroundColor = it } + item.badgeTextColor?.let { badge.badgeTextColor = it } } else { bottomNavigation.removeBadge(index) } diff --git a/packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabViewManager.kt b/packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabViewManager.kt index d2b97dc1..dad16c28 100644 --- a/packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabViewManager.kt +++ b/packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabViewManager.kt @@ -21,6 +21,8 @@ data class TabInfo( val key: String, val title: String, val badge: String?, + val badgeBackgroundColor: Int?, + val badgeTextColor: Int?, val activeTintColor: Int?, val hidden: Boolean, val testID: String? @@ -99,6 +101,8 @@ class RCTTabViewManager(context: ReactApplicationContext) : key = item.getString("key") ?: "", title = item.getString("title") ?: "", badge = if (item.hasKey("badge")) item.getString("badge") else null, + badgeBackgroundColor = if (item.hasKey("badgeBackgroundColor")) item.getInt("badgeBackgroundColor") else null, + badgeTextColor = if (item.hasKey("badgeTextColor")) item.getInt("badgeTextColor") else null, activeTintColor = if (item.hasKey("activeTintColor")) item.getInt("activeTintColor") else null, hidden = if (item.hasKey("hidden")) item.getBoolean("hidden") else false, testID = item.getString("testID")