Skip to content

Commit 0121208

Browse files
Simplify ImageRequest conversion (#53492)
Summary: Pull Request resolved: #53492 Changelog: [Internal] Goal is to simplify code and to lower the JNI payload - Send values as `int` instead of `Double` if they are converted to `int` on the Java side - We only have 2 optional values - all others are mandatory Reviewed By: lenaic Differential Revision: D81202196 fbshipit-source-id: df8b7d9e6a98e7c919de9be6a277876684f0383c
1 parent 6c7c518 commit 0121208

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

  • packages/react-native/ReactCommon/react/renderer

packages/react-native/ReactCommon/react/renderer/imagemanager/platform/android/react/renderer/imagemanager/conversions.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ inline void serializeImageSource(
5858
MapBufferBuilder& builder,
5959
const ImageSource& imageSource) {
6060
builder.putString(IS_KEY_URI, imageSource.uri);
61-
builder.putDouble(IS_KEY_VIEW_WIDTH, imageSource.size.width);
62-
builder.putDouble(IS_KEY_VIEW_HEIGHT, imageSource.size.height);
61+
builder.putInt(
62+
IS_KEY_VIEW_WIDTH, static_cast<int32_t>(imageSource.size.width));
63+
builder.putInt(
64+
IS_KEY_VIEW_HEIGHT, static_cast<int32_t>(imageSource.size.height));
6365
}
6466

6567
inline void serializeImageRequestParams(
@@ -69,7 +71,8 @@ inline void serializeImageRequestParams(
6971
builder.putString(
7072
IS_KEY_RESIZE_MODE, toString(imageRequestParams.resizeMode));
7173
builder.putString(IS_KEY_RESIZE_METHOD, imageRequestParams.resizeMethod);
72-
builder.putDouble(IS_KEY_BLUR_RADIUS, imageRequestParams.blurRadius);
74+
builder.putInt(
75+
IS_KEY_BLUR_RADIUS, static_cast<int32_t>(imageRequestParams.blurRadius));
7376
builder.putDouble(
7477
IS_KEY_RESIZE_MULTIPLIER, imageRequestParams.resizeMultiplier);
7578
builder.putBool(
@@ -83,7 +86,9 @@ inline void serializeImageRequestParams(
8386
builder.putInt(
8487
IS_KEY_TINT_COLOR, toAndroidRepr(imageRequestParams.tintColor));
8588
}
86-
builder.putDouble(IS_KEY_FADE_DURATION, imageRequestParams.fadeDuration);
89+
builder.putInt(
90+
IS_KEY_FADE_DURATION,
91+
static_cast<int32_t>(imageRequestParams.fadeDuration));
8792
builder.putBool(
8893
IS_KEY_PROGRESSIVE_RENDERING_ENABLED,
8994
imageRequestParams.progressiveRenderingEnabled);

packages/react-native/ReactCommon/react/renderer/mapbuffer/tests/MapBufferTest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ TEST(MapBufferTest, testDoubleEntries) {
9595
EXPECT_EQ(map.getDouble(1), 432.1);
9696
}
9797

98+
TEST(MapBufferTest, testStringEmpty) {
99+
auto builder = MapBufferBuilder();
100+
101+
builder.putString(0, "");
102+
auto map = builder.build();
103+
104+
EXPECT_EQ(map.getString(0), "");
105+
}
106+
98107
TEST(MapBufferTest, testStringEntries) {
99108
auto builder = MapBufferBuilder();
100109

0 commit comments

Comments
 (0)