Ver código fonte

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 4 anos atrás
pai
commit
05e2d27662
1 arquivos alterados com 16 adições e 5 exclusões
  1. 16
    5
      ios/RNCWebView.m

+ 16
- 5
ios/RNCWebView.m Ver arquivo

92
 
92
 
93
     // Workaround for StatusBar appearance bug for iOS 12
93
     // Workaround for StatusBar appearance bug for iOS 12
94
     // https://github.com/react-native-community/react-native-webview/issues/62
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
   return self;
106
   return self;
275
     [super removeFromSuperview];
283
     [super removeFromSuperview];
276
 }
284
 }
277
 
285
 
278
--(void)toggleFullScreenVideoStatusBars
286
+-(void)showFullScreenVideoStatusBars
279
 {
287
 {
280
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
288
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
281
-  if (!_isFullScreenVideoOpen) {
282
     _isFullScreenVideoOpen = YES;
289
     _isFullScreenVideoOpen = YES;
283
     RCTUnsafeExecuteOnMainQueueSync(^{
290
     RCTUnsafeExecuteOnMainQueueSync(^{
284
       [RCTSharedApplication() setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
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
     _isFullScreenVideoOpen = NO;
299
     _isFullScreenVideoOpen = NO;
288
     RCTUnsafeExecuteOnMainQueueSync(^{
300
     RCTUnsafeExecuteOnMainQueueSync(^{
289
       [RCTSharedApplication() setStatusBarHidden:self->_savedStatusBarHidden animated:YES];
301
       [RCTSharedApplication() setStatusBarHidden:self->_savedStatusBarHidden animated:YES];
290
       [RCTSharedApplication() setStatusBarStyle:self->_savedStatusBarStyle animated:YES];
302
       [RCTSharedApplication() setStatusBarStyle:self->_savedStatusBarStyle animated:YES];
291
     });
303
     });
292
-  }
293
 #pragma clang diagnostic pop
304
 #pragma clang diagnostic pop
294
 }
305
 }
295
 
306