Skip to content

Commit cd5d745

Browse files
Nick Lefeverfacebook-github-bot
authored andcommitted
Fix image loading on props change without layout invalidation (#51791)
Summary: Pull Request resolved: #51791 On iOS the <Image> shadow node was expecting a layout call for every clone. With `passChildrenWhenCloningPersistedNodes` <Image> components may have the image source updated without layout being called on it due to the re-use of the previous layout data thanks to the improved handling of layout invalidation. This diff triggers the image request as soon as possible if the cloned shadow node has a clean layout. The request will be made as soon as the image manager is set on the shadow node. Changelog: [iOS][Fixed] - Fix RCTImageComponentView image loading after source props change with no layout invalidation Reviewed By: NickGerleman, sammy-SC Differential Revision: D75919671 fbshipit-source-id: 8b92a9c63b6ff4a62c7eb7b0dbe18dd2be989b81
1 parent 0581e88 commit cd5d745

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ const char ImageComponentName[] = "Image";
2020
void ImageShadowNode::setImageManager(const SharedImageManager& imageManager) {
2121
ensureUnsealed();
2222
imageManager_ = imageManager;
23+
24+
// TODO: T226624691 Improve image request creation to avoid double requests
25+
// The image manager is set when the component descriptor adopts the shadow
26+
// node. For instances where the shadow node was cloned without dirtying the
27+
// layout, if the image source was changed we have to initiate the image
28+
// request now since there is no guarantee that layout will run for the shadow
29+
// node at a later time.
30+
if (getIsLayoutClean()) {
31+
auto sources = getConcreteProps().sources;
32+
auto layoutMetric = getLayoutMetrics();
33+
if (sources.size() <= 1 ||
34+
(layoutMetric.frame.size.width > 0 &&
35+
layoutMetric.frame.size.height > 0)) {
36+
updateStateIfNeeded();
37+
}
38+
}
2339
}
2440

2541
void ImageShadowNode::updateStateIfNeeded() {

0 commit comments

Comments
 (0)