Skip to content

Commit 14ea049

Browse files
authored
fix: appearance issues with dark mode switches on Android (#316)
* fix: appearance issues with dark mode switches on Android * Create ninety-garlics-bow.md
1 parent 3d0ac88 commit 14ea049

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

.changeset/ninety-garlics-bow.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: appearance issues with dark mode switches on Android

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
5656
private var fontSize: Int? = null
5757
private var fontFamily: String? = null
5858
private var fontWeight: Int? = null
59+
private var labeled: Boolean? = null
5960
private var lastReportedSize: Size? = null
6061
private var hasCustomAppearance = false
6162
private var uiModeConfiguration: Int = Configuration.UI_MODE_NIGHT_UNDEFINED
@@ -250,7 +251,6 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
250251
}
251252
view.setOnClickListener {
252253
onTabSelected(menuItem)
253-
updateTintColors(menuItem)
254254
}
255255

256256
item.testID?.let { testId ->
@@ -260,10 +260,13 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
260260
}
261261
}
262262
}
263-
updateTextAppearance()
264-
updateTintColors()
265263
}
266264
}
265+
// Update tint colors and text appearance after updating all items.
266+
post {
267+
updateTextAppearance()
268+
updateTintColors()
269+
}
267270
}
268271

269272
private fun getOrCreateItem(index: Int, title: String): MenuItem {
@@ -295,6 +298,7 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
295298
}
296299

297300
fun setLabeled(labeled: Boolean?) {
301+
this.labeled = labeled
298302
bottomNavigation.labelVisibilityMode = when (labeled) {
299303
false -> {
300304
LABEL_VISIBILITY_UNLABELED
@@ -310,7 +314,6 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
310314

311315
fun setRippleColor(color: ColorStateList) {
312316
bottomNavigation.itemRippleColor = color
313-
hasCustomAppearance = true
314317
}
315318

316319
@SuppressLint("CheckResult")
@@ -354,18 +357,15 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
354357
fun setActiveTintColor(color: Int?) {
355358
activeTintColor = color
356359
updateTintColors()
357-
hasCustomAppearance = true
358360
}
359361

360362
fun setInactiveTintColor(color: Int?) {
361363
inactiveTintColor = color
362364
updateTintColors()
363-
hasCustomAppearance = true
364365
}
365366

366367
fun setActiveIndicatorColor(color: ColorStateList) {
367368
bottomNavigation.itemActiveIndicatorColor = color
368-
hasCustomAppearance = true
369369
}
370370

371371
fun setFontSize(size: Int) {
@@ -421,11 +421,9 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
421421
}
422422
}
423423

424-
private fun updateTintColors(item: MenuItem? = null) {
424+
private fun updateTintColors() {
425425
// First let's check current item color.
426-
val currentItemTintColor = item?.itemId?.let { itemId ->
427-
items[itemId].activeTintColor
428-
}
426+
val currentItemTintColor = items.first { it.key == selectedItem }.activeTintColor
429427

430428
// getDefaultColor will always return a valid color but to satisfy the compiler we need to check for null
431429
val colorPrimary = currentItemTintColor ?: activeTintColor ?: Utils.getDefaultColorFor(
@@ -457,6 +455,8 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
457455
bottomNavigation = BottomNavigationView(context)
458456
addView(bottomNavigation)
459457
updateItems(items)
458+
setLabeled(this.labeled)
459+
this.selectedItem?.let { setSelectedItem(it) }
460460
uiModeConfiguration = newConfig?.uiMode ?: uiModeConfiguration
461461
}
462462
}

0 commit comments

Comments
 (0)