Skip to content

Commit 2b70882

Browse files
authored
fix(android): add missing badgeBackgroundColor and badgeTextColor to TabInfo (#482)
* fix(android): add missing badgeBackgroundColor and badgeTextColor to TabInfo The TabInfo data class was missing badgeBackgroundColor and badgeTextColor properties that RCTTabView.kt expects when applying badge colors. This caused Android builds to fail with: - Unresolved reference 'badgeBackgroundColor' - Unresolved reference 'badgeTextColor' - Unresolved reference 'colorError' Changes: - Add badgeBackgroundColor and badgeTextColor properties to TabInfo data class - Populate them from JS bridge in setItems() - Simplify badge color application to let Material use default theme colors when custom colors are not provided (avoids colorError resolution issues) Fixes #481 * chore: add changeset
1 parent 3a21e31 commit 2b70882

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed
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(android): add missing badgeBackgroundColor and badgeTextColor to TabInfo data class

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

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -256,31 +256,9 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
256256
if (item.badge != " ") {
257257
badge.text = item.badge
258258
}
259-
// Apply badge colors if provided, or reset to theme defaults if null
260-
if (item.badgeBackgroundColor != null) {
261-
badge.backgroundColor = item.badgeBackgroundColor
262-
} else {
263-
// Reset to theme default color by resolving the colorError attribute
264-
val typedValue = TypedValue()
265-
context.theme.resolveAttribute(
266-
com.google.android.material.R.attr.colorError,
267-
typedValue,
268-
true
269-
)
270-
badge.backgroundColor = typedValue.data
271-
}
272-
if (item.badgeTextColor != null) {
273-
badge.badgeTextColor = item.badgeTextColor
274-
} else {
275-
// Reset to theme default text color by resolving the colorOnError attribute
276-
val typedValue = TypedValue()
277-
context.theme.resolveAttribute(
278-
com.google.android.material.R.attr.colorOnError,
279-
typedValue,
280-
true
281-
)
282-
badge.badgeTextColor = typedValue.data
283-
}
259+
// Apply badge colors if provided (Material will use its default theme colors otherwise)
260+
item.badgeBackgroundColor?.let { badge.backgroundColor = it }
261+
item.badgeTextColor?.let { badge.badgeTextColor = it }
284262
} else {
285263
bottomNavigation.removeBadge(index)
286264
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ data class TabInfo(
2121
val key: String,
2222
val title: String,
2323
val badge: String?,
24+
val badgeBackgroundColor: Int?,
25+
val badgeTextColor: Int?,
2426
val activeTintColor: Int?,
2527
val hidden: Boolean,
2628
val testID: String?
@@ -99,6 +101,8 @@ class RCTTabViewManager(context: ReactApplicationContext) :
99101
key = item.getString("key") ?: "",
100102
title = item.getString("title") ?: "",
101103
badge = if (item.hasKey("badge")) item.getString("badge") else null,
104+
badgeBackgroundColor = if (item.hasKey("badgeBackgroundColor")) item.getInt("badgeBackgroundColor") else null,
105+
badgeTextColor = if (item.hasKey("badgeTextColor")) item.getInt("badgeTextColor") else null,
102106
activeTintColor = if (item.hasKey("activeTintColor")) item.getInt("activeTintColor") else null,
103107
hidden = if (item.hasKey("hidden")) item.getBoolean("hidden") else false,
104108
testID = item.getString("testID")

0 commit comments

Comments
 (0)