diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/imagehelper/ResourceDrawableIdHelper.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/imagehelper/ResourceDrawableIdHelper.kt index 67e8eef582822c..c4e0e8331fd005 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/imagehelper/ResourceDrawableIdHelper.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/imagehelper/ResourceDrawableIdHelper.kt @@ -37,15 +37,16 @@ public class ResourceDrawableIdHelper private constructor() { } synchronized(this) { - if (resourceDrawableIdMap.containsKey(normalizedName)) { - return resourceDrawableIdMap.get(normalizedName)!! - } - return context.resources.getIdentifier(normalizedName, "drawable", context.packageName).also { - resourceDrawableIdMap[normalizedName] = it - } + return resourceDrawableIdMap.get(normalizedName) ?: addDrawableId(context, normalizedName) } } + private fun addDrawableId(context: Context, normalizedName: String): Int { + val newId = context.resources.getIdentifier(normalizedName, "drawable", context.packageName) + resourceDrawableIdMap[normalizedName] = newId + return newId + } + public fun getResourceDrawable(context: Context, name: String?): Drawable? { val resId = getResourceDrawableId(context, name) return if (resId > 0) ResourcesCompat.getDrawable(context.resources, resId, null) else null