Skip to content

Commit

Permalink
Fix bad input of aspect ratio
Browse files Browse the repository at this point in the history
Reviewed By: oprisnik

Differential Revision: D58526382

fbshipit-source-id: 7c27cbdb03aa102ff8fad8c6645bf0e61aa6aa00
  • Loading branch information
Andrew Wang authored and facebook-github-bot committed Jun 14, 2024
1 parent da28826 commit 9d35ec0
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ import java.util.concurrent.atomic.AtomicReference
@MountSpec(isPureRender = true, canPreallocate = true, poolSize = 15)
object FrescoVitoImage2Spec {

@PropDefault const val imageAspectRatio: Float = 1f
private const val DEFAULT_IMAGE_ASPECT_RATIO = 1f
@PropDefault const val imageAspectRatio: Float = DEFAULT_IMAGE_ASPECT_RATIO

@PropDefault val prefetch: Prefetch = Prefetch.AUTO

Expand Down Expand Up @@ -101,7 +102,15 @@ object FrescoVitoImage2Spec {
size: Size,
@Prop(optional = true, resType = ResType.FLOAT) imageAspectRatio: Float,
) {
MeasureUtils.measureWithAspectRatio(widthSpec, heightSpec, imageAspectRatio, size)
val resolvedAspectRatio: Float =
if (!(imageAspectRatio > 0f)) {
// If the image aspect ratio is not set correctly, we will use the default aspect ratio of
// 1.0f, we've seen bad inputs like 0.0f and NaN.
DEFAULT_IMAGE_ASPECT_RATIO
} else {
imageAspectRatio
}
MeasureUtils.measureWithAspectRatio(widthSpec, heightSpec, resolvedAspectRatio, size)
}

@JvmStatic
Expand Down

0 comments on commit 9d35ec0

Please sign in to comment.