mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Android: Image Prefetching send ImageResizeMode as enum value (#53516)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53516 Changelog: [General][Breaking] Android: Image Prefetching send ImageResizeMode as enum value Idea: Reduce JNI payload by sending int values instead of strings Reviewed By: lenaic Differential Revision: D81252246 fbshipit-source-id: 7ba128725900422f8654b3019014fd49ec8152b6
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d1c5dae2e6
commit
e30f34eda6
@@ -5353,18 +5353,25 @@ 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 Companion Lcom/facebook/react/views/image/ImageResizeMethod$Companion;
|
||||
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;
|
||||
public static final fun parse (Ljava/lang/String;)Lcom/facebook/react/views/image/ImageResizeMethod;
|
||||
public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/views/image/ImageResizeMethod;
|
||||
public static fun values ()[Lcom/facebook/react/views/image/ImageResizeMethod;
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/image/ImageResizeMethod$Companion {
|
||||
public final fun parse (Ljava/lang/String;)Lcom/facebook/react/views/image/ImageResizeMethod;
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/image/ImageResizeMode {
|
||||
public static final field INSTANCE Lcom/facebook/react/views/image/ImageResizeMode;
|
||||
public static final fun defaultTileMode ()Landroid/graphics/Shader$TileMode;
|
||||
public static final fun defaultValue ()Lcom/facebook/drawee/drawable/ScalingUtils$ScaleType;
|
||||
public final synthetic fun fromInt (I)Ljava/lang/String;
|
||||
public static final fun toScaleType (Ljava/lang/String;)Lcom/facebook/drawee/drawable/ScalingUtils$ScaleType;
|
||||
public static final fun toTileMode (Ljava/lang/String;)Landroid/graphics/Shader$TileMode;
|
||||
}
|
||||
|
||||
+22
-1
@@ -7,9 +7,30 @@
|
||||
|
||||
package com.facebook.react.views.image
|
||||
|
||||
import com.facebook.common.logging.FLog
|
||||
import com.facebook.react.common.ReactConstants
|
||||
|
||||
public enum class ImageResizeMethod {
|
||||
AUTO,
|
||||
RESIZE,
|
||||
SCALE,
|
||||
NONE,
|
||||
NONE;
|
||||
|
||||
public companion object {
|
||||
@JvmStatic
|
||||
public fun parse(resizeMethod: String?): ImageResizeMethod {
|
||||
return when (resizeMethod) {
|
||||
null,
|
||||
"",
|
||||
"auto" -> ImageResizeMethod.AUTO
|
||||
"resize" -> ImageResizeMethod.RESIZE
|
||||
"scale" -> ImageResizeMethod.SCALE
|
||||
"none" -> ImageResizeMethod.NONE
|
||||
else -> {
|
||||
FLog.w(ReactConstants.TAG, "Invalid resize method: '$resizeMethod'")
|
||||
ImageResizeMethod.AUTO
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -21,6 +21,19 @@ public object ImageResizeMode {
|
||||
private const val RESIZE_MODE_REPEAT = "repeat"
|
||||
private const val RESIZE_MODE_NONE = "none"
|
||||
|
||||
@JvmSynthetic
|
||||
public fun fromInt(resizeMode: Int): String {
|
||||
return when (resizeMode) {
|
||||
0 -> RESIZE_MODE_COVER
|
||||
1 -> RESIZE_MODE_CONTAIN
|
||||
2 -> RESIZE_MODE_STRETCH
|
||||
3 -> RESIZE_MODE_CENTER
|
||||
4 -> RESIZE_MODE_REPEAT
|
||||
5 -> RESIZE_MODE_NONE
|
||||
else -> RESIZE_MODE_NONE
|
||||
}
|
||||
}
|
||||
|
||||
/** Converts JS resize modes into `ScalingUtils.ScaleType`. See `ImageResizeMode.js`. */
|
||||
@JvmStatic
|
||||
public fun toScaleType(resizeModeValue: String?): ScalingUtils.ScaleType {
|
||||
|
||||
+1
-11
@@ -188,17 +188,7 @@ public constructor(
|
||||
|
||||
@ReactProp(name = ViewProps.RESIZE_METHOD)
|
||||
public fun setResizeMethod(view: ReactImageView, resizeMethod: String?) {
|
||||
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'")
|
||||
}
|
||||
}
|
||||
view.setResizeMethod(ImageResizeMethod.parse(resizeMethod))
|
||||
}
|
||||
|
||||
@ReactProp(name = "resizeMultiplier")
|
||||
|
||||
+3
-20
@@ -12,30 +12,13 @@
|
||||
#include <react/renderer/imagemanager/primitives.h>
|
||||
#include <react/renderer/mapbuffer/MapBuffer.h>
|
||||
#include <react/renderer/mapbuffer/MapBufferBuilder.h>
|
||||
#include <string>
|
||||
#include <react/utils/to_underlying.h>
|
||||
#include <vector>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
namespace {
|
||||
|
||||
inline std::string toString(const ImageResizeMode& value) {
|
||||
switch (value) {
|
||||
case ImageResizeMode::Cover:
|
||||
return "cover";
|
||||
case ImageResizeMode::Contain:
|
||||
return "contain";
|
||||
case ImageResizeMode::Stretch:
|
||||
return "stretch";
|
||||
case ImageResizeMode::Center:
|
||||
return "center";
|
||||
case ImageResizeMode::Repeat:
|
||||
return "repeat";
|
||||
case ImageResizeMode::None:
|
||||
return "none";
|
||||
}
|
||||
}
|
||||
|
||||
constexpr MapBuffer::Key IS_KEY_URI = 0;
|
||||
constexpr MapBuffer::Key IS_KEY_DEFAULT_SRC = 1;
|
||||
constexpr MapBuffer::Key IS_KEY_RESIZE_MODE = 2;
|
||||
@@ -68,8 +51,8 @@ inline void serializeImageRequestParams(
|
||||
MapBufferBuilder& builder,
|
||||
const ImageRequestParams& imageRequestParams) {
|
||||
builder.putString(IS_KEY_DEFAULT_SRC, imageRequestParams.defaultSource.uri);
|
||||
builder.putString(
|
||||
IS_KEY_RESIZE_MODE, toString(imageRequestParams.resizeMode));
|
||||
builder.putInt(
|
||||
IS_KEY_RESIZE_MODE, to_underlying(imageRequestParams.resizeMode));
|
||||
builder.putString(IS_KEY_RESIZE_METHOD, imageRequestParams.resizeMethod);
|
||||
builder.putInt(
|
||||
IS_KEY_BLUR_RADIUS, static_cast<int32_t>(imageRequestParams.blurRadius));
|
||||
|
||||
@@ -162,13 +162,13 @@ inline folly::dynamic toDynamic(const ImageSource& imageSource) {
|
||||
|
||||
using ImageSources = std::vector<ImageSource>;
|
||||
|
||||
enum class ImageResizeMode {
|
||||
Cover,
|
||||
Contain,
|
||||
Stretch,
|
||||
Center,
|
||||
Repeat,
|
||||
None,
|
||||
enum class ImageResizeMode : int8_t {
|
||||
Cover = 0,
|
||||
Contain = 1,
|
||||
Stretch = 2,
|
||||
Center = 3,
|
||||
Repeat = 4,
|
||||
None = 5,
|
||||
};
|
||||
|
||||
class ImageErrorInfo {
|
||||
|
||||
Reference in New Issue
Block a user