Skip to content

Commit

Permalink
Remove unused vector drawable code path (#46878)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
Abbondanzo authored and facebook-github-bot committed Oct 8, 2024
1 parent aaf7a6a commit ff1c382
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 37 deletions.
1 change: 0 additions & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ff1c382

Please sign in to comment.