瀏覽代碼

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
Abraham Przewodnik 5 年之前
父節點
當前提交
05e2d27662
共有 1 個文件被更改,包括 16 次插入5 次删除
  1. 16
    5
      ios/RNCWebView.m

+ 16
- 5
ios/RNCWebView.m 查看文件

@@ -92,7 +92,15 @@ static NSDictionary* customCertificatesForHost;
92 92
 
93 93
     // Workaround for StatusBar appearance bug for iOS 12
94 94
     // https://github.com/react-native-community/react-native-webview/issues/62
95
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toggleFullScreenVideoStatusBars) name:@"_MRMediaRemotePlayerSupportedCommandsDidChangeNotification" object:nil];
95
+      [[NSNotificationCenter defaultCenter] addObserver:self
96
+                                               selector:@selector(showFullScreenVideoStatusBars)
97
+                                                   name:UIWindowDidBecomeVisibleNotification
98
+                                                 object:nil];
99
+
100
+      [[NSNotificationCenter defaultCenter] addObserver:self
101
+                                               selector:@selector(hideFullScreenVideoStatusBars)
102
+                                                   name:UIWindowDidBecomeHiddenNotification
103
+                                                 object:nil];
96 104
   }
97 105
 
98 106
   return self;
@@ -275,21 +283,24 @@ static NSDictionary* customCertificatesForHost;
275 283
     [super removeFromSuperview];
276 284
 }
277 285
 
278
--(void)toggleFullScreenVideoStatusBars
286
+-(void)showFullScreenVideoStatusBars
279 287
 {
280 288
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
281
-  if (!_isFullScreenVideoOpen) {
282 289
     _isFullScreenVideoOpen = YES;
283 290
     RCTUnsafeExecuteOnMainQueueSync(^{
284 291
       [RCTSharedApplication() setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
285 292
     });
286
-  } else {
293
+#pragma clang diagnostic pop
294
+}
295
+
296
+-(void)hideFullScreenVideoStatusBars
297
+{
298
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
287 299
     _isFullScreenVideoOpen = NO;
288 300
     RCTUnsafeExecuteOnMainQueueSync(^{
289 301
       [RCTSharedApplication() setStatusBarHidden:self->_savedStatusBarHidden animated:YES];
290 302
       [RCTSharedApplication() setStatusBarStyle:self->_savedStatusBarStyle animated:YES];
291 303
     });
292
-  }
293 304
 #pragma clang diagnostic pop
294 305
 }
295 306