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
   UIColor * _savedBackgroundColor;
42
   UIColor * _savedBackgroundColor;
43
   BOOL _savedHideKeyboardAccessoryView;
43
   BOOL _savedHideKeyboardAccessoryView;
44
   BOOL _savedKeyboardDisplayRequiresUserAction;
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
 - (instancetype)initWithFrame:(CGRect)frame
53
 - (instancetype)initWithFrame:(CGRect)frame
56
     _automaticallyAdjustContentInsets = YES;
62
     _automaticallyAdjustContentInsets = YES;
57
     _contentInset = UIEdgeInsetsZero;
63
     _contentInset = UIEdgeInsetsZero;
58
     _savedKeyboardDisplayRequiresUserAction = YES;
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
   if (@available(iOS 12.0, *)) {
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
     [[NSNotificationCenter defaultCenter]
72
     [[NSNotificationCenter defaultCenter]
65
       addObserver:self
73
       addObserver:self
66
       selector:@selector(keyboardWillHide)
74
       selector:@selector(keyboardWillHide)
69
       addObserver:self
77
       addObserver:self
70
       selector:@selector(keyboardWillShow)
78
       selector:@selector(keyboardWillShow)
71
       name:UIKeyboardWillShowNotification object:nil];
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
   return self;
86
   return self;
75
 }
87
 }
76
 
88
 
241
     [super removeFromSuperview];
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
 -(void)keyboardWillHide
274
 -(void)keyboardWillHide
245
 {
275
 {
246
     keyboardTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(keyboardDisplacementFix) userInfo:nil repeats:false];
276
     keyboardTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(keyboardDisplacementFix) userInfo:nil repeats:false];