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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
Родитель
3198009410
Коммит
f332fac163
|
@ -86,6 +86,10 @@ static NSDictionary *onLoadParamsForSource(RCTImageSource *source)
|
|||
{
|
||||
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)
|
||||
|
@ -95,9 +99,15 @@ static NSDictionary *onLoadParamsForSource(RCTImageSource *source)
|
|||
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;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче