Skip to content

Commit 7aa0423

Browse files
author
Muhammed Ibrahim
committed
refactor(android): update updateTintColors to use more kotlin features
1 parent 96bacba commit 7aa0423

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

android/src/main/java/com/rcttabview/RCTTabView.kt

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.rcttabview
22

3-
import android.R.attr
43
import android.content.Context
54
import android.content.res.ColorStateList
65
import android.graphics.drawable.BitmapDrawable
@@ -145,33 +144,29 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
145144
}
146145

147146
private fun updateTintColors() {
148-
if (activeTintColor == null || inactiveTintColor == null) {
149-
return;
150-
}
147+
val activeColor = activeTintColor ?: return
148+
val inactiveColor = inactiveTintColor ?: return
151149

152150
val states = arrayOf(
153-
intArrayOf(-attr.state_checked),
154-
intArrayOf(attr.state_checked)
155-
)
156-
val colors = intArrayOf(
157-
inactiveTintColor as Int,
158-
activeTintColor as Int
151+
intArrayOf(-android.R.attr.state_checked),
152+
intArrayOf(android.R.attr.state_checked)
159153
)
160154

161-
this.itemTextColor = ColorStateList(states, colors)
155+
val colors = intArrayOf(inactiveColor, activeColor)
162156

163-
this.itemIconTintList = ColorStateList(
164-
states, colors
165-
)
157+
ColorStateList(states, colors).apply {
158+
this@ReactBottomNavigationView.itemTextColor = this
159+
this@ReactBottomNavigationView.itemIconTintList = this
160+
}
166161
}
167162

168163
fun setActiveTintColor(color: Int?) {
169-
activeTintColor = color
170-
this.updateTintColors()
164+
activeTintColor = color
165+
updateTintColors()
171166
}
172167

173168
fun setInactiveTintColor(color: Int?) {
174-
inactiveTintColor = color
175-
this.updateTintColors()
169+
inactiveTintColor = color
170+
updateTintColors()
176171
}
177172
}

0 commit comments

Comments
 (0)