Skip to content

Commit c2623af

Browse files
christophpurrermeta-codesync[bot]
authored andcommitted
Pass view.width / .height to image prefetcher, needed for correct resource prefetching (#54546)
Summary: Pull Request resolved: #54546 Changelog: [Internal] We need to forward the `imageView` width and height to the prefetcher to correctly handle resize requests Reviewed By: sbuggay Differential Revision: D87083726 fbshipit-source-id: 8abfc7702e79ac8ad254229391ca1259fd1f5b47
1 parent 376183e commit c2623af

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

packages/react-native/ReactCommon/react/renderer/components/image/ImageShadowNode.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ void ImageShadowNode::updateStateIfNeeded() {
6565
imageProps.fadeDuration,
6666
imageProps.progressiveRenderingEnabled,
6767
imageProps.loadingIndicatorSource,
68-
imageProps.internal_analyticTag
68+
imageProps.internal_analyticTag,
69+
Size{
70+
.width =
71+
layoutMetrics_.frame.size.width * layoutMetrics_.pointScaleFactor,
72+
.height = layoutMetrics_.frame.size.height *
73+
layoutMetrics_.pointScaleFactor}
6974
#endif
7075
);
7176

@@ -85,7 +90,9 @@ void ImageShadowNode::updateStateIfNeeded() {
8590
(uri.starts_with("content://") || uri.starts_with("file://")));
8691
// If we would resize but have no dimensions, skip creating the request
8792
if (shouldResize &&
88-
(newImageSource.size.width == 0 || newImageSource.size.height == 0)) {
93+
(newImageSource.size.width == 0 || newImageSource.size.height == 0 ||
94+
layoutMetrics_.frame.size.width == 0 ||
95+
layoutMetrics_.frame.size.height == 0)) {
8996
// Keep the old state - don't create a new image request
9097
return;
9198
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class ImageRequestParams {
3030
Float fadeDuration,
3131
bool progressiveRenderingEnabled,
3232
ImageSource loadingIndicatorSource,
33-
std::string analyticTag)
33+
std::string analyticTag,
34+
Size size)
3435
: blurRadius(blurRadius),
3536
defaultSource(std::move(defaultSource)),
3637
resizeMode(resizeMode),
@@ -42,7 +43,8 @@ class ImageRequestParams {
4243
fadeDuration(fadeDuration),
4344
progressiveRenderingEnabled(progressiveRenderingEnabled),
4445
loadingIndicatorSource(std::move(loadingIndicatorSource)),
45-
analyticTag(std::move(analyticTag))
46+
analyticTag(std::move(analyticTag)),
47+
size(size)
4648
{
4749
}
4850

@@ -58,6 +60,7 @@ class ImageRequestParams {
5860
bool progressiveRenderingEnabled{};
5961
ImageSource loadingIndicatorSource{};
6062
std::string analyticTag{};
63+
Size size{};
6164

6265
bool operator==(const ImageRequestParams &rhs) const
6366
{
@@ -73,7 +76,8 @@ class ImageRequestParams {
7376
this->fadeDuration,
7477
this->progressiveRenderingEnabled,
7578
this->loadingIndicatorSource,
76-
this->analyticTag) ==
79+
this->analyticTag,
80+
this->size) ==
7781
std::tie(
7882
rhs.blurRadius,
7983
rhs.defaultSource,
@@ -86,7 +90,8 @@ class ImageRequestParams {
8690
rhs.fadeDuration,
8791
rhs.progressiveRenderingEnabled,
8892
rhs.loadingIndicatorSource,
89-
rhs.analyticTag);
93+
rhs.analyticTag,
94+
rhs.size);
9095
}
9196

9297
bool operator!=(const ImageRequestParams &rhs) const

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ constexpr MapBuffer::Key IS_KEY_DEFAULT_SRC = 1;
2424
constexpr MapBuffer::Key IS_KEY_RESIZE_MODE = 2;
2525
constexpr MapBuffer::Key IS_KEY_RESIZE_METHOD = 3;
2626
constexpr MapBuffer::Key IS_KEY_BLUR_RADIUS = 4;
27-
constexpr MapBuffer::Key IS_KEY_VIEW_WIDTH = 5;
28-
constexpr MapBuffer::Key IS_KEY_VIEW_HEIGHT = 6;
27+
constexpr MapBuffer::Key IS_KEY_IMAGE_WIDTH = 5;
28+
constexpr MapBuffer::Key IS_KEY_IMAGE_HEIGHT = 6;
2929
constexpr MapBuffer::Key IS_KEY_RESIZE_MULTIPLIER = 7;
3030
constexpr MapBuffer::Key IS_KEY_SHOULD_NOTIFY_LOAD_EVENTS = 8;
3131
constexpr MapBuffer::Key IS_KEY_OVERLAY_COLOR = 9;
@@ -35,16 +35,20 @@ constexpr MapBuffer::Key IS_KEY_PROGRESSIVE_RENDERING_ENABLED = 12;
3535
constexpr MapBuffer::Key IS_KEY_LOADING_INDICATOR_SRC = 13;
3636
constexpr MapBuffer::Key IS_KEY_ANALYTIC_TAG = 14;
3737
constexpr MapBuffer::Key IS_KEY_TAG = 15;
38+
constexpr MapBuffer::Key IS_KEY_VIEW_WIDTH = 16;
39+
constexpr MapBuffer::Key IS_KEY_VIEW_HEIGHT = 17;
3840

3941
inline void serializeImageSource(MapBufferBuilder &builder, const ImageSource &imageSource)
4042
{
4143
builder.putString(IS_KEY_URI, imageSource.uri);
42-
builder.putInt(IS_KEY_VIEW_WIDTH, static_cast<int32_t>(imageSource.size.width));
43-
builder.putInt(IS_KEY_VIEW_HEIGHT, static_cast<int32_t>(imageSource.size.height));
44+
builder.putInt(IS_KEY_IMAGE_WIDTH, static_cast<int32_t>(imageSource.size.width));
45+
builder.putInt(IS_KEY_IMAGE_HEIGHT, static_cast<int32_t>(imageSource.size.height));
4446
}
4547

4648
inline void serializeImageRequestParams(MapBufferBuilder &builder, const ImageRequestParams &imageRequestParams)
4749
{
50+
builder.putInt(IS_KEY_VIEW_WIDTH, static_cast<int32_t>(imageRequestParams.size.width));
51+
builder.putInt(IS_KEY_VIEW_HEIGHT, static_cast<int32_t>(imageRequestParams.size.height));
4852
builder.putString(IS_KEY_DEFAULT_SRC, imageRequestParams.defaultSource.uri);
4953
builder.putInt(IS_KEY_RESIZE_MODE, to_underlying(imageRequestParams.resizeMode));
5054
builder.putString(IS_KEY_RESIZE_METHOD, imageRequestParams.resizeMethod);

0 commit comments

Comments
 (0)