@@ -56,6 +56,7 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
56
56
private var fontSize: Int? = null
57
57
private var fontFamily: String? = null
58
58
private var fontWeight: Int? = null
59
+ private var labeled: Boolean? = null
59
60
private var lastReportedSize: Size ? = null
60
61
private var hasCustomAppearance = false
61
62
private var uiModeConfiguration: Int = Configuration .UI_MODE_NIGHT_UNDEFINED
@@ -250,7 +251,6 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
250
251
}
251
252
view.setOnClickListener {
252
253
onTabSelected(menuItem)
253
- updateTintColors(menuItem)
254
254
}
255
255
256
256
item.testID?.let { testId ->
@@ -260,10 +260,13 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
260
260
}
261
261
}
262
262
}
263
- updateTextAppearance()
264
- updateTintColors()
265
263
}
266
264
}
265
+ // Update tint colors and text appearance after updating all items.
266
+ post {
267
+ updateTextAppearance()
268
+ updateTintColors()
269
+ }
267
270
}
268
271
269
272
private fun getOrCreateItem (index : Int , title : String ): MenuItem {
@@ -295,6 +298,7 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
295
298
}
296
299
297
300
fun setLabeled (labeled : Boolean? ) {
301
+ this .labeled = labeled
298
302
bottomNavigation.labelVisibilityMode = when (labeled) {
299
303
false -> {
300
304
LABEL_VISIBILITY_UNLABELED
@@ -310,7 +314,6 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
310
314
311
315
fun setRippleColor (color : ColorStateList ) {
312
316
bottomNavigation.itemRippleColor = color
313
- hasCustomAppearance = true
314
317
}
315
318
316
319
@SuppressLint(" CheckResult" )
@@ -354,18 +357,15 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
354
357
fun setActiveTintColor (color : Int? ) {
355
358
activeTintColor = color
356
359
updateTintColors()
357
- hasCustomAppearance = true
358
360
}
359
361
360
362
fun setInactiveTintColor (color : Int? ) {
361
363
inactiveTintColor = color
362
364
updateTintColors()
363
- hasCustomAppearance = true
364
365
}
365
366
366
367
fun setActiveIndicatorColor (color : ColorStateList ) {
367
368
bottomNavigation.itemActiveIndicatorColor = color
368
- hasCustomAppearance = true
369
369
}
370
370
371
371
fun setFontSize (size : Int ) {
@@ -421,11 +421,9 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
421
421
}
422
422
}
423
423
424
- private fun updateTintColors (item : MenuItem ? = null ) {
424
+ private fun updateTintColors () {
425
425
// 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
429
427
430
428
// getDefaultColor will always return a valid color but to satisfy the compiler we need to check for null
431
429
val colorPrimary = currentItemTintColor ? : activeTintColor ? : Utils .getDefaultColorFor(
@@ -457,6 +455,8 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
457
455
bottomNavigation = BottomNavigationView (context)
458
456
addView(bottomNavigation)
459
457
updateItems(items)
458
+ setLabeled(this .labeled)
459
+ this .selectedItem?.let { setSelectedItem(it) }
460
460
uiModeConfiguration = newConfig?.uiMode ? : uiModeConfiguration
461
461
}
462
462
}
0 commit comments