@@ -23,20 +23,18 @@ import com.facebook.react.bridge.ReadableArray
23
23
import com.facebook.react.bridge.WritableMap
24
24
import com.facebook.react.common.assets.ReactFontManager
25
25
import com.facebook.react.modules.core.ReactChoreographer
26
- import com.facebook.react.views.imagehelper.ImageSource
27
26
import com.facebook.react.views.text.ReactTypefaceUtils
28
27
import com.google.android.material.bottomnavigation.BottomNavigationView
29
28
import coil3.request.ImageRequest
30
29
import coil3.svg.SvgDecoder
31
30
32
31
33
32
class ReactBottomNavigationView (context : Context ) : BottomNavigationView(context) {
34
- private val icons : MutableMap <Int , ImageSource > = mutableMapOf ()
33
+ private val iconSources : MutableMap <Int , ImageSource > = mutableMapOf ()
35
34
private var isLayoutEnqueued = false
36
35
var items: MutableList <TabInfo >? = null
37
36
var onTabSelectedListener: ((WritableMap ) -> Unit )? = null
38
37
var onTabLongPressedListener: ((WritableMap ) -> Unit )? = null
39
- private var isAnimating = false
40
38
private var activeTintColor: Int? = null
41
39
private var inactiveTintColor: Int? = null
42
40
private val checkedStateSet = intArrayOf(android.R .attr.state_checked)
@@ -91,7 +89,7 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
91
89
92
90
private fun onTabSelected (item : MenuItem ) {
93
91
if (isLayoutEnqueued) {
94
- return ;
92
+ return
95
93
}
96
94
val selectedItem = items?.first { it.title == item.title }
97
95
selectedItem?.let {
@@ -108,8 +106,8 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
108
106
items.forEachIndexed { index, item ->
109
107
val menuItem = getOrCreateItem(index, item.title)
110
108
menuItem.isVisible = ! item.hidden
111
- if (icons .containsKey(index)) {
112
- getDrawable(icons [index]!! ) {
109
+ if (iconSources .containsKey(index)) {
110
+ getDrawable(iconSources [index]!! ) {
113
111
menuItem.icon = it
114
112
}
115
113
}
@@ -150,12 +148,9 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
150
148
if (uri.isNullOrEmpty()) {
151
149
continue
152
150
}
153
- val imageSource =
154
- ImageSource (
155
- context,
156
- uri
157
- )
158
- this .icons[idx] = imageSource
151
+
152
+ val imageSource = ImageSource (context, uri)
153
+ this .iconSources[idx] = imageSource
159
154
160
155
// Update existing item if exists.
161
156
menu.findItem(idx)?.let { menuItem ->
@@ -183,7 +178,7 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
183
178
@SuppressLint(" CheckResult" )
184
179
private fun getDrawable (imageSource : ImageSource , onDrawableReady : (Drawable ? ) -> Unit ) {
185
180
val request = ImageRequest .Builder (context)
186
- .data(imageSource.uri )
181
+ .data(imageSource.getUri(context) )
187
182
.target { drawable ->
188
183
post { onDrawableReady(drawable.asDrawable(context.resources)) }
189
184
}
@@ -197,11 +192,6 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
197
192
imageLoader.enqueue(request)
198
193
}
199
194
200
- override fun onDetachedFromWindow () {
201
- super .onDetachedFromWindow()
202
- isAnimating = false
203
- }
204
-
205
195
fun setBarTintColor (color : Int? ) {
206
196
// Set the color, either using the active background color or a default color.
207
197
val backgroundColor = color ? : getDefaultColorFor(android.R .attr.colorPrimary) ? : return
@@ -241,10 +231,10 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
241
231
updateTextAppearance()
242
232
}
243
233
244
- fun setFontWeight (weight : String? ) {
245
- val fontWeight = ReactTypefaceUtils .parseFontWeight(weight)
246
- this .fontWeight = fontWeight
247
- updateTextAppearance()
234
+ fun setFontWeight (weight : String? ) {
235
+ val fontWeight = ReactTypefaceUtils .parseFontWeight(weight)
236
+ this .fontWeight = fontWeight
237
+ updateTextAppearance()
248
238
}
249
239
250
240
private fun getTypefaceStyle (weight : Int? ) = when (weight) {
@@ -289,7 +279,7 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
289
279
// First let's check current item color.
290
280
val currentItemTintColor = items?.find { it.title == item?.title }?.activeTintColor
291
281
292
- // getDeaultColor will always return a valid color but to satisfy the compiler we need to check for null
282
+ // getDefaultColor will always return a valid color but to satisfy the compiler we need to check for null
293
283
val colorPrimary = currentItemTintColor ? : activeTintColor ? : getDefaultColorFor(android.R .attr.colorPrimary) ? : return
294
284
val colorSecondary =
295
285
inactiveTintColor ? : getDefaultColorFor(android.R .attr.textColorSecondary) ? : return
@@ -313,3 +303,6 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
313
303
return baseColor.defaultColor
314
304
}
315
305
}
306
+
307
+
308
+
0 commit comments