Delete "react.views.text.frescosupport" (#55436)

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

The component is no longer referenced anywhere after the previous changes, and can be deleted.

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D92484075

fbshipit-source-id: f98fc143076da81aa390f616d6f5bc767e83a66a
This commit is contained in:
Nick Gerleman authored and meta-codesync[bot] committed 2026-02-08 03:03:05 -08:00
1 parent e2b07beea2
commit 444eb0eb2c
3 files changed
-384

No files matched your search

@@ -1,156 +0,0 @@
/*
* 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.
*/
@file:Suppress("DEPRECATION")
package com.facebook.react.views.text.frescosupport
import android.content.Context
import android.net.Uri
import com.facebook.common.logging.FLog
import com.facebook.common.util.UriUtil
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder
import com.facebook.imagepipeline.request.ImageRequest
import com.facebook.react.bridge.Dynamic
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.ReadableType
import com.facebook.react.common.ReactConstants
import com.facebook.react.common.annotations.internal.LegacyArchitecture
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger
import com.facebook.react.uimanager.ViewProps
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.views.text.internal.ReactTextInlineImageShadowNode
import com.facebook.react.views.text.internal.span.TextInlineImageSpan
import com.facebook.yoga.YogaConstants
import java.util.Locale
/** Shadow node that represents an inline image. Loading is done using Fresco. */
@LegacyArchitecture(logLevel = LegacyArchitectureLogLevel.ERROR)
@Deprecated(
message = "This class is part of Legacy Architecture and will be removed in a future release",
level = DeprecationLevel.WARNING,
)
internal class FrescoBasedReactTextInlineImageShadowNode(
private val draweeControllerBuilder: AbstractDraweeControllerBuilder<*, ImageRequest, *, *>,
private val callerContext: Any?,
) : ReactTextInlineImageShadowNode() {
private var uri: Uri? = null
private var headers: ReadableMap? = null
private var width = YogaConstants.UNDEFINED
private var resizeMode: String? = null
private var height = YogaConstants.UNDEFINED
private var tintColor = 0
@ReactProp(name = "src")
fun setSource(sources: ReadableArray?) {
val source =
if (sources == null || sources.size() == 0 || sources.getType(0) != ReadableType.Map) null
else checkNotNull(sources.getMap(0)).getString("uri")
var tempUri: Uri? = null
if (source != null) {
try {
tempUri = Uri.parse(source)
// Verify scheme is set, so that relative uri (used by static resources) are not handled.
if (tempUri.scheme == null) {
tempUri = null
}
} catch (e: Exception) {
// ignore malformed uri, then attempt to extract resource ID.
}
if (tempUri == null) {
tempUri = getResourceDrawableUri(themedContext, source)
}
}
if (tempUri != uri) {
markUpdated()
}
uri = tempUri
}
@ReactProp(name = "headers")
fun setHeaders(newHeaders: ReadableMap?) {
headers = newHeaders
}
@ReactProp(name = "tintColor", customType = "Color")
fun setTintColor(newTintColor: Int) {
tintColor = newTintColor
}
/** Besides width/height, all other layout props on inline images are ignored */
override fun setWidth(newWidth: Dynamic) {
if (newWidth.type == ReadableType.Number) {
width = newWidth.asDouble().toFloat()
} else {
FLog.w(ReactConstants.TAG, "Inline images must not have percentage based width")
width = YogaConstants.UNDEFINED
}
}
override fun setHeight(newHeight: Dynamic) {
if (newHeight.type == ReadableType.Number) {
height = newHeight.asDouble().toFloat()
} else {
FLog.w(ReactConstants.TAG, "Inline images must not have percentage based height")
height = YogaConstants.UNDEFINED
}
}
@ReactProp(name = ViewProps.RESIZE_MODE)
fun setResizeMode(newResizeMode: String?) {
resizeMode = newResizeMode
}
fun getUri(): Uri? = uri
fun getHeaders(): ReadableMap? = headers
override fun isVirtual(): Boolean = true
override fun buildInlineImageSpan(): TextInlineImageSpan {
val resources = themedContext.resources
val finalWidth = Math.ceil(width.toDouble()).toInt()
val finalHeight = Math.ceil(height.toDouble()).toInt()
return FrescoBasedReactTextInlineImageSpan(
resources,
finalHeight,
finalWidth,
tintColor,
getUri(),
getHeaders(),
getDraweeControllerBuilder(),
getCallerContext(),
resizeMode,
)
}
fun getDraweeControllerBuilder() = draweeControllerBuilder
fun getCallerContext(): Any? = callerContext
// TODO: t9053573 is tracking that this code should be shared
companion object {
fun getResourceDrawableUri(context: Context, name: String?): Uri? {
if (name == null || name.isEmpty()) {
return null
}
val formattedName = name.lowercase(Locale.getDefault()).replace("-", "_")
val resId = context.resources.getIdentifier(formattedName, "drawable", context.packageName)
return Uri.Builder().scheme(UriUtil.LOCAL_RESOURCE_SCHEME).path(resId.toString()).build()
}
init {
LegacyArchitectureLogger.assertLegacyArchitecture(
"FrescoBasedReactTextInlineImageShadowNode",
LegacyArchitectureLogLevel.ERROR,
)
}
}
}
@@ -1,174 +0,0 @@
/*
* 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.text.frescosupport
import android.content.res.Resources
import android.graphics.BlendMode
import android.graphics.BlendModeColorFilter
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Build
import android.widget.TextView
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder
import com.facebook.drawee.generic.GenericDraweeHierarchy
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder
import com.facebook.drawee.view.DraweeHolder
import com.facebook.imagepipeline.request.ImageRequest
import com.facebook.imagepipeline.request.ImageRequestBuilder
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.modules.fresco.ReactNetworkImageRequest
import com.facebook.react.uimanager.PixelUtil
import com.facebook.react.views.image.ImageResizeMode
import com.facebook.react.views.text.internal.span.TextInlineImageSpan
/**
* FrescoBasedTextInlineImageSpan is a span for Images that are inside <Text/>. It computes its size
* based on the input size. When it is time to draw, it will use the Fresco framework to get the
* right Drawable and let that draw.
*
* Since Fresco needs to callback to the TextView that contains this, in the ViewManager, you must
* tell the Span about the TextView
*
* Note: It borrows code from DynamicDrawableSpan and if that code updates how it computes size or
* draws, we need to update this as well.
*/
internal class FrescoBasedReactTextInlineImageSpan(
resources: Resources,
height: Int,
width: Int,
private val tintColor: Int,
uri: Uri?,
private val headers: ReadableMap?,
private val draweeControllerBuilder: AbstractDraweeControllerBuilder<*, ImageRequest, *, *>,
private val callerContext: Any?,
private val resizeMode: String?,
) : TextInlineImageSpan() {
private var textView: TextView? = null
private val _uri: Uri = uri ?: Uri.EMPTY
private val _width: Int = PixelUtil.toPixelFromDIP(width.toDouble()).toInt()
private val _height: Int = PixelUtil.toPixelFromDIP(height.toDouble()).toInt()
private val draweeHolder: DraweeHolder<GenericDraweeHierarchy> =
DraweeHolder(GenericDraweeHierarchyBuilder.newInstance(resources).build())
override val width: Int
get() = _width
override val height: Int
get() = _height
override var drawable: Drawable? = null
private set
/**
* The ReactTextView that holds this ImageSpan is responsible for passing these methods on so that
* we can do proper lifetime management for Fresco
*/
override fun onDetachedFromWindow() {
draweeHolder.onDetach()
}
override fun onStartTemporaryDetach() {
draweeHolder.onDetach()
}
override fun onAttachedToWindow() {
draweeHolder.onAttach()
}
override fun onFinishTemporaryDetach() {
draweeHolder.onAttach()
}
override fun getSize(
paint: Paint,
text: CharSequence,
start: Int,
end: Int,
fm: Paint.FontMetricsInt?,
): Int {
// NOTE: This getSize code is copied from DynamicDrawableSpan and modified
// to not use a Drawable
fm?.let { fm ->
fm.ascent = -_height
fm.descent = 0
fm.top = fm.ascent
fm.bottom = 0
}
return _width
}
override fun setTextView(textView: TextView?) {
this.textView = textView
}
override fun draw(
canvas: Canvas,
text: CharSequence,
start: Int,
end: Int,
x: Float,
top: Int,
y: Int,
bottom: Int,
paint: Paint,
) {
if (drawable == null) {
val imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(_uri)
val imageRequest: ImageRequest =
ReactNetworkImageRequest.fromBuilderWithHeaders(imageRequestBuilder, headers)
draweeHolder.hierarchy.setActualImageScaleType(ImageResizeMode.toScaleType(resizeMode))
draweeControllerBuilder.reset()
draweeControllerBuilder.oldController = draweeHolder.controller
callerContext?.let { draweeControllerBuilder.setCallerContext(it) }
draweeControllerBuilder.setImageRequest(imageRequest)
val draweeController = draweeControllerBuilder.build()
draweeHolder.controller = draweeController
draweeControllerBuilder.reset()
checkNotNull(draweeHolder.topLevelDrawable).apply {
setBounds(0, 0, _width, _height)
if (tintColor != 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
colorFilter = BlendModeColorFilter(tintColor, BlendMode.SRC_IN)
} else {
colorFilter = PorterDuffColorFilter(tintColor, PorterDuff.Mode.SRC_IN)
}
}
callback = textView
drawable = this
}
}
// NOTE: This drawing code is copied from DynamicDrawableSpan
canvas.save()
// Align to center
val _drawable = checkNotNull(drawable)
val fontHeight = (paint.descent() - paint.ascent()).toInt()
val centerY = y + paint.descent().toInt() - fontHeight / 2
val transY = centerY - _drawable.bounds.height() / 2
canvas.translate(x, transY.toFloat())
_drawable.draw(canvas)
canvas.restore()
}
}
@@ -1,54 +0,0 @@
/*
* 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.text.frescosupport
import android.view.View
import com.facebook.drawee.backends.pipeline.Fresco
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder
import com.facebook.imagepipeline.request.ImageRequest
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.BaseViewManager
import com.facebook.react.uimanager.ThemedReactContext
/**
* Manages Images embedded in Text nodes using Fresco. Since they are used only as a virtual nodes
* any type of native view operation will throw an [IllegalStateException].
*/
@Suppress("DEPRECATION")
@ReactModule(name = FrescoBasedReactTextInlineImageViewManager.REACT_CLASS)
internal class FrescoBasedReactTextInlineImageViewManager
@JvmOverloads
constructor(
private val draweeControllerBuilder:
@JvmSuppressWildcards
AbstractDraweeControllerBuilder<*, ImageRequest, *, *>? =
null,
private val callerContext: Any? = null,
) : BaseViewManager<View, FrescoBasedReactTextInlineImageShadowNode>() {
override fun getName(): String = REACT_CLASS
override fun createViewInstance(context: ThemedReactContext): View {
throw IllegalStateException("RCTTextInlineImage doesn't map into a native view")
}
override fun createShadowNodeInstance(): FrescoBasedReactTextInlineImageShadowNode =
FrescoBasedReactTextInlineImageShadowNode(
draweeControllerBuilder ?: Fresco.newDraweeControllerBuilder(),
callerContext,
)
override fun getShadowNodeClass(): Class<FrescoBasedReactTextInlineImageShadowNode> =
FrescoBasedReactTextInlineImageShadowNode::class.java
override fun updateExtraData(root: View, extraData: Any) = Unit
companion object {
const val REACT_CLASS: String = "RCTTextInlineImage"
}
}