Просмотр исходного кода

Merge branch 'master' into @salakar/bugfix/androidx-rn60

Jamon Holmgren 5 лет назад
Родитель
Сommit
89f5117c08
No account linked to committer's email address
8 измененных файлов: 148 добавлений и 8 удалений
  1. 19
    0
      .all-contributorsrc
  2. 2
    2
      README.md
  3. 11
    0
      docs/Reference.md
  4. 1
    0
      ios/RNCWKWebView.h
  5. 95
    4
      ios/RNCWKWebView.m
  6. 4
    0
      ios/RNCWKWebViewManager.m
  7. 1
    1
      package.json
  8. 15
    1
      src/WebViewTypes.ts

+ 19
- 0
.all-contributorsrc Просмотреть файл

@@ -150,6 +150,25 @@
150 150
       "contributions": [
151 151
         "doc"
152 152
       ]
153
+    },
154
+    {
155
+      "login": "TMomemt",
156
+      "name": "TMomemt",
157
+      "avatar_url": "https://avatars3.githubusercontent.com/u/42024947?v=4",
158
+      "profile": "https://github.com/TMomemt",
159
+      "contributions": [
160
+        "code"
161
+      ]
162
+    },
163
+    {
164
+      "login": "ericlewis",
165
+      "name": "Eric Lewis",
166
+      "avatar_url": "https://avatars0.githubusercontent.com/u/674503?v=4",
167
+      "profile": "http://www.try.com",
168
+      "contributions": [
169
+        "code",
170
+        "doc"
171
+      ]
153 172
     }
154 173
   ],
155 174
   "contributorsPerLine": 7

+ 2
- 2
README.md
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 11
- 0
docs/Reference.md Просмотреть файл

@@ -42,6 +42,7 @@ This document lays out the current public properties and methods for the React N
42 42
 - [`useWebKit`](Reference.md#usewebkit)
43 43
 - [`url`](Reference.md#url)
44 44
 - [`html`](Reference.md#html)
45
+- [`keyboardDisplayRequiresUserAction`](Reference.md#keyboardDisplayRequiresUserAction)
45 46
 - [`hideKeyboardAccessoryView`](Reference.md#hidekeyboardaccessoryview)
46 47
 - [`allowsBackForwardNavigationGestures`](Reference.md#allowsbackforwardnavigationgestures)
47 48
 - [`incognito`](Reference.md#incognito)
@@ -756,6 +757,16 @@ If true, use WKWebView instead of UIWebView.
756 757
 
757 758
 ---
758 759
 
760
+### `keyboardDisplayRequiresUserAction`
761
+
762
+If false, web content can programmatically display the keyboard when using the WKWebView. The default value is `true`.
763
+
764
+| Type    | Required | Platform |
765
+| ------- | -------- | -------- |
766
+| boolean | No       | iOS      |
767
+
768
+---
769
+
759 770
 ### `hideKeyboardAccessoryView`
760 771
 
761 772
 If true, this will hide the keyboard accessory view (< > and Done) when using the WKWebView.

+ 1
- 0
ios/RNCWKWebView.h Просмотреть файл

@@ -37,6 +37,7 @@
37 37
 #endif
38 38
 @property (nonatomic, assign) UIEdgeInsets contentInset;
39 39
 @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
40
+@property (nonatomic, assign) BOOL keyboardDisplayRequiresUserAction;
40 41
 @property (nonatomic, assign) BOOL hideKeyboardAccessoryView;
41 42
 @property (nonatomic, assign) BOOL allowsBackForwardNavigationGestures;
42 43
 @property (nonatomic, assign) BOOL incognito;

+ 95
- 4
ios/RNCWKWebView.m Просмотреть файл

@@ -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)

+ 4
- 0
ios/RNCWKWebViewManager.m Просмотреть файл

@@ -101,6 +101,10 @@ RCT_CUSTOM_VIEW_PROPERTY(showsVerticalScrollIndicator, BOOL, RNCWKWebView) {
101 101
   view.showsVerticalScrollIndicator = json == nil ? true : [RCTConvert BOOL: json];
102 102
 }
103 103
 
104
+RCT_CUSTOM_VIEW_PROPERTY(keyboardDisplayRequiresUserAction, BOOL, RNCWKWebView) {
105
+  view.keyboardDisplayRequiresUserAction = json == nil ? true : [RCTConvert BOOL: json];
106
+}
107
+
104 108
 RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString *)script)
105 109
 {
106 110
   [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWKWebView *> *viewRegistry) {

+ 1
- 1
package.json Просмотреть файл

@@ -8,7 +8,7 @@
8 8
     "Thibault Malbranche <malbranche.thibault@gmail.com>"
9 9
   ],
10 10
   "license": "MIT",
11
-  "version": "5.7.0",
11
+  "version": "5.8.1",
12 12
   "homepage": "https://github.com/react-native-community/react-native-webview#readme",
13 13
   "scripts": {
14 14
     "ci": "CI=true && yarn lint && yarn test",

+ 15
- 1
src/WebViewTypes.ts Просмотреть файл

@@ -91,7 +91,7 @@ export interface WebViewNativeEvent {
91 91
   lockIdentifier: number;
92 92
 }
93 93
 
94
-export interface WebViewProgressEvent extends WebViewNativeEvent {
94
+export interface WebViewNativeProgressEvent extends WebViewNativeEvent {
95 95
   progress: number;
96 96
 }
97 97
 
@@ -122,6 +122,8 @@ export interface WebViewError extends WebViewNativeEvent {
122 122
 
123 123
 export type WebViewEvent = NativeSyntheticEvent<WebViewNativeEvent>;
124 124
 
125
+export type WebViewProgressEvent = NativeSyntheticEvent<WebViewNativeProgressEvent>;
126
+
125 127
 export type WebViewNavigationEvent = NativeSyntheticEvent<WebViewNavigation>;
126 128
 
127 129
 export type WebViewMessageEvent = NativeSyntheticEvent<WebViewMessage>;
@@ -401,6 +403,18 @@ export interface IOSWebViewProps extends WebViewSharedProps {
401 403
    */
402 404
   directionalLockEnabled?: boolean;
403 405
 
406
+  /**
407
+   * A Boolean value indicating whether web content can programmatically display the keyboard.
408
+   *
409
+   * When this property is set to true, the user must explicitly tap the elements in the
410
+   * web view to display the keyboard (or other relevant input view) for that element.
411
+   * When set to false, a focus event on an element causes the input view to be displayed
412
+   * and associated with that element automatically.
413
+   *
414
+   * The default value is `true`.
415
+   * @platform ios
416
+   */
417
+  keyboardDisplayRequiresUserAction?: boolean;
404 418
 }
405 419
 
406 420
 export interface AndroidWebViewProps extends WebViewSharedProps {