From c2914a8d7345204997678956ecf076dfbf776cc5 Mon Sep 17 00:00:00 2001 From: Eric Lewis Date: Tue, 30 Apr 2019 04:08:41 -0400 Subject: [PATCH] fix(WKWebView): StatusBar is gone after fullscreen (iOS 12) (#544) fixes #62 --- ios/RNCWKWebView.m | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/ios/RNCWKWebView.m b/ios/RNCWKWebView.m index c152d5b..dc351a5 100644 --- a/ios/RNCWKWebView.m +++ b/ios/RNCWKWebView.m @@ -42,6 +42,12 @@ static NSURLCredential* clientAuthenticationCredential; UIColor * _savedBackgroundColor; BOOL _savedHideKeyboardAccessoryView; BOOL _savedKeyboardDisplayRequiresUserAction; + + // Workaround for StatusBar appearance bug for iOS 12 + // https://github.com/react-native-community/react-native-webview/issues/62 + BOOL _isFullScreenVideoOpen; + UIStatusBarStyle _savedStatusBarStyle; + BOOL _savedStatusBarHidden; } - (instancetype)initWithFrame:(CGRect)frame @@ -56,11 +62,13 @@ static NSURLCredential* clientAuthenticationCredential; _automaticallyAdjustContentInsets = YES; _contentInset = UIEdgeInsetsZero; _savedKeyboardDisplayRequiresUserAction = YES; + _savedStatusBarStyle = RCTSharedApplication().statusBarStyle; + _savedStatusBarHidden = RCTSharedApplication().statusBarHidden; } - // Workaround for a keyboard dismissal bug present in iOS 12 - // https://openradar.appspot.com/radar?id=5018321736957952 if (@available(iOS 12.0, *)) { + // Workaround for a keyboard dismissal bug present in iOS 12 + // https://openradar.appspot.com/radar?id=5018321736957952 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) @@ -69,8 +77,12 @@ static NSURLCredential* clientAuthenticationCredential; addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil]; + + // Workaround for StatusBar appearance bug for iOS 12 + // https://github.com/react-native-community/react-native-webview/issues/62 + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toggleFullScreenVideoStatusBars) name:@"_MRMediaRemotePlayerSupportedCommandsDidChangeNotification" object:nil]; } - + return self; } @@ -241,6 +253,24 @@ static NSURLCredential* clientAuthenticationCredential; [super removeFromSuperview]; } +-(void)toggleFullScreenVideoStatusBars +{ +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + if (!_isFullScreenVideoOpen) { + _isFullScreenVideoOpen = YES; + RCTUnsafeExecuteOnMainQueueSync(^{ + [RCTSharedApplication() setStatusBarStyle:UIStatusBarStyleLightContent animated:YES]; + }); + } else { + _isFullScreenVideoOpen = NO; + RCTUnsafeExecuteOnMainQueueSync(^{ + [RCTSharedApplication() setStatusBarHidden:_savedStatusBarHidden animated:YES]; + [RCTSharedApplication() setStatusBarStyle:_savedStatusBarStyle animated:YES]; + }); + } +#pragma clang diagnostic pop +} + -(void)keyboardWillHide { keyboardTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(keyboardDisplacementFix) userInfo:nil repeats:false];