Skip to content

Commit fd3ef7b

Browse files
Thomas Nardonefacebook-github-bot
authored andcommitted
Avoid !! in ResourceDrawableHelper.kt (facebook#43820)
Summary: Pull Request resolved: facebook#43820 Changelog: [Internal] Reviewed By: cortinico Differential Revision: D55701291 fbshipit-source-id: afdce3ffa59bc488d6c36d78a8cf3176089599ba
1 parent 70c3158 commit fd3ef7b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/imagehelper/ResourceDrawableIdHelper.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ public class ResourceDrawableIdHelper private constructor() {
3737
}
3838

3939
synchronized(this) {
40-
if (resourceDrawableIdMap.containsKey(normalizedName)) {
41-
return resourceDrawableIdMap.get(normalizedName)!!
42-
}
43-
return context.resources.getIdentifier(normalizedName, "drawable", context.packageName).also {
44-
resourceDrawableIdMap[normalizedName] = it
45-
}
40+
return resourceDrawableIdMap.get(normalizedName) ?: addDrawableId(context, normalizedName)
4641
}
4742
}
4843

44+
private fun addDrawableId(context: Context, normalizedName: String): Int {
45+
val newId = context.resources.getIdentifier(normalizedName, "drawable", context.packageName)
46+
resourceDrawableIdMap[normalizedName] = newId
47+
return newId
48+
}
49+
4950
public fun getResourceDrawable(context: Context, name: String?): Drawable? {
5051
val resId = getResourceDrawableId(context, name)
5152
return if (resId > 0) ResourcesCompat.getDrawable(context.resources, resId, null) else null

0 commit comments

Comments
 (0)