Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -6129,12 +6129,17 @@ public class com/facebook/react/views/imagehelper/MultiSourceHelper$MultiSourceR
public fun getBestResultInCache ()Lcom/facebook/react/views/imagehelper/ImageSource;
}

public class com/facebook/react/views/imagehelper/ResourceDrawableIdHelper {
public fun clear ()V
public static fun getInstance ()Lcom/facebook/react/views/imagehelper/ResourceDrawableIdHelper;
public fun getResourceDrawable (Landroid/content/Context;Ljava/lang/String;)Landroid/graphics/drawable/Drawable;
public fun getResourceDrawableId (Landroid/content/Context;Ljava/lang/String;)I
public fun getResourceDrawableUri (Landroid/content/Context;Ljava/lang/String;)Landroid/net/Uri;
public final class com/facebook/react/views/imagehelper/ResourceDrawableIdHelper {
public static final field Companion Lcom/facebook/react/views/imagehelper/ResourceDrawableIdHelper$Companion;
public final fun clear ()V
public static final fun getInstance ()Lcom/facebook/react/views/imagehelper/ResourceDrawableIdHelper;
public final fun getResourceDrawable (Landroid/content/Context;Ljava/lang/String;)Landroid/graphics/drawable/Drawable;
public final fun getResourceDrawableId (Landroid/content/Context;Ljava/lang/String;)I
public final fun getResourceDrawableUri (Landroid/content/Context;Ljava/lang/String;)Landroid/net/Uri;
}

public final class com/facebook/react/views/imagehelper/ResourceDrawableIdHelper$Companion {
public final fun getInstance ()Lcom/facebook/react/views/imagehelper/ResourceDrawableIdHelper;
}

public class com/facebook/react/views/modal/ModalHostShadowNode$$PropsSetter : com/facebook/react/uimanager/ViewManagerPropertyUpdater$ShadowNodeSetter {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.views.imagehelper

import android.content.Context
import android.graphics.drawable.Drawable
import android.net.Uri
import androidx.core.content.res.ResourcesCompat
import javax.annotation.concurrent.ThreadSafe

/** Helper class for obtaining information about local images. */
@ThreadSafe
public class ResourceDrawableIdHelper private constructor() {
private val resourceDrawableIdMap: MutableMap<String, Int> = HashMap()

@Synchronized
public fun clear() {
resourceDrawableIdMap.clear()
}

public fun getResourceDrawableId(context: Context, name: String?): Int {
if (name.isNullOrEmpty()) {
return 0
}
val normalizedName = name.lowercase().replace("-", "_")

// name could be a resource id.
try {
return normalizedName.toInt()
} catch (e: NumberFormatException) {
// Do nothing.
}

synchronized(this) {
if (resourceDrawableIdMap.containsKey(normalizedName)) {
return resourceDrawableIdMap.get(normalizedName)!!
}
return context.resources.getIdentifier(normalizedName, "drawable", context.packageName).also {
resourceDrawableIdMap[normalizedName] = it
}
}
}

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
}

public fun getResourceDrawableUri(context: Context, name: String?): Uri {
val resId = getResourceDrawableId(context, name)
return if (resId > 0) {
Uri.Builder().scheme(LOCAL_RESOURCE_SCHEME).path(resId.toString()).build()
} else {
Uri.EMPTY
}
}

public companion object {
private const val LOCAL_RESOURCE_SCHEME = "res"
private val resourceDrawableIdHelper: ResourceDrawableIdHelper = ResourceDrawableIdHelper()
@JvmStatic
public val instance: ResourceDrawableIdHelper
get() = resourceDrawableIdHelper
}
}