Remove unused vector drawable code path (#46878)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46878

Removes an unused code path from `ResourceDrawableIdHelper`. Vector drawables are now loaded via Fresco decoder so we don't need to offer this utility anymore. While part of the public API, it only made it into 0.76.0 RCs and should have really been marked internal.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D64021956

fbshipit-source-id: 6e8073e0f7f079d023fa1e45a5a43f8652ca2826
This commit is contained in:
Peter Abbondanzo
2024-10-08 07:24:28 -07:00
committed by Facebook GitHub Bot
parent aaf7a6a3ab
commit ff1c3824d2
2 changed files with 0 additions and 37 deletions
@@ -6784,7 +6784,6 @@ public final class com/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 fun isVectorDrawable (Landroid/content/Context;Ljava/lang/String;)Z
}
public final class com/facebook/react/views/imagehelper/ResourceDrawableIdHelper$Companion {
@@ -8,18 +8,15 @@
package com.facebook.react.views.imagehelper
import android.content.Context
import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.net.Uri
import androidx.core.content.res.ResourcesCompat
import javax.annotation.concurrent.ThreadSafe
import org.xmlpull.v1.XmlPullParser
/** Helper class for obtaining information about local images. */
@ThreadSafe
public class ResourceDrawableIdHelper private constructor() {
private val resourceDrawableIdMap: MutableMap<String, Int> = HashMap()
private val vectorDrawableCheckCache: MutableMap<String, Boolean> = HashMap()
@Synchronized
public fun clear() {
@@ -64,39 +61,6 @@ public class ResourceDrawableIdHelper private constructor() {
}
}
public fun isVectorDrawable(context: Context, name: String): Boolean {
return vectorDrawableCheckCache.getOrPut(name, { getOpeningXmlTag(context, name) == "vector" })
}
/**
* If the provided resource name is a valid drawable resource and is an XML file, returns the root
* XML tag. Skips over the versioning/encoding header. Non-XML files and malformed XML files
* return null.
*
* For example, a vector drawable file would return "vector".
*/
private fun getOpeningXmlTag(context: Context, name: String): String? {
val resId = getResourceDrawableId(context, name).takeIf { it > 0 } ?: return null
return try {
val xmlParser = context.resources.getXml(resId)
xmlParser.use {
var parentTag: String? = null
var eventType = xmlParser.eventType
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
parentTag = xmlParser.name
break
}
eventType = xmlParser.next()
}
parentTag
}
} catch (e: Resources.NotFoundException) {
// Drawable image is not an XML file
null
}
}
public companion object {
private const val LOCAL_RESOURCE_SCHEME = "res"
private val resourceDrawableIdHelper: ResourceDrawableIdHelper = ResourceDrawableIdHelper()