Skip to content

Commit f332fac

Browse files
tido64facebook-github-bot
authored andcommitted
iOS: Add UIScene support to RCTImageView (#28141)
Summary: Apps implementing `UISceneDelegate` no longer clear out images when backgrounded because `UIApplicationDidEnterBackgroundNotification` no longer gets fired. ## Changelog [iOS] [Added] - UIScene support for RCTImageView Pull Request resolved: #28141 Test Plan: 1. Create a new iOS app implementing `UISceneDelegate` or modify an existing one 2. Open a React view with some images 3. Switch to another app, or background the current app 4. Observe that `-[RCTImageView clearImageIfDetached]` gets called Reviewed By: shergin Differential Revision: D20009200 Pulled By: hramos fbshipit-source-id: bdbf79d6cf56a295344c036b9225efec672fa780
1 parent 3198009 commit f332fac

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Libraries/Image/RCTImageView.mm

+13-3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
8686
{
8787
if ((self = [super initWithFrame:CGRectZero])) {
8888
_bridge = bridge;
89+
_imageView = [[RCTUIImageViewAnimated alloc] init];
90+
_imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
91+
[self addSubview:_imageView];
92+
8993
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
9094
[center addObserver:self
9195
selector:@selector(clearImageIfDetached)
@@ -95,9 +99,15 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
9599
selector:@selector(clearImageIfDetached)
96100
name:UIApplicationDidEnterBackgroundNotification
97101
object:nil];
98-
_imageView = [[RCTUIImageViewAnimated alloc] init];
99-
_imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
100-
[self addSubview:_imageView];
102+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
103+
if (@available(iOS 13.0, *)) {
104+
[center addObserver:self
105+
selector:@selector(clearImageIfDetached)
106+
107+
name:UISceneDidEnterBackgroundNotification
108+
object:nil];
109+
}
110+
#endif
101111
}
102112
return self;
103113
}

0 commit comments

Comments
 (0)