|
@@ -41,6 +41,13 @@ static NSURLCredential* clientAuthenticationCredential;
|
41
|
41
|
{
|
42
|
42
|
UIColor * _savedBackgroundColor;
|
43
|
43
|
BOOL _savedHideKeyboardAccessoryView;
|
|
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;
|
44
|
51
|
}
|
45
|
52
|
|
46
|
53
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
@@ -54,11 +61,14 @@ static NSURLCredential* clientAuthenticationCredential;
|
54
|
61
|
_directionalLockEnabled = YES;
|
55
|
62
|
_automaticallyAdjustContentInsets = YES;
|
56
|
63
|
_contentInset = UIEdgeInsetsZero;
|
|
64
|
+ _savedKeyboardDisplayRequiresUserAction = YES;
|
|
65
|
+ _savedStatusBarStyle = RCTSharedApplication().statusBarStyle;
|
|
66
|
+ _savedStatusBarHidden = RCTSharedApplication().statusBarHidden;
|
57
|
67
|
}
|
58
|
68
|
|
59
|
|
- // Workaround for a keyboard dismissal bug present in iOS 12
|
60
|
|
- // https://openradar.appspot.com/radar?id=5018321736957952
|
61
|
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
|
62
|
72
|
[[NSNotificationCenter defaultCenter]
|
63
|
73
|
addObserver:self
|
64
|
74
|
selector:@selector(keyboardWillHide)
|
|
@@ -67,8 +77,12 @@ static NSURLCredential* clientAuthenticationCredential;
|
67
|
77
|
addObserver:self
|
68
|
78
|
selector:@selector(keyboardWillShow)
|
69
|
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];
|
70
|
84
|
}
|
71
|
|
-
|
|
85
|
+
|
72
|
86
|
return self;
|
73
|
87
|
}
|
74
|
88
|
|
|
@@ -214,6 +228,7 @@ static NSURLCredential* clientAuthenticationCredential;
|
214
|
228
|
|
215
|
229
|
[self addSubview:_webView];
|
216
|
230
|
[self setHideKeyboardAccessoryView: _savedHideKeyboardAccessoryView];
|
|
231
|
+ [self setKeyboardDisplayRequiresUserAction: _savedKeyboardDisplayRequiresUserAction];
|
217
|
232
|
[self visitSource];
|
218
|
233
|
}
|
219
|
234
|
}
|
|
@@ -238,6 +253,24 @@ static NSURLCredential* clientAuthenticationCredential;
|
238
|
253
|
[super removeFromSuperview];
|
239
|
254
|
}
|
240
|
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
|
+
|
241
|
274
|
-(void)keyboardWillHide
|
242
|
275
|
{
|
243
|
276
|
keyboardTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(keyboardDisplacementFix) userInfo:nil repeats:false];
|
|
@@ -364,6 +397,64 @@ static NSURLCredential* clientAuthenticationCredential;
|
364
|
397
|
}
|
365
|
398
|
}
|
366
|
399
|
|
|
400
|
+-(void)setKeyboardDisplayRequiresUserAction:(BOOL)keyboardDisplayRequiresUserAction
|
|
401
|
+{
|
|
402
|
+ if (_webView == nil) {
|
|
403
|
+ _savedKeyboardDisplayRequiresUserAction = keyboardDisplayRequiresUserAction;
|
|
404
|
+ return;
|
|
405
|
+ }
|
|
406
|
+
|
|
407
|
+ if (_savedKeyboardDisplayRequiresUserAction == true) {
|
|
408
|
+ return;
|
|
409
|
+ }
|
|
410
|
+
|
|
411
|
+ UIView* subview;
|
|
412
|
+
|
|
413
|
+ for (UIView* view in _webView.scrollView.subviews) {
|
|
414
|
+ if([[view.class description] hasPrefix:@"WK"])
|
|
415
|
+ subview = view;
|
|
416
|
+ }
|
|
417
|
+
|
|
418
|
+ if(subview == nil) return;
|
|
419
|
+
|
|
420
|
+ Class class = subview.class;
|
|
421
|
+
|
|
422
|
+ NSOperatingSystemVersion iOS_11_3_0 = (NSOperatingSystemVersion){11, 3, 0};
|
|
423
|
+ NSOperatingSystemVersion iOS_12_2_0 = (NSOperatingSystemVersion){12, 2, 0};
|
|
424
|
+
|
|
425
|
+ Method method;
|
|
426
|
+ IMP override;
|
|
427
|
+
|
|
428
|
+ if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_12_2_0]) {
|
|
429
|
+ // iOS 12.2.0 - Future
|
|
430
|
+ SEL selector = sel_getUid("_elementDidFocus:userIsInteracting:blurPreviousNode:changingActivityState:userObject:");
|
|
431
|
+ method = class_getInstanceMethod(class, selector);
|
|
432
|
+ IMP original = method_getImplementation(method);
|
|
433
|
+ override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, BOOL arg3, id arg4) {
|
|
434
|
+ ((void (*)(id, SEL, void*, BOOL, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3, arg4);
|
|
435
|
+ });
|
|
436
|
+ }
|
|
437
|
+ else if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_11_3_0]) {
|
|
438
|
+ // iOS 11.3.0 - 12.2.0
|
|
439
|
+ SEL selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:");
|
|
440
|
+ method = class_getInstanceMethod(class, selector);
|
|
441
|
+ IMP original = method_getImplementation(method);
|
|
442
|
+ override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, BOOL arg3, id arg4) {
|
|
443
|
+ ((void (*)(id, SEL, void*, BOOL, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3, arg4);
|
|
444
|
+ });
|
|
445
|
+ } else {
|
|
446
|
+ // iOS 9.0 - 11.3.0
|
|
447
|
+ SEL selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:");
|
|
448
|
+ method = class_getInstanceMethod(class, selector);
|
|
449
|
+ IMP original = method_getImplementation(method);
|
|
450
|
+ override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, id arg3) {
|
|
451
|
+ ((void (*)(id, SEL, void*, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3);
|
|
452
|
+ });
|
|
453
|
+ }
|
|
454
|
+
|
|
455
|
+ method_setImplementation(method, override);
|
|
456
|
+}
|
|
457
|
+
|
367
|
458
|
-(void)setHideKeyboardAccessoryView:(BOOL)hideKeyboardAccessoryView
|
368
|
459
|
{
|
369
|
460
|
if (_webView == nil) {
|
|
@@ -460,7 +551,7 @@ static NSURLCredential* clientAuthenticationCredential;
|
460
|
551
|
{
|
461
|
552
|
NSDictionary *event = @{
|
462
|
553
|
@"url": _webView.URL.absoluteString ?: @"",
|
463
|
|
- @"title": _webView.title,
|
|
554
|
+ @"title": _webView.title ?: @"",
|
464
|
555
|
@"loading" : @(_webView.loading),
|
465
|
556
|
@"canGoBack": @(_webView.canGoBack),
|
466
|
557
|
@"canGoForward" : @(_webView.canGoForward)
|