Skip to content

Commit

Permalink
Add downsampling override type 'never'
Browse files Browse the repository at this point in the history
Differential Revision: D62393211
  • Loading branch information
Abbondanzo authored and facebook-github-bot committed Oct 8, 2024
1 parent d7a8aae commit 41add1f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Image/ImageProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type AndroidImageProps = $ReadOnly<{|
* dimensions differ from the image view's dimensions. Defaults to `'auto'`.
* See https://reactnative.dev/docs/image#resizemethod-android
*/
resizeMethod?: ?('auto' | 'resize' | 'scale'),
resizeMethod?: ?('auto' | 'resize' | 'scale' | 'none'),

/**
* When the `resizeMethod` is set to `resize`, the destination dimensions are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4825,7 +4825,7 @@ type AndroidImageProps = $ReadOnly<{|
loadingIndicatorSource?: ?(number | $ReadOnly<{| uri: string |}>),
progressiveRenderingEnabled?: ?boolean,
fadeDuration?: ?number,
resizeMethod?: ?(\\"auto\\" | \\"resize\\" | \\"scale\\"),
resizeMethod?: ?(\\"auto\\" | \\"resize\\" | \\"scale\\" | \\"none\\"),
resizeMultiplier?: ?number,
|}>;
export type ImageProps = {|
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -6636,6 +6636,7 @@ public final class com/facebook/react/views/image/ImageLoadEvent$Companion {

public final class com/facebook/react/views/image/ImageResizeMethod : java/lang/Enum {
public static final field AUTO Lcom/facebook/react/views/image/ImageResizeMethod;
public static final field NONE Lcom/facebook/react/views/image/ImageResizeMethod;
public static final field RESIZE Lcom/facebook/react/views/image/ImageResizeMethod;
public static final field SCALE Lcom/facebook/react/views/image/ImageResizeMethod;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ constructor(
// the 'last' ReactActivity is being destroyed, which effectively means the app is being
// backgrounded.
if (hasBeenInitialized() && clearOnDestroy) {
imagePipeline!!.clearMemoryCaches()
imagePipeline?.clearMemoryCaches()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public enum class ImageResizeMethod {
AUTO,
RESIZE,
SCALE,
NONE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ public constructor(
when (resizeMethod) {
null,
"auto" -> view.setResizeMethod(ImageResizeMethod.AUTO)

"resize" -> view.setResizeMethod(ImageResizeMethod.RESIZE)
"scale" -> view.setResizeMethod(ImageResizeMethod.SCALE)
"none" -> view.setResizeMethod(ImageResizeMethod.NONE)
else -> {
view.setResizeMethod(ImageResizeMethod.AUTO)
FLog.w(ReactConstants.TAG, "Invalid resize method: '$resizeMethod'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.facebook.drawee.generic.RoundingParams
import com.facebook.drawee.view.GenericDraweeView
import com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory
import com.facebook.imagepipeline.common.ResizeOptions
import com.facebook.imagepipeline.core.DownsampleMode
import com.facebook.imagepipeline.image.CloseableImage
import com.facebook.imagepipeline.image.ImageInfo
import com.facebook.imagepipeline.postprocessors.IterativeBoxBlurPostProcessor
Expand Down Expand Up @@ -415,6 +416,10 @@ public class ReactImageView(
.setAutoRotateEnabled(true)
.setProgressiveRenderingEnabled(progressiveRenderingEnabled)

if (resizeMethod == ImageResizeMethod.NONE) {
imageRequestBuilder.setDownsampleOverride(DownsampleMode.NEVER)
}

val imageRequest: ImageRequest =
ReactNetworkImageRequest.fromBuilderWithHeaders(imageRequestBuilder, headers)

Expand All @@ -435,14 +440,16 @@ public class ReactImageView(
callerContext?.let { builder.setCallerContext(it) }

cachedImageSource?.let { cachedSource ->
val cachedImageRequest =
val cachedImageRequestBuilder =
ImageRequestBuilder.newBuilderWithSource(cachedSource.uri)
.setPostprocessor(postprocessor)
.setResizeOptions(resizeOptions)
.setAutoRotateEnabled(true)
.setProgressiveRenderingEnabled(progressiveRenderingEnabled)
.build()
builder.setLowResImageRequest(cachedImageRequest)
if (resizeMethod == ImageResizeMethod.NONE) {
cachedImageRequestBuilder.setDownsampleOverride(DownsampleMode.NEVER)
}
builder.setLowResImageRequest(cachedImageRequestBuilder.build())
}

if (downloadListener != null && controllerForTesting != null) {
Expand Down

0 comments on commit 41add1f

Please sign in to comment.