Skip to content

Commit 04fbfed

Browse files
nit
1 parent 8816ab5 commit 04fbfed

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTUrlBackgroundImageLoader.mm

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ - (instancetype)init
3636
- (void)updateStateWithNewState:(ViewShadowNode::ConcreteState::Shared)state
3737
oldState:(ViewShadowNode::ConcreteState::Shared)oldState
3838
{
39-
// Unsubscribe from old observers
40-
if (oldState) {
41-
const auto& oldRequests = oldState->getData().getBackgroundImageRequests();
42-
for (const auto& request : oldRequests) {
39+
const auto* oldRequests = oldState ? &oldState->getData().getBackgroundImageRequests() : nullptr;
40+
const auto* newRequests = state ? &state->getData().getBackgroundImageRequests() : nullptr;
41+
42+
if (oldRequests && newRequests && *oldRequests == *newRequests) {
43+
return;
44+
}
45+
46+
if (oldRequests) {
47+
for (const auto& request : *oldRequests) {
4348
if (request.imageRequest) {
4449
auto it = _uriToObserver.find(request.imageSource.uri);
4550
if (it != _uriToObserver.end()) {
@@ -54,10 +59,8 @@ - (void)updateStateWithNewState:(ViewShadowNode::ConcreteState::Shared)state
5459
_uriToObserver.clear();
5560
[_loadedImages removeAllObjects];
5661

57-
// Subscribe to new observers
58-
if (state) {
59-
const auto &newRequests = state->getData().getBackgroundImageRequests();
60-
for (const auto &request : newRequests) {
62+
if (newRequests) {
63+
for (const auto &request : *newRequests) {
6164
if (request.imageRequest) {
6265
const std::string &uri = request.imageSource.uri;
6366
auto [it, inserted] = _uriToObserver.emplace(uri, self);

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ @implementation RCTViewComponentView {
6161
BOOL _useCustomContainerView;
6262
NSMutableSet<NSString *> *_accessibilityOrderNativeIDs;
6363
RCTSwiftUIContainerViewWrapper *_swiftUIWrapper;
64-
6564
RCTUrlBackgroundImageLoader *_backgroundImageLoader;
6665
}
6766

@@ -662,7 +661,7 @@ - (void)prepareForRecycle
662661
_filterLayer = nil;
663662
[self clearExistingBackgroundImageLayers];
664663

665-
// Clean up background image state and observers
664+
// Clean up background image observers
666665
[_backgroundImageLoader reset];
667666

668667
_propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN = nil;
@@ -1349,7 +1348,6 @@ - (void)clearExistingBackgroundImageLayers
13491348

13501349
- (void)backgroundImagesDidLoadWithImages:(NSDictionary<NSString *, id> *)loadedImages
13511350
{
1352-
_needsInvalidateLayer = YES;
13531351
[self invalidateLayer];
13541352
}
13551353

0 commit comments

Comments
 (0)