Skip to content

Commit

Permalink
iOS: Add UIScene support to RCTImageView (#28141)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tido64 authored and facebook-github-bot committed Mar 12, 2020
1 parent 3198009 commit f332fac
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Libraries/Image/RCTImageView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
{
if ((self = [super initWithFrame:CGRectZero])) {
_bridge = bridge;
_imageView = [[RCTUIImageViewAnimated alloc] init];
_imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:_imageView];

NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(clearImageIfDetached)
Expand All @@ -95,9 +99,15 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
selector:@selector(clearImageIfDetached)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
_imageView = [[RCTUIImageViewAnimated alloc] init];
_imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:_imageView];
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
[center addObserver:self
selector:@selector(clearImageIfDetached)

name:UISceneDidEnterBackgroundNotification
object:nil];
}
#endif
}
return self;
}
Expand Down

0 comments on commit f332fac

Please sign in to comment.