Skip to content

Commit 315fd51

Browse files
authored
feat: implement drawable cache (#304)
1 parent ac96b23 commit 315fd51

File tree

1 file changed

+11
-2
lines changed
  • packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview

1 file changed

+11
-2
lines changed

packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabView.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
4242
var onNativeLayoutListener: ((width: Double, height: Double) -> Unit)? = null
4343
var disablePageAnimations = false
4444
var items: MutableList<TabInfo> = mutableListOf()
45+
private val iconSources: MutableMap<Int, ImageSource> = mutableMapOf()
46+
private val drawableCache: MutableMap<ImageSource, Drawable> = mutableMapOf()
4547

4648
private var isLayoutEnqueued = false
4749
private var selectedItem: String? = null
48-
private val iconSources: MutableMap<Int, ImageSource> = mutableMapOf()
4950
private var activeTintColor: Int? = null
5051
private var inactiveTintColor: Int? = null
5152
private val checkedStateSet = intArrayOf(android.R.attr.state_checked)
@@ -309,10 +310,18 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
309310

310311
@SuppressLint("CheckResult")
311312
private fun getDrawable(imageSource: ImageSource, onDrawableReady: (Drawable?) -> Unit) {
313+
drawableCache[imageSource]?.let {
314+
onDrawableReady(it)
315+
return
316+
}
312317
val request = ImageRequest.Builder(context)
313318
.data(imageSource.getUri(context))
314319
.target { drawable ->
315-
post { onDrawableReady(drawable.asDrawable(context.resources)) }
320+
post {
321+
val stateDrawable = drawable.asDrawable(context.resources)
322+
drawableCache[imageSource] = stateDrawable
323+
onDrawableReady(stateDrawable)
324+
}
316325
}
317326
.listener(
318327
onError = { _, result ->

0 commit comments

Comments
 (0)