Browse Source

fix(WKWebView): StatusBar is gone after fullscreen (iOS 12) (#544)

fixes #62
Eric Lewis 5 years ago
parent
commit
c2914a8d73
1 changed files with 33 additions and 3 deletions
  1. 33
    3
      ios/RNCWKWebView.m

+ 33
- 3
ios/RNCWKWebView.m View File

@@ -42,6 +42,12 @@ static NSURLCredential* clientAuthenticationCredential;
42 42
   UIColor * _savedBackgroundColor;
43 43
   BOOL _savedHideKeyboardAccessoryView;
44 44
   BOOL _savedKeyboardDisplayRequiresUserAction;
45
+  
46
+  // Workaround for StatusBar appearance bug for iOS 12
47
+  // https://github.com/react-native-community/react-native-webview/issues/62
48
+  BOOL _isFullScreenVideoOpen;
49
+  UIStatusBarStyle _savedStatusBarStyle;
50
+  BOOL _savedStatusBarHidden;
45 51
 }
46 52
 
47 53
 - (instancetype)initWithFrame:(CGRect)frame
@@ -56,11 +62,13 @@ static NSURLCredential* clientAuthenticationCredential;
56 62
     _automaticallyAdjustContentInsets = YES;
57 63
     _contentInset = UIEdgeInsetsZero;
58 64
     _savedKeyboardDisplayRequiresUserAction = YES;
65
+    _savedStatusBarStyle = RCTSharedApplication().statusBarStyle;
66
+    _savedStatusBarHidden = RCTSharedApplication().statusBarHidden;
59 67
   }
60 68
 
61
-  // Workaround for a keyboard dismissal bug present in iOS 12
62
-  // https://openradar.appspot.com/radar?id=5018321736957952
63 69
   if (@available(iOS 12.0, *)) {
70
+    // Workaround for a keyboard dismissal bug present in iOS 12
71
+    // https://openradar.appspot.com/radar?id=5018321736957952
64 72
     [[NSNotificationCenter defaultCenter]
65 73
       addObserver:self
66 74
       selector:@selector(keyboardWillHide)
@@ -69,8 +77,12 @@ static NSURLCredential* clientAuthenticationCredential;
69 77
       addObserver:self
70 78
       selector:@selector(keyboardWillShow)
71 79
       name:UIKeyboardWillShowNotification object:nil];
80
+    
81
+    // Workaround for StatusBar appearance bug for iOS 12
82
+    // https://github.com/react-native-community/react-native-webview/issues/62
83
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toggleFullScreenVideoStatusBars) name:@"_MRMediaRemotePlayerSupportedCommandsDidChangeNotification" object:nil];
72 84
   }
73
-
85
+  
74 86
   return self;
75 87
 }
76 88
 
@@ -241,6 +253,24 @@ static NSURLCredential* clientAuthenticationCredential;
241 253
     [super removeFromSuperview];
242 254
 }
243 255
 
256
+-(void)toggleFullScreenVideoStatusBars
257
+{
258
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
259
+  if (!_isFullScreenVideoOpen) {
260
+    _isFullScreenVideoOpen = YES;
261
+    RCTUnsafeExecuteOnMainQueueSync(^{
262
+      [RCTSharedApplication() setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
263
+    });
264
+  } else {
265
+    _isFullScreenVideoOpen = NO;
266
+    RCTUnsafeExecuteOnMainQueueSync(^{
267
+      [RCTSharedApplication() setStatusBarHidden:_savedStatusBarHidden animated:YES];
268
+      [RCTSharedApplication() setStatusBarStyle:_savedStatusBarStyle animated:YES];
269
+    });
270
+  }
271
+#pragma clang diagnostic pop
272
+}
273
+
244 274
 -(void)keyboardWillHide
245 275
 {
246 276
     keyboardTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(keyboardDisplacementFix) userInfo:nil repeats:false];