|
1 | 1 | package com.rcttabview |
2 | 2 |
|
3 | | -import android.R.attr |
4 | 3 | import android.content.Context |
5 | 4 | import android.content.res.ColorStateList |
6 | 5 | import android.graphics.drawable.BitmapDrawable |
@@ -145,33 +144,29 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context |
145 | 144 | } |
146 | 145 |
|
147 | 146 | private fun updateTintColors() { |
148 | | - if (activeTintColor == null || inactiveTintColor == null) { |
149 | | - return; |
150 | | - } |
| 147 | + val activeColor = activeTintColor ?: return |
| 148 | + val inactiveColor = inactiveTintColor ?: return |
151 | 149 |
|
152 | 150 | 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) |
159 | 153 | ) |
160 | 154 |
|
161 | | - this.itemTextColor = ColorStateList(states, colors) |
| 155 | + val colors = intArrayOf(inactiveColor, activeColor) |
162 | 156 |
|
163 | | - this.itemIconTintList = ColorStateList( |
164 | | - states, colors |
165 | | - ) |
| 157 | + ColorStateList(states, colors).apply { |
| 158 | + this@ReactBottomNavigationView.itemTextColor = this |
| 159 | + this@ReactBottomNavigationView.itemIconTintList = this |
| 160 | + } |
166 | 161 | } |
167 | 162 |
|
168 | 163 | fun setActiveTintColor(color: Int?) { |
169 | | - activeTintColor = color |
170 | | - this.updateTintColors() |
| 164 | + activeTintColor = color |
| 165 | + updateTintColors() |
171 | 166 | } |
172 | 167 |
|
173 | 168 | fun setInactiveTintColor(color: Int?) { |
174 | | - inactiveTintColor = color |
175 | | - this.updateTintColors() |
| 169 | + inactiveTintColor = color |
| 170 | + updateTintColors() |
176 | 171 | } |
177 | 172 | } |
0 commit comments