Skip to content

Commit

Permalink
Ship Primitive image component
Browse files Browse the repository at this point in the history
Summary: The experiment was neutral, all issues have been addressed so I'm shipping primitive implementation of image component and removing mount spec version.

Reviewed By: pentiumao

Differential Revision: D66643554

fbshipit-source-id: ea7d4faa914741253df44957b371a15531e39e56
  • Loading branch information
zielinskimz authored and facebook-github-bot committed Dec 2, 2024
1 parent 2cc5c9b commit 7a5316a
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,6 @@ internal constructor(
/** This flag is used to enable a fix for the ANR issue with sticky header RecyclerView. */
@JvmField var enableFixForStickyHeader: Boolean = false

/**
* This flag is used to enable using PrimitiveComponent implementation of an Image component.
*/
@JvmField var usePrimitiveImage: Boolean = false

/**
* This flag is used to enable using PrimitiveComponent implementation of a SolidColor
* component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.facebook.litho.MatrixDrawable
import com.facebook.litho.PrimitiveComponent
import com.facebook.litho.PrimitiveComponentScope
import com.facebook.litho.Style
import com.facebook.litho.annotations.ExperimentalLithoApi
import com.facebook.rendercore.Size
import com.facebook.rendercore.SizeConstraints
import com.facebook.rendercore.primitives.DrawableAllocator
Expand All @@ -46,7 +45,6 @@ import kotlin.math.max
* @param useIntrinsicSize Whether to use the intrinsic size of the [drawable] for component
* measurement.
*/
@ExperimentalLithoApi
class ExperimentalImage(
private val drawable: Drawable?,
private val scaleType: ScaleType = ScaleType.FIT_CENTER,
Expand Down

This file was deleted.

14 changes: 2 additions & 12 deletions litho-widget/src/main/java/com/facebook/litho/widget/ImageSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ import android.widget.ImageView
import com.facebook.litho.Component
import com.facebook.litho.ComponentContext
import com.facebook.litho.annotations.ExcuseMySpec
import com.facebook.litho.annotations.ExperimentalLithoApi
import com.facebook.litho.annotations.LayoutSpec
import com.facebook.litho.annotations.OnCreateLayout
import com.facebook.litho.annotations.Prop
import com.facebook.litho.annotations.PropDefault
import com.facebook.litho.annotations.Reason
import com.facebook.litho.annotations.ResType
import com.facebook.litho.config.ComponentsConfiguration

/**
* A component that is able to display drawable resources. It takes a drawable resource ID as prop.
Expand All @@ -43,22 +41,14 @@ object ImageSpec {

@PropDefault val useIntrinsicSize: Boolean = true

@OptIn(ExperimentalLithoApi::class)
@OnCreateLayout
fun onCreateLayout(
c: ComponentContext,
@Prop(resType = ResType.DRAWABLE) drawable: Drawable?,
@Prop(optional = true) scaleType: ImageView.ScaleType?,
@Prop(optional = true) useIntrinsicSize: Boolean,
): Component {
return if (ComponentsConfiguration.usePrimitiveImage) {
ExperimentalImage(drawable, scaleType ?: ImageView.ScaleType.FIT_CENTER, useIntrinsicSize)
} else {
ImageComponent.create(c)
.drawable(drawable)
.scaleType(scaleType ?: ImageView.ScaleType.FIT_CENTER)
.useIntrinsicSize(useIntrinsicSize)
.build()
}
return ExperimentalImage(
drawable, scaleType ?: ImageView.ScaleType.FIT_CENTER, useIntrinsicSize)
}
}

0 comments on commit 7a5316a

Please sign in to comment.