fix(iOS): Fix changing notification bars #735 (#898)

UIWindowDidBecomeVisibleNotification and UIWindowDidBecomeHiddenNotification seem far more reliable at detecting fullscreen video.

Tested on iOS 11, 12 and 13
This commit is contained in:
Abraham Przewodnik 2019-09-27 01:22:07 +02:00 committed by Thibault Malbranche
parent 401277fd17
commit 05e2d27662

View File

@ -92,7 +92,15 @@ static NSDictionary* customCertificatesForHost;
// Workaround for StatusBar appearance bug for iOS 12 // Workaround for StatusBar appearance bug for iOS 12
// https://github.com/react-native-community/react-native-webview/issues/62 // https://github.com/react-native-community/react-native-webview/issues/62
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toggleFullScreenVideoStatusBars) name:@"_MRMediaRemotePlayerSupportedCommandsDidChangeNotification" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(showFullScreenVideoStatusBars)
name:UIWindowDidBecomeVisibleNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hideFullScreenVideoStatusBars)
name:UIWindowDidBecomeHiddenNotification
object:nil];
} }
return self; return self;
@ -275,21 +283,24 @@ static NSDictionary* customCertificatesForHost;
[super removeFromSuperview]; [super removeFromSuperview];
} }
-(void)toggleFullScreenVideoStatusBars -(void)showFullScreenVideoStatusBars
{ {
#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdeprecated-declarations"
if (!_isFullScreenVideoOpen) {
_isFullScreenVideoOpen = YES; _isFullScreenVideoOpen = YES;
RCTUnsafeExecuteOnMainQueueSync(^{ RCTUnsafeExecuteOnMainQueueSync(^{
[RCTSharedApplication() setStatusBarStyle:UIStatusBarStyleLightContent animated:YES]; [RCTSharedApplication() setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
}); });
} else { #pragma clang diagnostic pop
}
-(void)hideFullScreenVideoStatusBars
{
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
_isFullScreenVideoOpen = NO; _isFullScreenVideoOpen = NO;
RCTUnsafeExecuteOnMainQueueSync(^{ RCTUnsafeExecuteOnMainQueueSync(^{
[RCTSharedApplication() setStatusBarHidden:self->_savedStatusBarHidden animated:YES]; [RCTSharedApplication() setStatusBarHidden:self->_savedStatusBarHidden animated:YES];
[RCTSharedApplication() setStatusBarStyle:self->_savedStatusBarStyle animated:YES]; [RCTSharedApplication() setStatusBarStyle:self->_savedStatusBarStyle animated:YES];
}); });
}
#pragma clang diagnostic pop #pragma clang diagnostic pop
} }