@@ -23,20 +23,18 @@ import com.facebook.react.bridge.ReadableArray
2323import com.facebook.react.bridge.WritableMap
2424import com.facebook.react.common.assets.ReactFontManager
2525import com.facebook.react.modules.core.ReactChoreographer
26- import com.facebook.react.views.imagehelper.ImageSource
2726import com.facebook.react.views.text.ReactTypefaceUtils
2827import com.google.android.material.bottomnavigation.BottomNavigationView
2928import coil3.request.ImageRequest
3029import coil3.svg.SvgDecoder
3130
3231
3332class ReactBottomNavigationView (context : Context ) : BottomNavigationView(context) {
34- private val icons : MutableMap <Int , ImageSource > = mutableMapOf ()
33+ private val iconSources : MutableMap <Int , ImageSource > = mutableMapOf ()
3534 private var isLayoutEnqueued = false
3635 var items: MutableList <TabInfo >? = null
3736 var onTabSelectedListener: ((WritableMap ) -> Unit )? = null
3837 var onTabLongPressedListener: ((WritableMap ) -> Unit )? = null
39- private var isAnimating = false
4038 private var activeTintColor: Int? = null
4139 private var inactiveTintColor: Int? = null
4240 private val checkedStateSet = intArrayOf(android.R .attr.state_checked)
@@ -91,7 +89,7 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
9189
9290 private fun onTabSelected (item : MenuItem ) {
9391 if (isLayoutEnqueued) {
94- return ;
92+ return
9593 }
9694 val selectedItem = items?.first { it.title == item.title }
9795 selectedItem?.let {
@@ -108,8 +106,8 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
108106 items.forEachIndexed { index, item ->
109107 val menuItem = getOrCreateItem(index, item.title)
110108 menuItem.isVisible = ! item.hidden
111- if (icons .containsKey(index)) {
112- getDrawable(icons [index]!! ) {
109+ if (iconSources .containsKey(index)) {
110+ getDrawable(iconSources [index]!! ) {
113111 menuItem.icon = it
114112 }
115113 }
@@ -150,12 +148,9 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
150148 if (uri.isNullOrEmpty()) {
151149 continue
152150 }
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
159154
160155 // Update existing item if exists.
161156 menu.findItem(idx)?.let { menuItem ->
@@ -183,7 +178,7 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
183178 @SuppressLint(" CheckResult" )
184179 private fun getDrawable (imageSource : ImageSource , onDrawableReady : (Drawable ? ) -> Unit ) {
185180 val request = ImageRequest .Builder (context)
186- .data(imageSource.uri )
181+ .data(imageSource.getUri(context) )
187182 .target { drawable ->
188183 post { onDrawableReady(drawable.asDrawable(context.resources)) }
189184 }
@@ -197,11 +192,6 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
197192 imageLoader.enqueue(request)
198193 }
199194
200- override fun onDetachedFromWindow () {
201- super .onDetachedFromWindow()
202- isAnimating = false
203- }
204-
205195 fun setBarTintColor (color : Int? ) {
206196 // Set the color, either using the active background color or a default color.
207197 val backgroundColor = color ? : getDefaultColorFor(android.R .attr.colorPrimary) ? : return
@@ -241,10 +231,10 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
241231 updateTextAppearance()
242232 }
243233
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()
248238 }
249239
250240 private fun getTypefaceStyle (weight : Int? ) = when (weight) {
@@ -289,7 +279,7 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
289279 // First let's check current item color.
290280 val currentItemTintColor = items?.find { it.title == item?.title }?.activeTintColor
291281
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
293283 val colorPrimary = currentItemTintColor ? : activeTintColor ? : getDefaultColorFor(android.R .attr.colorPrimary) ? : return
294284 val colorSecondary =
295285 inactiveTintColor ? : getDefaultColorFor(android.R .attr.textColorSecondary) ? : return
@@ -313,3 +303,6 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
313303 return baseColor.defaultColor
314304 }
315305}
306+
307+
308+
0 commit comments