Selaa lähdekoodia

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

Jamon Holmgren 6 vuotta sitten
vanhempi
commit
89f5117c08
No account linked to committer's email address
8 muutettua tiedostoa jossa 148 lisäystä ja 8 poistoa
  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 Näytä tiedosto

150
       "contributions": [
150
       "contributions": [
151
         "doc"
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
   "contributorsPerLine": 7
174
   "contributorsPerLine": 7

+ 2
- 2
README.md
File diff suppressed because it is too large
Näytä tiedosto


+ 11
- 0
docs/Reference.md Näytä tiedosto

42
 - [`useWebKit`](Reference.md#usewebkit)
42
 - [`useWebKit`](Reference.md#usewebkit)
43
 - [`url`](Reference.md#url)
43
 - [`url`](Reference.md#url)
44
 - [`html`](Reference.md#html)
44
 - [`html`](Reference.md#html)
45
+- [`keyboardDisplayRequiresUserAction`](Reference.md#keyboardDisplayRequiresUserAction)
45
 - [`hideKeyboardAccessoryView`](Reference.md#hidekeyboardaccessoryview)
46
 - [`hideKeyboardAccessoryView`](Reference.md#hidekeyboardaccessoryview)
46
 - [`allowsBackForwardNavigationGestures`](Reference.md#allowsbackforwardnavigationgestures)
47
 - [`allowsBackForwardNavigationGestures`](Reference.md#allowsbackforwardnavigationgestures)
47
 - [`incognito`](Reference.md#incognito)
48
 - [`incognito`](Reference.md#incognito)
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
 ### `hideKeyboardAccessoryView`
770
 ### `hideKeyboardAccessoryView`
760
 
771
 
761
 If true, this will hide the keyboard accessory view (< > and Done) when using the WKWebView.
772
 If true, this will hide the keyboard accessory view (< > and Done) when using the WKWebView.

+ 1
- 0
ios/RNCWKWebView.h Näytä tiedosto

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

+ 95
- 4
ios/RNCWKWebView.m Näytä tiedosto

41
 {
41
 {
42
   UIColor * _savedBackgroundColor;
42
   UIColor * _savedBackgroundColor;
43
   BOOL _savedHideKeyboardAccessoryView;
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
 - (instancetype)initWithFrame:(CGRect)frame
53
 - (instancetype)initWithFrame:(CGRect)frame
54
     _directionalLockEnabled = YES;
61
     _directionalLockEnabled = YES;
55
     _automaticallyAdjustContentInsets = YES;
62
     _automaticallyAdjustContentInsets = YES;
56
     _contentInset = UIEdgeInsetsZero;
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
   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
62
     [[NSNotificationCenter defaultCenter]
72
     [[NSNotificationCenter defaultCenter]
63
       addObserver:self
73
       addObserver:self
64
       selector:@selector(keyboardWillHide)
74
       selector:@selector(keyboardWillHide)
67
       addObserver:self
77
       addObserver:self
68
       selector:@selector(keyboardWillShow)
78
       selector:@selector(keyboardWillShow)
69
       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];
70
   }
84
   }
71
-
85
+  
72
   return self;
86
   return self;
73
 }
87
 }
74
 
88
 
214
 
228
 
215
     [self addSubview:_webView];
229
     [self addSubview:_webView];
216
     [self setHideKeyboardAccessoryView: _savedHideKeyboardAccessoryView];
230
     [self setHideKeyboardAccessoryView: _savedHideKeyboardAccessoryView];
231
+    [self setKeyboardDisplayRequiresUserAction: _savedKeyboardDisplayRequiresUserAction];
217
     [self visitSource];
232
     [self visitSource];
218
   }
233
   }
219
 }
234
 }
238
     [super removeFromSuperview];
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
 -(void)keyboardWillHide
274
 -(void)keyboardWillHide
242
 {
275
 {
243
     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];
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
 -(void)setHideKeyboardAccessoryView:(BOOL)hideKeyboardAccessoryView
458
 -(void)setHideKeyboardAccessoryView:(BOOL)hideKeyboardAccessoryView
368
 {
459
 {
369
     if (_webView == nil) {
460
     if (_webView == nil) {
460
 {
551
 {
461
   NSDictionary *event = @{
552
   NSDictionary *event = @{
462
     @"url": _webView.URL.absoluteString ?: @"",
553
     @"url": _webView.URL.absoluteString ?: @"",
463
-    @"title": _webView.title,
554
+    @"title": _webView.title ?: @"",
464
     @"loading" : @(_webView.loading),
555
     @"loading" : @(_webView.loading),
465
     @"canGoBack": @(_webView.canGoBack),
556
     @"canGoBack": @(_webView.canGoBack),
466
     @"canGoForward" : @(_webView.canGoForward)
557
     @"canGoForward" : @(_webView.canGoForward)

+ 4
- 0
ios/RNCWKWebViewManager.m Näytä tiedosto

101
   view.showsVerticalScrollIndicator = json == nil ? true : [RCTConvert BOOL: json];
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
 RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString *)script)
108
 RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString *)script)
105
 {
109
 {
106
   [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWKWebView *> *viewRegistry) {
110
   [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWKWebView *> *viewRegistry) {

+ 1
- 1
package.json Näytä tiedosto

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

+ 15
- 1
src/WebViewTypes.ts Näytä tiedosto

91
   lockIdentifier: number;
91
   lockIdentifier: number;
92
 }
92
 }
93
 
93
 
94
-export interface WebViewProgressEvent extends WebViewNativeEvent {
94
+export interface WebViewNativeProgressEvent extends WebViewNativeEvent {
95
   progress: number;
95
   progress: number;
96
 }
96
 }
97
 
97
 
122
 
122
 
123
 export type WebViewEvent = NativeSyntheticEvent<WebViewNativeEvent>;
123
 export type WebViewEvent = NativeSyntheticEvent<WebViewNativeEvent>;
124
 
124
 
125
+export type WebViewProgressEvent = NativeSyntheticEvent<WebViewNativeProgressEvent>;
126
+
125
 export type WebViewNavigationEvent = NativeSyntheticEvent<WebViewNavigation>;
127
 export type WebViewNavigationEvent = NativeSyntheticEvent<WebViewNavigation>;
126
 
128
 
127
 export type WebViewMessageEvent = NativeSyntheticEvent<WebViewMessage>;
129
 export type WebViewMessageEvent = NativeSyntheticEvent<WebViewMessage>;
401
    */
403
    */
402
   directionalLockEnabled?: boolean;
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
 export interface AndroidWebViewProps extends WebViewSharedProps {
420
 export interface AndroidWebViewProps extends WebViewSharedProps {