Parcourir la source

fix(iOS): UIWebView Removal (#828)

Apple required us to remove this (see #819)

BREAKING CHANGE: UIWebView has been removed
BREAKING CHANGE: useWebkit prop removal
BREAKING CHANGE: scalesPageToFit prop removal on iOS (since it's not compatible with WKWebview)
BREAKING CHANGE: Renamed RNCWKWebView to RNCWebView on iOS
Thibault Malbranche il y a 5 ans
Parent
révision
8549be5fd0
No account linked to committer's email address

+ 7
- 8
README.md Voir le fichier

@@ -1,8 +1,8 @@
1 1
 # React Native WebView - a Modern, Cross-Platform WebView for React Native
2 2
 
3
-[![star this repo](http://githubbadges.com/star.svg?user=react-native-community&repo=react-native-webview&style=flat)](https://github.com/react-native-community/react-native-webview) 
4
-[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) 
5
-[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors) 
3
+[![star this repo](http://githubbadges.com/star.svg?user=react-native-community&repo=react-native-webview&style=flat)](https://github.com/react-native-community/react-native-webview)
4
+[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
5
+[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors)
6 6
 [![Known Vulnerabilities](https://snyk.io/test/github/react-native-community/react-native-webview/badge.svg?style=flat-square)](https://snyk.io/test/github/react-native-community/react-native-webview)
7 7
 <a href="https://www.npmjs.com/package/react-native-webview"><img src="https://img.shields.io/npm/v/react-native-webview.svg"></a>
8 8
 
@@ -17,7 +17,7 @@ _This project is maintained for free by these people using both their free time
17 17
 
18 18
 ## Platforms Supported
19 19
 
20
-- [x] iOS (both UIWebView and WKWebView)
20
+- [x] iOS
21 21
 - [x] Android
22 22
 
23 23
 _Note: Expo support for React Native WebView started with [Expo SDK v33.0.0](https://blog.expo.io/expo-sdk-v33-0-0-is-now-available-52d1c99dfe4c)._
@@ -34,10 +34,10 @@ This project follows [semantic versioning](https://semver.org/). We do not hesit
34 34
 
35 35
 Current Version: ![version](https://img.shields.io/npm/v/react-native-webview.svg)
36 36
 
37
-yarn add react-native-webview@androidx
37
+- [7.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v7.0.0 - Removed UIWebView
38
+
38 39
 - [6.0.**2**](https://github.com/react-native-community/react-native-webview/releases/tag/v6.0.2) - Update to AndroidX. Make sure to enable it in your project's `android/gradle.properties`. See [Getting Started Guide](docs/Getting-Started.md).
39 40
 
40
-yarn add react-native-webview
41 41
 - [5.0.**1**](https://github.com/react-native-community/react-native-webview/releases/tag/v5.0.0) - Refactored the old postMessage implementation for communication from webview to native.
42 42
 - [4.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v4.0.0) - Added cache (enabled by default).
43 43
 - [3.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v3.0.0) - WKWebview: Add shared process pool so cookies and localStorage are shared across webviews in iOS (enabled by default).
@@ -45,7 +45,6 @@ yarn add react-native-webview
45 45
 
46 46
 **Upcoming:**
47 47
 
48
-- UIWebView removal
49 48
 - this.webView.postMessage() removal (never documented and less flexible than injectJavascript)
50 49
 - Kotlin rewrite
51 50
 - Maybe Swift rewrite
@@ -73,7 +72,7 @@ For more, read the [API Reference](./docs/Reference.md) and [Guide](./docs/Guide
73 72
 
74 73
 ## Common issues
75 74
 
76
-- If you're getting `Invariant Violation: Native component for "RNCWKWebView does not exist"` it likely means you forgot to run `react-native link` or there was some error with the linking process
75
+- If you're getting `Invariant Violation: Native component for "RNCWebView does not exist"` it likely means you forgot to run `react-native link` or there was some error with the linking process
77 76
 
78 77
 ## Contributing
79 78
 

+ 0
- 1
docs/Contributing.md Voir le fichier

@@ -45,5 +45,4 @@ $ yarn add ../react-native-webview && react-native link react-native-webview
45 45
 ## Notes
46 46
 
47 47
 - We use TypeScript.
48
-- We don't intend to support UIWebView and will remove it soon.
49 48
 - After pulling this repo and installing all dependencies, you can run tests using the command: `yarn ci`

+ 1
- 1
docs/Custom-iOS.md Voir le fichier

@@ -137,7 +137,7 @@ Once these are exposed, you can reference them in your custom web view class.
137 137
 If you open webpages that needs a Client Certificate for Authentication, you can create a credential and pass it to the webview:
138 138
 
139 139
 ```
140
-[RNCWKWebView setClientAuthenticationCredential:credential];
140
+[RNCWebView setClientAuthenticationCredential:credential];
141 141
 ```
142 142
 
143 143
 This can be paired with a call from Javascript to pass a string label for the certificate stored in keychain and use native calls to fetch the certificate to create a credential object. This call can be made anywhere that makes sense for your application (e.g. as part of the user authentication stack). The only requirement is to make this call before displaying any webviews.

+ 2
- 2
docs/Guide.md Voir le fichier

@@ -297,7 +297,7 @@ This runs the JavaScript in the `runFirst` string once the page is loaded. In th
297 297
 
298 298
 _Under the hood_
299 299
 
300
-> On iOS, `injectedJavaScript` runs a method on WKWebView called `evaluateJavaScript:completionHandler:`
300
+> On iOS, `injectedJavaScript` runs a method on WebView called `evaluateJavaScript:completionHandler:`
301 301
 > On Android, `injectedJavaScript` runs a method on the Android WebView called `evaluateJavascriptWithFallback`
302 302
 
303 303
 #### The `injectJavaScript` method
@@ -341,7 +341,7 @@ After 3 seconds, this code turns the background blue:
341 341
 
342 342
 _Under the hood_
343 343
 
344
-> On iOS, `injectJavaScript` calls WKWebView's `evaluateJS:andThen:`
344
+> On iOS, `injectJavaScript` calls WebView's `evaluateJS:andThen:`
345 345
 > On Android, `injectJavaScript` calls Android WebView's `evaluateJavascriptWithFallback` method
346 346
 
347 347
 #### The `window.ReactNativeWebView.postMessage` method and `onMessage` prop

+ 25
- 42
docs/Reference.md Voir le fichier

@@ -43,7 +43,6 @@ This document lays out the current public properties and methods for the React N
43 43
 - [`geolocationEnabled`](Reference.md#geolocationenabled)
44 44
 - [`allowUniversalAccessFromFileURLs`](Reference.md#allowUniversalAccessFromFileURLs)
45 45
 - [`allowingReadAccessToURL`](Reference.md#allowingReadAccessToURL)
46
-- [`useWebKit`](Reference.md#usewebkit)
47 46
 - [`url`](Reference.md#url)
48 47
 - [`html`](Reference.md#html)
49 48
 - [`keyboardDisplayRequiresUserAction`](Reference.md#keyboardDisplayRequiresUserAction)
@@ -132,7 +131,7 @@ const INJECTED_JAVASCRIPT = `(function() {
132 131
   source={{ uri: 'https://facebook.github.io/react-native' }}
133 132
   injectedJavaScript={INJECTED_JAVASCRIPT}
134 133
   onMessage={this.onMessage}
135
-/>
134
+/>;
136 135
 ```
137 136
 
138 137
 ---
@@ -312,7 +311,6 @@ Function that is invoked when the `WebView` is loading.
312 311
 
313 312
 > **_Note_**
314 313
 >
315
-> On iOS, when useWebKit=false, this prop will not work.
316 314
 > On android, You can't get the url property, meaning that `event.nativeEvent.url` will be null.
317 315
 
318 316
 | Type     | Required |
@@ -459,11 +457,9 @@ Example:
459 457
 
460 458
 Boolean that controls whether the web content is scaled to fit the view and enables the user to change the scale. The default value is `true`.
461 459
 
462
-On iOS, when [`useWebKit=true`](Reference.md#usewebkit), this prop will not work.
463
-
464
-| Type | Required |
465
-| ---- | -------- |
466
-| bool | No       |
460
+| Type | Required | Platform |
461
+| ---- | -------- | -------- |
462
+| bool | No       | Android  |
467 463
 
468 464
 ---
469 465
 
@@ -605,26 +601,26 @@ Boolean value to enable third party cookies in the `WebView`. Used on Android Lo
605 601
 
606 602
 ### `userAgent`
607 603
 
608
-Sets the user-agent for the `WebView`. This will only work for iOS if you are using WKWebView, not UIWebView (see https://developer.apple.com/documentation/webkit/wkwebview/1414950-customuseragent).
604
+Sets the user-agent for the `WebView`.
609 605
 
610
-| Type   | Required | Platform               |
611
-| ------ | -------- | ---------------------- |
612
-| string | No       | Android, iOS WKWebView |
606
+| Type   | Required |
607
+| ------ | -------- |
608
+| string | No       |
613 609
 
614 610
 ---
615 611
 
616 612
 ### `applicationNameForUserAgent`
617 613
 
618
-Append to the existing user-agent. This will only work for iOS if you are using WKWebView, not UIWebView. Setting `userAgent` will override this.
614
+Append to the existing user-agent. Setting `userAgent` will override this.
619 615
 
620
-| Type   | Required | Platform      |
621
-| ------ | -------- | ------------- |
622
-| string | No       | Android, iOS WKWebView |
616
+| Type   | Required |
617
+| ------ | -------- |
618
+| string | No       |
623 619
 
624 620
 ```jsx
625 621
 <WebView
626 622
   source={{ uri: 'https://facebook.github.io/react-native' }}
627
-  applicationNameForUserAgent={"DemoApp/1.1.0"}
623
+  applicationNameForUserAgent={'DemoApp/1.1.0'}
628 624
 />
629 625
 // Resulting User-Agent will look like:
630 626
 // Mozilla/5.0 (Linux; Android 8.1.0; Android SDK built for x86 Build/OSM1.180201.021; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36 DemoApp/1.1.0
@@ -722,9 +718,6 @@ Possible values for `dataDetectorTypes` are:
722 718
 - `calendarEvent`
723 719
 - `none`
724 720
 - `all`
725
-
726
-With the [new WebKit](Reference.md#usewebkit) implementation, we have three new values:
727
-
728 721
 - `trackingNumber`
729 722
 - `flightNumber`
730 723
 - `lookupSuggestion`
@@ -798,21 +791,11 @@ Boolean that sets whether JavaScript running in the context of a file scheme URL
798 791
 
799 792
 ### `allowingReadAccessToURL`
800 793
 
801
-A String value that indicates which URLs the WebView's file can then reference in scripts, AJAX requests, and CSS imports. This is only used in `RNCWKWebView` for WebViews that are loaded with a source.uri set to a `'file://'` URL. If not provided, the default is to only allow read access to the URL provided in source.uri itself.
802
-
803
-| Type   | Required | Platform      |
804
-| ------ | -------- | ------------- |
805
-| string | No       | iOS WKWebView |
806
-
807
----
808
-
809
-### `useWebKit`
810
-
811
-If true, use WKWebView instead of UIWebView.
794
+A String value that indicates which URLs the WebView's file can then reference in scripts, AJAX requests, and CSS imports. This is only used in for WebViews that are loaded with a source.uri set to a `'file://'` URL. If not provided, the default is to only allow read access to the URL provided in source.uri itself.
812 795
 
813
-| Type    | Required | Platform |
814
-| ------- | -------- | -------- |
815
-| boolean | No       | iOS      |
796
+| Type   | Required | Platform |
797
+| ------ | -------- | -------- |
798
+| string | No       | iOS      |
816 799
 
817 800
 ---
818 801
 
@@ -838,7 +821,7 @@ If true, use WKWebView instead of UIWebView.
838 821
 
839 822
 ### `keyboardDisplayRequiresUserAction`
840 823
 
841
-If false, web content can programmatically display the keyboard when using the WKWebView. The default value is `true`.
824
+If false, web content can programmatically display the keyboard. The default value is `true`.
842 825
 
843 826
 | Type    | Required | Platform |
844 827
 | ------- | -------- | -------- |
@@ -848,7 +831,7 @@ If false, web content can programmatically display the keyboard when using the W
848 831
 
849 832
 ### `hideKeyboardAccessoryView`
850 833
 
851
-If true, this will hide the keyboard accessory view (< > and Done) when using the WKWebView.
834
+If true, this will hide the keyboard accessory view (< > and Done).
852 835
 
853 836
 | Type    | Required | Platform |
854 837
 | ------- | -------- | -------- |
@@ -858,7 +841,7 @@ If true, this will hide the keyboard accessory view (< > and Done) when using th
858 841
 
859 842
 ### `allowsBackForwardNavigationGestures`
860 843
 
861
-If true, this will be able horizontal swipe gestures when using the WKWebView. The default value is `false`.
844
+If true, this will be able horizontal swipe gestures. The default value is `false`.
862 845
 
863 846
 | Type    | Required | Platform |
864 847
 | ------- | -------- | -------- |
@@ -870,9 +853,9 @@ If true, this will be able horizontal swipe gestures when using the WKWebView. T
870 853
 
871 854
 Does not store any data within the lifetime of the WebView.
872 855
 
873
-| Type    | Required | Platform               |
874
-| ------- | -------- | ---------------------- |
875
-| boolean | No       | Android, iOS WKWebView |
856
+| Type    | Required |
857
+| ------- | -------- |
858
+| boolean | No       |
876 859
 
877 860
 ---
878 861
 
@@ -898,7 +881,7 @@ Sets whether the WebView should disable saving form data. The default value is `
898 881
 
899 882
 ### `cacheEnabled`
900 883
 
901
-Sets whether WebView & WKWebView should use browser caching.
884
+Sets whether WebView should use browser caching.
902 885
 
903 886
 | Type    | Required | Default |
904 887
 | ------- | -------- | ------- |
@@ -928,7 +911,7 @@ A Boolean value that determines whether pressing on a link displays a preview of
928 911
 
929 912
 ### `sharedCookiesEnabled`
930 913
 
931
-Set `true` if shared cookies from `[NSHTTPCookieStorage sharedHTTPCookieStorage]` should used for every load request in the `RNCWKWebView`. The default value is `false`.
914
+Set `true` if shared cookies from `[NSHTTPCookieStorage sharedHTTPCookieStorage]` should used for every load request in the WebView. The default value is `false`.
932 915
 
933 916
 | Type    | Required | Platform |
934 917
 | ------- | -------- | -------- |

+ 0
- 39
ios/RNCUIWebView.h Voir le fichier

@@ -1,39 +0,0 @@
1
-#import <React/RCTView.h>
2
-
3
-@class RNCUIWebView;
4
-
5
-/**
6
- * Special scheme used to pass messages to the injectedJavaScript
7
- * code without triggering a page load. Usage:
8
- *
9
- *   window.location.href = RNCJSNavigationScheme + '://hello'
10
- */
11
-extern NSString *const RNCJSNavigationScheme;
12
-
13
-@protocol RNCUIWebViewDelegate <NSObject>
14
-
15
-- (BOOL)webView:(RNCUIWebView *)webView
16
-shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
17
-   withCallback:(RCTDirectEventBlock)callback;
18
-
19
-@end
20
-
21
-@interface RNCUIWebView : RCTView
22
-
23
-@property (nonatomic, weak) id<RNCUIWebViewDelegate> delegate;
24
-
25
-@property (nonatomic, copy) NSDictionary *source;
26
-@property (nonatomic, assign) UIEdgeInsets contentInset;
27
-@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
28
-@property (nonatomic, assign) BOOL messagingEnabled;
29
-@property (nonatomic, copy) NSString *injectedJavaScript;
30
-@property (nonatomic, assign) BOOL scalesPageToFit;
31
-
32
-- (void)goForward;
33
-- (void)goBack;
34
-- (void)reload;
35
-- (void)stopLoading;
36
-- (void)postMessage:(NSString *)message;
37
-- (void)injectJavaScript:(NSString *)script;
38
-
39
-@end

+ 0
- 332
ios/RNCUIWebView.m Voir le fichier

@@ -1,332 +0,0 @@
1
-#import "RNCUIWebView.h"
2
-
3
-// #import <UIKit/UIKit.h>
4
-#import <React/RCTAutoInsetsProtocol.h>
5
-#import <React/RCTConvert.h>
6
-#import <React/RCTEventDispatcher.h>
7
-#import <React/RCTLog.h>
8
-#import <React/RCTUtils.h>
9
-#import <React/RCTView.h>
10
-#import <React/UIView+React.h>
11
-
12
-NSString *const RNCJSNavigationScheme = @"react-js-navigation";
13
-
14
-static NSString *const MessageHandlerName = @"ReactNativeWebView";
15
-
16
-@interface RNCUIWebView () <UIWebViewDelegate, RCTAutoInsetsProtocol>
17
-
18
-@property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
19
-@property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish;
20
-@property (nonatomic, copy) RCTDirectEventBlock onLoadingError;
21
-@property (nonatomic, copy) RCTDirectEventBlock onShouldStartLoadWithRequest;
22
-@property (nonatomic, copy) RCTDirectEventBlock onMessage;
23
-
24
-@end
25
-
26
-@implementation RNCUIWebView
27
-{
28
-  UIWebView *_webView;
29
-  NSString *_injectedJavaScript;
30
-}
31
-
32
-- (void)dealloc
33
-{
34
-  _webView.delegate = nil;
35
-}
36
-
37
-- (instancetype)initWithFrame:(CGRect)frame
38
-{
39
-  if ((self = [super initWithFrame:frame])) {
40
-    super.backgroundColor = [UIColor clearColor];
41
-    _automaticallyAdjustContentInsets = YES;
42
-    _contentInset = UIEdgeInsetsZero;
43
-    _webView = [[UIWebView alloc] initWithFrame:self.bounds];
44
-    _webView.delegate = self;
45
-#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
46
-    if ([_webView.scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
47
-      _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
48
-    }
49
-#endif
50
-    [self addSubview:_webView];
51
-  }
52
-  return self;
53
-}
54
-
55
-RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
56
-
57
-- (void)goForward
58
-{
59
-  [_webView goForward];
60
-}
61
-
62
-- (void)goBack
63
-{
64
-  [_webView goBack];
65
-}
66
-
67
-- (void)reload
68
-{
69
-  NSURLRequest *request = [RCTConvert NSURLRequest:self.source];
70
-  if (request.URL && !_webView.request.URL.absoluteString.length) {
71
-    [_webView loadRequest:request];
72
-  }
73
-  else {
74
-    [_webView reload];
75
-  }
76
-}
77
-
78
-- (void)stopLoading
79
-{
80
-  [_webView stopLoading];
81
-}
82
-
83
-- (void)postMessage:(NSString *)message
84
-{
85
-  NSDictionary *eventInitDict = @{
86
-    @"data": message,
87
-  };
88
-  NSString *source = [NSString
89
-    stringWithFormat:@"window.dispatchEvent(new MessageEvent('message', %@));",
90
-    RCTJSONStringify(eventInitDict, NULL)
91
-  ];
92
-  [_webView stringByEvaluatingJavaScriptFromString:source];
93
-}
94
-
95
-- (void)injectJavaScript:(NSString *)script
96
-{
97
-  [_webView stringByEvaluatingJavaScriptFromString:script];
98
-}
99
-
100
-- (void)setSource:(NSDictionary *)source
101
-{
102
-  if (![_source isEqualToDictionary:source]) {
103
-    _source = [source copy];
104
-
105
-    // Check for a static html source first
106
-    NSString *html = [RCTConvert NSString:source[@"html"]];
107
-    if (html) {
108
-      NSURL *baseURL = [RCTConvert NSURL:source[@"baseUrl"]];
109
-      if (!baseURL) {
110
-        baseURL = [NSURL URLWithString:@"about:blank"];
111
-      }
112
-      [_webView loadHTMLString:html baseURL:baseURL];
113
-      return;
114
-    }
115
-
116
-    NSURLRequest *request = [RCTConvert NSURLRequest:source];
117
-    // Because of the way React works, as pages redirect, we actually end up
118
-    // passing the redirect urls back here, so we ignore them if trying to load
119
-    // the same url. We'll expose a call to 'reload' to allow a user to load
120
-    // the existing page.
121
-    if ([request.URL isEqual:_webView.request.URL]) {
122
-      return;
123
-    }
124
-    if (!request.URL) {
125
-      // Clear the webview
126
-      [_webView loadHTMLString:@"" baseURL:nil];
127
-      return;
128
-    }
129
-    [_webView loadRequest:request];
130
-  }
131
-}
132
-
133
-- (void)layoutSubviews
134
-{
135
-  [super layoutSubviews];
136
-  _webView.frame = self.bounds;
137
-}
138
-
139
-- (void)setContentInset:(UIEdgeInsets)contentInset
140
-{
141
-  _contentInset = contentInset;
142
-  [RCTView autoAdjustInsetsForView:self
143
-                    withScrollView:_webView.scrollView
144
-                      updateOffset:NO];
145
-}
146
-
147
-- (void)setScalesPageToFit:(BOOL)scalesPageToFit
148
-{
149
-  if (_webView.scalesPageToFit != scalesPageToFit) {
150
-    _webView.scalesPageToFit = scalesPageToFit;
151
-    [_webView reload];
152
-  }
153
-}
154
-
155
-- (BOOL)scalesPageToFit
156
-{
157
-  return _webView.scalesPageToFit;
158
-}
159
-
160
-- (void)setBackgroundColor:(UIColor *)backgroundColor
161
-{
162
-  CGFloat alpha = CGColorGetAlpha(backgroundColor.CGColor);
163
-  self.opaque = _webView.opaque = (alpha == 1.0);
164
-  _webView.backgroundColor = backgroundColor;
165
-}
166
-
167
-- (UIColor *)backgroundColor
168
-{
169
-  return _webView.backgroundColor;
170
-}
171
-
172
-- (NSMutableDictionary<NSString *, id> *)baseEvent
173
-{
174
-  NSMutableDictionary<NSString *, id> *event = [[NSMutableDictionary alloc] initWithDictionary:@{
175
-    @"url": _webView.request.URL.absoluteString ?: @"",
176
-    @"loading" : @(_webView.loading),
177
-    @"title": [_webView stringByEvaluatingJavaScriptFromString:@"document.title"],
178
-    @"canGoBack": @(_webView.canGoBack),
179
-    @"canGoForward" : @(_webView.canGoForward),
180
-  }];
181
-
182
-  return event;
183
-}
184
-
185
-- (void)refreshContentInset
186
-{
187
-  [RCTView autoAdjustInsetsForView:self
188
-                    withScrollView:_webView.scrollView
189
-                      updateOffset:YES];
190
-}
191
-
192
-#pragma mark - UIWebViewDelegate methods
193
-
194
-- (BOOL)webView:(__unused UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
195
- navigationType:(UIWebViewNavigationType)navigationType
196
-{
197
-  BOOL isJSNavigation = [request.URL.scheme isEqualToString:RNCJSNavigationScheme];
198
-
199
-  static NSDictionary<NSNumber *, NSString *> *navigationTypes;
200
-  static dispatch_once_t onceToken;
201
-  dispatch_once(&onceToken, ^{
202
-    navigationTypes = @{
203
-      @(UIWebViewNavigationTypeLinkClicked): @"click",
204
-      @(UIWebViewNavigationTypeFormSubmitted): @"formsubmit",
205
-      @(UIWebViewNavigationTypeBackForward): @"backforward",
206
-      @(UIWebViewNavigationTypeReload): @"reload",
207
-      @(UIWebViewNavigationTypeFormResubmitted): @"formresubmit",
208
-      @(UIWebViewNavigationTypeOther): @"other",
209
-    };
210
-  });
211
-
212
-  // skip this for the JS Navigation handler
213
-  if (!isJSNavigation && _onShouldStartLoadWithRequest) {
214
-    NSMutableDictionary<NSString *, id> *event = [self baseEvent];
215
-    [event addEntriesFromDictionary: @{
216
-      @"url": (request.URL).absoluteString,
217
-      @"mainDocumentURL": (request.mainDocumentURL).absoluteString,
218
-      @"navigationType": navigationTypes[@(navigationType)]
219
-    }];
220
-    if (![self.delegate webView:self
221
-      shouldStartLoadForRequest:event
222
-                   withCallback:_onShouldStartLoadWithRequest]) {
223
-      return NO;
224
-    }
225
-  }
226
-
227
-  if (_onLoadingStart) {
228
-    // We have this check to filter out iframe requests and whatnot
229
-    BOOL isTopFrame = [request.URL isEqual:request.mainDocumentURL];
230
-    if (isTopFrame) {
231
-      NSMutableDictionary<NSString *, id> *event = [self baseEvent];
232
-      [event addEntriesFromDictionary: @{
233
-        @"url": (request.URL).absoluteString,
234
-        @"navigationType": navigationTypes[@(navigationType)]
235
-      }];
236
-      _onLoadingStart(event);
237
-    }
238
-  }
239
-
240
-  if (isJSNavigation && [request.URL.host isEqualToString:MessageHandlerName]) {
241
-    NSString *data = request.URL.query;
242
-    data = [data stringByReplacingOccurrencesOfString:@"+" withString:@" "];
243
-    data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
244
-
245
-    NSMutableDictionary<NSString *, id> *event = [self baseEvent];
246
-    [event addEntriesFromDictionary: @{
247
-      @"data": data,
248
-    }];
249
-
250
-    NSString *source = [NSString stringWithFormat:@"window.%@.messageReceived();", MessageHandlerName];
251
-
252
-    [_webView stringByEvaluatingJavaScriptFromString:source];
253
-
254
-    _onMessage(event);
255
-  }
256
-
257
-  // JS Navigation handler
258
-  return !isJSNavigation;
259
-}
260
-
261
-- (void)webView:(__unused UIWebView *)webView didFailLoadWithError:(NSError *)error
262
-{
263
-  if (_onLoadingError) {
264
-    if ([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled) {
265
-      // NSURLErrorCancelled is reported when a page has a redirect OR if you load
266
-      // a new URL in the WebView before the previous one came back. We can just
267
-      // ignore these since they aren't real errors.
268
-      // http://stackoverflow.com/questions/1024748/how-do-i-fix-nsurlerrordomain-error-999-in-iphone-3-0-os
269
-      return;
270
-    }
271
-
272
-    if ([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102) {
273
-      // Error code 102 "Frame load interrupted" is raised by the UIWebView if
274
-      // its delegate returns FALSE from webView:shouldStartLoadWithRequest:navigationType
275
-      // when the URL is from an http redirect. This is a common pattern when
276
-      // implementing OAuth with a WebView.
277
-      return;
278
-    }
279
-
280
-    NSMutableDictionary<NSString *, id> *event = [self baseEvent];
281
-    [event addEntriesFromDictionary:@{
282
-      @"domain": error.domain,
283
-      @"code": @(error.code),
284
-      @"description": error.localizedDescription,
285
-    }];
286
-    _onLoadingError(event);
287
-  }
288
-}
289
-
290
-- (void)webViewDidFinishLoad:(UIWebView *)webView
291
-{
292
-  if (_messagingEnabled) {
293
-    NSString *source = [NSString stringWithFormat:
294
-      @"(function() {"
295
-       "  var messageQueue = [];"
296
-       "  var messagePending = false;"
297
-
298
-       "  function processQueue () {"
299
-       "    if (!messageQueue.length || messagePending) return;"
300
-       "    messagePending = true;"
301
-       "    document.location = '%@://%@?' + encodeURIComponent(messageQueue.shift());"
302
-       "  }"
303
-
304
-       "  window.%@ = {"
305
-       "    postMessage: function (data) {"
306
-       "      messageQueue.push(String(data));"
307
-       "      processQueue();"
308
-       "    },"
309
-       "    messageReceived: function () {"
310
-       "      messagePending = false;"
311
-       "      processQueue();"
312
-       "    }"
313
-       "  };"
314
-       "})();", RNCJSNavigationScheme, MessageHandlerName, MessageHandlerName
315
-    ];
316
-    [webView stringByEvaluatingJavaScriptFromString:source];
317
-  }
318
-  if (_injectedJavaScript != nil) {
319
-    NSString *jsEvaluationValue = [webView stringByEvaluatingJavaScriptFromString:_injectedJavaScript];
320
-
321
-    NSMutableDictionary<NSString *, id> *event = [self baseEvent];
322
-    event[@"jsEvaluationValue"] = jsEvaluationValue;
323
-
324
-    _onLoadingFinish(event);
325
-  }
326
-  // we only need the final 'finishLoad' call so only fire the event when we're actually done loading.
327
-  else if (_onLoadingFinish && !webView.loading && ![webView.request.URL.absoluteString isEqualToString:@"about:blank"]) {
328
-    _onLoadingFinish([self baseEvent]);
329
-  }
330
-}
331
-
332
-@end

+ 0
- 5
ios/RNCUIWebViewManager.h Voir le fichier

@@ -1,5 +0,0 @@
1
-#import <React/RCTViewManager.h>
2
-
3
-@interface RNCUIWebViewManager : RCTViewManager
4
-
5
-@end

+ 0
- 154
ios/RNCUIWebViewManager.m Voir le fichier

@@ -1,154 +0,0 @@
1
-#import "RNCUIWebViewManager.h"
2
-
3
-#import <React/RCTBridge.h>
4
-#import <React/RCTUIManager.h>
5
-#import <React/UIView+React.h>
6
-#import "RNCUIWebView.h"
7
-
8
-@interface RNCUIWebViewManager () <RNCUIWebViewDelegate>
9
-
10
-@end
11
-
12
-@implementation RNCUIWebViewManager
13
-{
14
-  NSConditionLock *_shouldStartLoadLock;
15
-  BOOL _shouldStartLoad;
16
-}
17
-
18
-RCT_EXPORT_MODULE()
19
-
20
-- (UIView *)view
21
-{
22
-  RNCUIWebView *webView = [RNCUIWebView new];
23
-  webView.delegate = self;
24
-  return webView;
25
-}
26
-
27
-RCT_EXPORT_VIEW_PROPERTY(source, NSDictionary)
28
-RCT_REMAP_VIEW_PROPERTY(bounces, _webView.scrollView.bounces, BOOL)
29
-RCT_REMAP_VIEW_PROPERTY(scrollEnabled, _webView.scrollView.scrollEnabled, BOOL)
30
-RCT_REMAP_VIEW_PROPERTY(decelerationRate, _webView.scrollView.decelerationRate, CGFloat)
31
-RCT_EXPORT_VIEW_PROPERTY(scalesPageToFit, BOOL)
32
-RCT_EXPORT_VIEW_PROPERTY(messagingEnabled, BOOL)
33
-RCT_EXPORT_VIEW_PROPERTY(injectedJavaScript, NSString)
34
-RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
35
-RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
36
-RCT_EXPORT_VIEW_PROPERTY(onLoadingStart, RCTDirectEventBlock)
37
-RCT_EXPORT_VIEW_PROPERTY(onLoadingFinish, RCTDirectEventBlock)
38
-RCT_EXPORT_VIEW_PROPERTY(onLoadingError, RCTDirectEventBlock)
39
-RCT_EXPORT_VIEW_PROPERTY(onMessage, RCTDirectEventBlock)
40
-RCT_EXPORT_VIEW_PROPERTY(onShouldStartLoadWithRequest, RCTDirectEventBlock)
41
-RCT_REMAP_VIEW_PROPERTY(allowsInlineMediaPlayback, _webView.allowsInlineMediaPlayback, BOOL)
42
-RCT_REMAP_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, _webView.mediaPlaybackRequiresUserAction, BOOL)
43
-RCT_REMAP_VIEW_PROPERTY(dataDetectorTypes, _webView.dataDetectorTypes, UIDataDetectorTypes)
44
-RCT_REMAP_VIEW_PROPERTY(showsHorizontalScrollIndicator, _webView.scrollView.showsHorizontalScrollIndicator, BOOL)
45
-RCT_REMAP_VIEW_PROPERTY(showsVerticalScrollIndicator, _webView.scrollView.showsVerticalScrollIndicator, BOOL)
46
-RCT_REMAP_VIEW_PROPERTY(directionalLockEnabled, _webView.scrollView.directionalLockEnabled, BOOL)
47
-
48
-RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag)
49
-{
50
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCUIWebView *> *viewRegistry) {
51
-    RNCUIWebView *view = viewRegistry[reactTag];
52
-    if (![view isKindOfClass:[RNCUIWebView class]]) {
53
-      RCTLogError(@"Invalid view returned from registry, expecting RNCUIWebView, got: %@", view);
54
-    } else {
55
-      [view goBack];
56
-    }
57
-  }];
58
-}
59
-
60
-RCT_EXPORT_METHOD(goForward:(nonnull NSNumber *)reactTag)
61
-{
62
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
63
-    RNCUIWebView *view = viewRegistry[reactTag];
64
-    if (![view isKindOfClass:[RNCUIWebView class]]) {
65
-      RCTLogError(@"Invalid view returned from registry, expecting RNCUIWebView, got: %@", view);
66
-    } else {
67
-      [view goForward];
68
-    }
69
-  }];
70
-}
71
-
72
-RCT_EXPORT_METHOD(reload:(nonnull NSNumber *)reactTag)
73
-{
74
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCUIWebView *> *viewRegistry) {
75
-    RNCUIWebView *view = viewRegistry[reactTag];
76
-    if (![view isKindOfClass:[RNCUIWebView class]]) {
77
-      RCTLogError(@"Invalid view returned from registry, expecting RNCUIWebView, got: %@", view);
78
-    } else {
79
-      [view reload];
80
-    }
81
-  }];
82
-}
83
-
84
-RCT_EXPORT_METHOD(stopLoading:(nonnull NSNumber *)reactTag)
85
-{
86
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCUIWebView *> *viewRegistry) {
87
-    RNCUIWebView *view = viewRegistry[reactTag];
88
-    if (![view isKindOfClass:[RNCUIWebView class]]) {
89
-      RCTLogError(@"Invalid view returned from registry, expecting RNCUIWebView, got: %@", view);
90
-    } else {
91
-      [view stopLoading];
92
-    }
93
-  }];
94
-}
95
-
96
-RCT_EXPORT_METHOD(postMessage:(nonnull NSNumber *)reactTag message:(NSString *)message)
97
-{
98
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCUIWebView *> *viewRegistry) {
99
-    RNCUIWebView *view = viewRegistry[reactTag];
100
-    if (![view isKindOfClass:[RNCUIWebView class]]) {
101
-      RCTLogError(@"Invalid view returned from registry, expecting RNCUIWebView, got: %@", view);
102
-    } else {
103
-      [view postMessage:message];
104
-    }
105
-  }];
106
-}
107
-
108
-RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString *)script)
109
-{
110
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCUIWebView *> *viewRegistry) {
111
-    RNCUIWebView *view = viewRegistry[reactTag];
112
-    if (![view isKindOfClass:[RNCUIWebView class]]) {
113
-      RCTLogError(@"Invalid view returned from registry, expecting RNCUIWebView, got: %@", view);
114
-    } else {
115
-      [view injectJavaScript:script];
116
-    }
117
-  }];
118
-}
119
-
120
-#pragma mark - Exported synchronous methods
121
-
122
-- (BOOL)webView:(__unused RNCUIWebView *)webView
123
-shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
124
-   withCallback:(RCTDirectEventBlock)callback
125
-{
126
-  _shouldStartLoadLock = [[NSConditionLock alloc] initWithCondition:arc4random()];
127
-  _shouldStartLoad = YES;
128
-  request[@"lockIdentifier"] = @(_shouldStartLoadLock.condition);
129
-  callback(request);
130
-
131
-  // Block the main thread for a maximum of 250ms until the JS thread returns
132
-  if ([_shouldStartLoadLock lockWhenCondition:0 beforeDate:[NSDate dateWithTimeIntervalSinceNow:.25]]) {
133
-    BOOL returnValue = _shouldStartLoad;
134
-    [_shouldStartLoadLock unlock];
135
-    _shouldStartLoadLock = nil;
136
-    return returnValue;
137
-  } else {
138
-    RCTLogWarn(@"Did not receive response to shouldStartLoad in time, defaulting to YES");
139
-    return YES;
140
-  }
141
-}
142
-
143
-RCT_EXPORT_METHOD(startLoadWithResult:(BOOL)result lockIdentifier:(NSInteger)lockIdentifier)
144
-{
145
-  if ([_shouldStartLoadLock tryLockWhenCondition:lockIdentifier]) {
146
-    _shouldStartLoad = result;
147
-    [_shouldStartLoadLock unlockWithCondition:0];
148
-  } else {
149
-    RCTLogWarn(@"startLoadWithResult invoked with invalid lockIdentifier: "
150
-               "got %lld, expected %lld", (long long)lockIdentifier, (long long)_shouldStartLoadLock.condition);
151
-  }
152
-}
153
-
154
-@end

ios/RNCWKWebView.h → ios/RNCWebView.h Voir le fichier

@@ -9,19 +9,19 @@
9 9
 #import <React/RCTDefines.h>
10 10
 #import <WebKit/WebKit.h>
11 11
 
12
-@class RNCWKWebView;
12
+@class RNCWebView;
13 13
 
14
-@protocol RNCWKWebViewDelegate <NSObject>
14
+@protocol RNCWebViewDelegate <NSObject>
15 15
 
16
-- (BOOL)webView:(RNCWKWebView *)webView
16
+- (BOOL)webView:(RNCWebView *)webView
17 17
    shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
18 18
    withCallback:(RCTDirectEventBlock)callback;
19 19
 
20 20
 @end
21 21
 
22
-@interface RNCWKWebView : RCTView
22
+@interface RNCWebView : RCTView
23 23
 
24
-@property (nonatomic, weak) id<RNCWKWebViewDelegate> delegate;
24
+@property (nonatomic, weak) id<RNCWebViewDelegate> delegate;
25 25
 @property (nonatomic, copy) NSDictionary *source;
26 26
 @property (nonatomic, assign) BOOL messagingEnabled;
27 27
 @property (nonatomic, copy) NSString *injectedJavaScript;

ios/RNCWKWebView.m → ios/RNCWebView.m Voir le fichier

@@ -5,7 +5,7 @@
5 5
  * LICENSE file in the root directory of this source tree.
6 6
  */
7 7
 
8
-#import "RNCWKWebView.h"
8
+#import "RNCWebView.h"
9 9
 #import <React/RCTConvert.h>
10 10
 #import <React/RCTAutoInsetsProtocol.h>
11 11
 #import "RNCWKProcessPoolManager.h"
@@ -27,7 +27,7 @@ static NSURLCredential* clientAuthenticationCredential;
27 27
 }
28 28
 @end
29 29
 
30
-@interface RNCWKWebView () <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler, UIScrollViewDelegate, RCTAutoInsetsProtocol>
30
+@interface RNCWebView () <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler, UIScrollViewDelegate, RCTAutoInsetsProtocol>
31 31
 @property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
32 32
 @property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish;
33 33
 @property (nonatomic, copy) RCTDirectEventBlock onLoadingError;
@@ -38,12 +38,12 @@ static NSURLCredential* clientAuthenticationCredential;
38 38
 @property (nonatomic, copy) WKWebView *webView;
39 39
 @end
40 40
 
41
-@implementation RNCWKWebView
41
+@implementation RNCWebView
42 42
 {
43 43
   UIColor * _savedBackgroundColor;
44 44
   BOOL _savedHideKeyboardAccessoryView;
45 45
   BOOL _savedKeyboardDisplayRequiresUserAction;
46
-  
46
+
47 47
   // Workaround for StatusBar appearance bug for iOS 12
48 48
   // https://github.com/react-native-community/react-native-webview/issues/62
49 49
   BOOL _isFullScreenVideoOpen;
@@ -86,12 +86,12 @@ static NSURLCredential* clientAuthenticationCredential;
86 86
       addObserver:self
87 87
       selector:@selector(keyboardWillShow)
88 88
       name:UIKeyboardWillShowNotification object:nil];
89
-    
89
+
90 90
     // Workaround for StatusBar appearance bug for iOS 12
91 91
     // https://github.com/react-native-community/react-native-webview/issues/62
92 92
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toggleFullScreenVideoStatusBars) name:@"_MRMediaRemotePlayerSupportedCommandsDidChangeNotification" object:nil];
93 93
   }
94
-  
94
+
95 95
   return self;
96 96
 }
97 97
 
@@ -449,22 +449,22 @@ static NSURLCredential* clientAuthenticationCredential;
449 449
         _savedKeyboardDisplayRequiresUserAction = keyboardDisplayRequiresUserAction;
450 450
         return;
451 451
     }
452
-  
452
+
453 453
     if (_savedKeyboardDisplayRequiresUserAction == true) {
454 454
         return;
455 455
     }
456
-  
456
+
457 457
     UIView* subview;
458
-  
458
+
459 459
     for (UIView* view in _webView.scrollView.subviews) {
460 460
         if([[view.class description] hasPrefix:@"WK"])
461 461
             subview = view;
462 462
     }
463
-  
463
+
464 464
     if(subview == nil) return;
465
-  
465
+
466 466
     Class class = subview.class;
467
-  
467
+
468 468
     NSOperatingSystemVersion iOS_11_3_0 = (NSOperatingSystemVersion){11, 3, 0};
469 469
     NSOperatingSystemVersion iOS_12_2_0 = (NSOperatingSystemVersion){12, 2, 0};
470 470
     NSOperatingSystemVersion iOS_13_0_0 = (NSOperatingSystemVersion){13, 0, 0};
@@ -507,7 +507,7 @@ static NSURLCredential* clientAuthenticationCredential;
507 507
             ((void (*)(id, SEL, void*, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3);
508 508
         });
509 509
     }
510
-  
510
+
511 511
     method_setImplementation(method, override);
512 512
 }
513 513
 
@@ -623,7 +623,7 @@ static NSURLCredential* clientAuthenticationCredential;
623 623
 {
624 624
   [super layoutSubviews];
625 625
 
626
-  // Ensure webview takes the position and dimensions of RNCWKWebView
626
+  // Ensure webview takes the position and dimensions of RNCWebView
627 627
   _webView.frame = self.bounds;
628 628
   _webView.scrollView.contentInset = _contentInset;
629 629
 }

+ 17
- 29
ios/RNCWebView.xcodeproj/project.pbxproj Voir le fichier

@@ -8,10 +8,8 @@
8 8
 
9 9
 /* Begin PBXBuildFile section */
10 10
 		3515965E21A3C86000623BFA /* RNCWKProcessPoolManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 3515965D21A3C86000623BFA /* RNCWKProcessPoolManager.m */; };
11
-		E914DBF6214474710071092B /* RNCUIWebViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = E914DBF3214474710071092B /* RNCUIWebViewManager.m */; };
12
-		E914DBF7214474710071092B /* RNCUIWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = E914DBF4214474710071092B /* RNCUIWebView.m */; };
13
-		E91B351D21446E6C00F9801F /* RNCWKWebViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = E91B351B21446E6C00F9801F /* RNCWKWebViewManager.m */; };
14
-		E91B351E21446E6C00F9801F /* RNCWKWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = E91B351C21446E6C00F9801F /* RNCWKWebView.m */; };
11
+		E91B351D21446E6C00F9801F /* RNCWebViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = E91B351B21446E6C00F9801F /* RNCWebViewManager.m */; };
12
+		E91B351E21446E6C00F9801F /* RNCWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = E91B351C21446E6C00F9801F /* RNCWebView.m */; };
15 13
 /* End PBXBuildFile section */
16 14
 
17 15
 /* Begin PBXCopyFilesBuildPhase section */
@@ -30,14 +28,10 @@
30 28
 		134814201AA4EA6300B7C361 /* libRNCWebView.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNCWebView.a; sourceTree = BUILT_PRODUCTS_DIR; };
31 29
 		3515965D21A3C86000623BFA /* RNCWKProcessPoolManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNCWKProcessPoolManager.m; sourceTree = "<group>"; };
32 30
 		3515965F21A3C87E00623BFA /* RNCWKProcessPoolManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNCWKProcessPoolManager.h; sourceTree = "<group>"; };
33
-		E914DBF2214474710071092B /* RNCUIWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNCUIWebView.h; sourceTree = "<group>"; };
34
-		E914DBF3214474710071092B /* RNCUIWebViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNCUIWebViewManager.m; sourceTree = "<group>"; };
35
-		E914DBF4214474710071092B /* RNCUIWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNCUIWebView.m; sourceTree = "<group>"; };
36
-		E914DBF5214474710071092B /* RNCUIWebViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNCUIWebViewManager.h; sourceTree = "<group>"; };
37
-		E91B351921446E6C00F9801F /* RNCWKWebViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNCWKWebViewManager.h; sourceTree = "<group>"; };
38
-		E91B351A21446E6C00F9801F /* RNCWKWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNCWKWebView.h; sourceTree = "<group>"; };
39
-		E91B351B21446E6C00F9801F /* RNCWKWebViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNCWKWebViewManager.m; sourceTree = "<group>"; };
40
-		E91B351C21446E6C00F9801F /* RNCWKWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNCWKWebView.m; sourceTree = "<group>"; };
31
+		E91B351921446E6C00F9801F /* RNCWebViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNCWebViewManager.h; sourceTree = "<group>"; };
32
+		E91B351A21446E6C00F9801F /* RNCWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNCWebView.h; sourceTree = "<group>"; };
33
+		E91B351B21446E6C00F9801F /* RNCWebViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNCWebViewManager.m; sourceTree = "<group>"; };
34
+		E91B351C21446E6C00F9801F /* RNCWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNCWebView.m; sourceTree = "<group>"; };
41 35
 /* End PBXFileReference section */
42 36
 
43 37
 /* Begin PBXFrameworksBuildPhase section */
@@ -62,14 +56,10 @@
62 56
 		58B511D21A9E6C8500147676 = {
63 57
 			isa = PBXGroup;
64 58
 			children = (
65
-				E914DBF2214474710071092B /* RNCUIWebView.h */,
66
-				E914DBF4214474710071092B /* RNCUIWebView.m */,
67
-				E914DBF5214474710071092B /* RNCUIWebViewManager.h */,
68
-				E914DBF3214474710071092B /* RNCUIWebViewManager.m */,
69
-				E91B351A21446E6C00F9801F /* RNCWKWebView.h */,
70
-				E91B351C21446E6C00F9801F /* RNCWKWebView.m */,
71
-				E91B351921446E6C00F9801F /* RNCWKWebViewManager.h */,
72
-				E91B351B21446E6C00F9801F /* RNCWKWebViewManager.m */,
59
+				E91B351A21446E6C00F9801F /* RNCWebView.h */,
60
+				E91B351C21446E6C00F9801F /* RNCWebView.m */,
61
+				E91B351921446E6C00F9801F /* RNCWebViewManager.h */,
62
+				E91B351B21446E6C00F9801F /* RNCWebViewManager.m */,
73 63
 				3515965D21A3C86000623BFA /* RNCWKProcessPoolManager.m */,
74 64
 				3515965F21A3C87E00623BFA /* RNCWKProcessPoolManager.h */,
75 65
 				134814211AA4EA7D00B7C361 /* Products */,
@@ -112,7 +102,7 @@
112 102
 			};
113 103
 			buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNCWebView" */;
114 104
 			compatibilityVersion = "Xcode 3.2";
115
-			developmentRegion = English;
105
+			developmentRegion = en;
116 106
 			hasScannedForEncodings = 0;
117 107
 			knownRegions = (
118 108
 				en,
@@ -132,10 +122,8 @@
132 122
 			isa = PBXSourcesBuildPhase;
133 123
 			buildActionMask = 2147483647;
134 124
 			files = (
135
-				E91B351D21446E6C00F9801F /* RNCWKWebViewManager.m in Sources */,
136
-				E914DBF7214474710071092B /* RNCUIWebView.m in Sources */,
137
-				E914DBF6214474710071092B /* RNCUIWebViewManager.m in Sources */,
138
-				E91B351E21446E6C00F9801F /* RNCWKWebView.m in Sources */,
125
+				E91B351D21446E6C00F9801F /* RNCWebViewManager.m in Sources */,
126
+				E91B351E21446E6C00F9801F /* RNCWebView.m in Sources */,
139 127
 				3515965E21A3C86000623BFA /* RNCWKProcessPoolManager.m in Sources */,
140 128
 			);
141 129
 			runOnlyForDeploymentPostprocessing = 0;
@@ -227,10 +215,10 @@
227 215
 		58B511F01A9E6C8500147676 /* Debug */ = {
228 216
 			isa = XCBuildConfiguration;
229 217
 			buildSettings = {
218
+				FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../node_modules/react-native/**";
230 219
 				HEADER_SEARCH_PATHS = (
231 220
 					"$(inherited)",
232
-					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
233
-					"$(SRCROOT)/../../../React/**",
221
+					"$(SRCROOT)/../node_modules/react-native/React/**",
234 222
 					"$(SRCROOT)/../../react-native/React/**",
235 223
 				);
236 224
 				LIBRARY_SEARCH_PATHS = "$(inherited)";
@@ -243,10 +231,10 @@
243 231
 		58B511F11A9E6C8500147676 /* Release */ = {
244 232
 			isa = XCBuildConfiguration;
245 233
 			buildSettings = {
234
+				FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../node_modules/react-native/**";
246 235
 				HEADER_SEARCH_PATHS = (
247 236
 					"$(inherited)",
248
-					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
249
-					"$(SRCROOT)/../../../React/**",
237
+					"$(SRCROOT)/../node_modules/react-native/React/**",
250 238
 					"$(SRCROOT)/../../react-native/React/**",
251 239
 				);
252 240
 				LIBRARY_SEARCH_PATHS = "$(inherited)";

ios/RNCWKWebViewManager.h → ios/RNCWebViewManager.h Voir le fichier

@@ -7,5 +7,5 @@
7 7
 
8 8
 #import <React/RCTViewManager.h>
9 9
 
10
-@interface RNCWKWebViewManager : RCTViewManager
10
+@interface RNCWebViewManager : RCTViewManager
11 11
 @end

ios/RNCWKWebViewManager.m → ios/RNCWebViewManager.m Voir le fichier

@@ -5,13 +5,13 @@
5 5
  * LICENSE file in the root directory of this source tree.
6 6
  */
7 7
 
8
-#import "RNCWKWebViewManager.h"
8
+#import "RNCWebViewManager.h"
9 9
 
10 10
 #import <React/RCTUIManager.h>
11 11
 #import <React/RCTDefines.h>
12
-#import "RNCWKWebView.h"
12
+#import "RNCWebView.h"
13 13
 
14
-@interface RNCWKWebViewManager () <RNCWKWebViewDelegate>
14
+@interface RNCWebViewManager () <RNCWebViewDelegate>
15 15
 @end
16 16
 
17 17
 @implementation RCTConvert (UIScrollView)
@@ -27,7 +27,7 @@ RCT_ENUM_CONVERTER(UIScrollViewContentInsetAdjustmentBehavior, (@{
27 27
 
28 28
 @end
29 29
 
30
-@implementation RNCWKWebViewManager
30
+@implementation RNCWebViewManager
31 31
 {
32 32
   NSConditionLock *_shouldStartLoadLock;
33 33
   BOOL _shouldStartLoad;
@@ -37,7 +37,7 @@ RCT_EXPORT_MODULE()
37 37
 
38 38
 - (UIView *)view
39 39
 {
40
-  RNCWKWebView *webView = [RNCWKWebView new];
40
+  RNCWebView *webView = [RNCWebView new];
41 41
   webView.delegate = self;
42 42
   return webView;
43 43
 }
@@ -80,58 +80,58 @@ RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
80 80
 
81 81
 RCT_EXPORT_METHOD(postMessage:(nonnull NSNumber *)reactTag message:(NSString *)message)
82 82
 {
83
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWKWebView *> *viewRegistry) {
84
-    RNCWKWebView *view = viewRegistry[reactTag];
85
-    if (![view isKindOfClass:[RNCWKWebView class]]) {
86
-      RCTLogError(@"Invalid view returned from registry, expecting RNCWKWebView, got: %@", view);
83
+  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWebView *> *viewRegistry) {
84
+    RNCWebView *view = viewRegistry[reactTag];
85
+    if (![view isKindOfClass:[RNCWebView class]]) {
86
+      RCTLogError(@"Invalid view returned from registry, expecting RNCWebView, got: %@", view);
87 87
     } else {
88 88
       [view postMessage:message];
89 89
     }
90 90
   }];
91 91
 }
92 92
 
93
-RCT_CUSTOM_VIEW_PROPERTY(bounces, BOOL, RNCWKWebView) {
93
+RCT_CUSTOM_VIEW_PROPERTY(bounces, BOOL, RNCWebView) {
94 94
   view.bounces = json == nil ? true : [RCTConvert BOOL: json];
95 95
 }
96 96
 
97
-RCT_CUSTOM_VIEW_PROPERTY(useSharedProcessPool, BOOL, RNCWKWebView) {
97
+RCT_CUSTOM_VIEW_PROPERTY(useSharedProcessPool, BOOL, RNCWebView) {
98 98
   view.useSharedProcessPool = json == nil ? true : [RCTConvert BOOL: json];
99 99
 }
100 100
 
101
-RCT_CUSTOM_VIEW_PROPERTY(scrollEnabled, BOOL, RNCWKWebView) {
101
+RCT_CUSTOM_VIEW_PROPERTY(scrollEnabled, BOOL, RNCWebView) {
102 102
   view.scrollEnabled = json == nil ? true : [RCTConvert BOOL: json];
103 103
 }
104 104
 
105
-RCT_CUSTOM_VIEW_PROPERTY(sharedCookiesEnabled, BOOL, RNCWKWebView) {
105
+RCT_CUSTOM_VIEW_PROPERTY(sharedCookiesEnabled, BOOL, RNCWebView) {
106 106
     view.sharedCookiesEnabled = json == nil ? false : [RCTConvert BOOL: json];
107 107
 }
108 108
 
109
-RCT_CUSTOM_VIEW_PROPERTY(decelerationRate, CGFloat, RNCWKWebView) {
109
+RCT_CUSTOM_VIEW_PROPERTY(decelerationRate, CGFloat, RNCWebView) {
110 110
   view.decelerationRate = json == nil ? UIScrollViewDecelerationRateNormal : [RCTConvert CGFloat: json];
111 111
 }
112 112
 
113
-RCT_CUSTOM_VIEW_PROPERTY(directionalLockEnabled, BOOL, RNCWKWebView) {
113
+RCT_CUSTOM_VIEW_PROPERTY(directionalLockEnabled, BOOL, RNCWebView) {
114 114
     view.directionalLockEnabled = json == nil ? true : [RCTConvert BOOL: json];
115 115
 }
116 116
 
117
-RCT_CUSTOM_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL, RNCWKWebView) {
117
+RCT_CUSTOM_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL, RNCWebView) {
118 118
   view.showsHorizontalScrollIndicator = json == nil ? true : [RCTConvert BOOL: json];
119 119
 }
120 120
 
121
-RCT_CUSTOM_VIEW_PROPERTY(showsVerticalScrollIndicator, BOOL, RNCWKWebView) {
121
+RCT_CUSTOM_VIEW_PROPERTY(showsVerticalScrollIndicator, BOOL, RNCWebView) {
122 122
   view.showsVerticalScrollIndicator = json == nil ? true : [RCTConvert BOOL: json];
123 123
 }
124 124
 
125
-RCT_CUSTOM_VIEW_PROPERTY(keyboardDisplayRequiresUserAction, BOOL, RNCWKWebView) {
125
+RCT_CUSTOM_VIEW_PROPERTY(keyboardDisplayRequiresUserAction, BOOL, RNCWebView) {
126 126
   view.keyboardDisplayRequiresUserAction = json == nil ? true : [RCTConvert BOOL: json];
127 127
 }
128 128
 
129 129
 RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString *)script)
130 130
 {
131
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWKWebView *> *viewRegistry) {
132
-    RNCWKWebView *view = viewRegistry[reactTag];
133
-    if (![view isKindOfClass:[RNCWKWebView class]]) {
134
-      RCTLogError(@"Invalid view returned from registry, expecting RNCWKWebView, got: %@", view);
131
+  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWebView *> *viewRegistry) {
132
+    RNCWebView *view = viewRegistry[reactTag];
133
+    if (![view isKindOfClass:[RNCWebView class]]) {
134
+      RCTLogError(@"Invalid view returned from registry, expecting RNCWebView, got: %@", view);
135 135
     } else {
136 136
       [view injectJavaScript:script];
137 137
     }
@@ -140,10 +140,10 @@ RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString
140 140
 
141 141
 RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag)
142 142
 {
143
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWKWebView *> *viewRegistry) {
144
-    RNCWKWebView *view = viewRegistry[reactTag];
145
-    if (![view isKindOfClass:[RNCWKWebView class]]) {
146
-      RCTLogError(@"Invalid view returned from registry, expecting RNCWKWebView, got: %@", view);
143
+  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWebView *> *viewRegistry) {
144
+    RNCWebView *view = viewRegistry[reactTag];
145
+    if (![view isKindOfClass:[RNCWebView class]]) {
146
+      RCTLogError(@"Invalid view returned from registry, expecting RNCWebView, got: %@", view);
147 147
     } else {
148 148
       [view goBack];
149 149
     }
@@ -152,10 +152,10 @@ RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag)
152 152
 
153 153
 RCT_EXPORT_METHOD(goForward:(nonnull NSNumber *)reactTag)
154 154
 {
155
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWKWebView *> *viewRegistry) {
156
-    RNCWKWebView *view = viewRegistry[reactTag];
157
-    if (![view isKindOfClass:[RNCWKWebView class]]) {
158
-      RCTLogError(@"Invalid view returned from registry, expecting RNCWKWebView, got: %@", view);
155
+  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWebView *> *viewRegistry) {
156
+    RNCWebView *view = viewRegistry[reactTag];
157
+    if (![view isKindOfClass:[RNCWebView class]]) {
158
+      RCTLogError(@"Invalid view returned from registry, expecting RNCWebView, got: %@", view);
159 159
     } else {
160 160
       [view goForward];
161 161
     }
@@ -164,10 +164,10 @@ RCT_EXPORT_METHOD(goForward:(nonnull NSNumber *)reactTag)
164 164
 
165 165
 RCT_EXPORT_METHOD(reload:(nonnull NSNumber *)reactTag)
166 166
 {
167
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWKWebView *> *viewRegistry) {
168
-    RNCWKWebView *view = viewRegistry[reactTag];
169
-    if (![view isKindOfClass:[RNCWKWebView class]]) {
170
-      RCTLogError(@"Invalid view returned from registry, expecting RNCWKWebView, got: %@", view);
167
+  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWebView *> *viewRegistry) {
168
+    RNCWebView *view = viewRegistry[reactTag];
169
+    if (![view isKindOfClass:[RNCWebView class]]) {
170
+      RCTLogError(@"Invalid view returned from registry, expecting RNCWebView, got: %@", view);
171 171
     } else {
172 172
       [view reload];
173 173
     }
@@ -176,10 +176,10 @@ RCT_EXPORT_METHOD(reload:(nonnull NSNumber *)reactTag)
176 176
 
177 177
 RCT_EXPORT_METHOD(stopLoading:(nonnull NSNumber *)reactTag)
178 178
 {
179
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWKWebView *> *viewRegistry) {
180
-    RNCWKWebView *view = viewRegistry[reactTag];
181
-    if (![view isKindOfClass:[RNCWKWebView class]]) {
182
-      RCTLogError(@"Invalid view returned from registry, expecting RNCWKWebView, got: %@", view);
179
+  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RNCWebView *> *viewRegistry) {
180
+    RNCWebView *view = viewRegistry[reactTag];
181
+    if (![view isKindOfClass:[RNCWebView class]]) {
182
+      RCTLogError(@"Invalid view returned from registry, expecting RNCWebView, got: %@", view);
183 183
     } else {
184 184
       [view stopLoading];
185 185
     }
@@ -188,7 +188,7 @@ RCT_EXPORT_METHOD(stopLoading:(nonnull NSNumber *)reactTag)
188 188
 
189 189
 #pragma mark - Exported synchronous methods
190 190
 
191
-- (BOOL)          webView:(RNCWKWebView *)webView
191
+- (BOOL)          webView:(RNCWebView *)webView
192 192
 shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
193 193
              withCallback:(RCTDirectEventBlock)callback
194 194
 {

+ 3
- 3
package.json Voir le fichier

@@ -8,7 +8,7 @@
8 8
     "Thibault Malbranche <malbranche.thibault@gmail.com>"
9 9
   ],
10 10
   "license": "MIT",
11
-  "version": "6.11.1",
11
+  "version": "7.0.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",
@@ -20,7 +20,7 @@
20 20
   },
21 21
   "peerDependencies": {
22 22
     "react": "^16.0",
23
-    "react-native": ">=0.57 <0.60"
23
+    "react-native": ">=0.60 <0.62"
24 24
   },
25 25
   "dependencies": {
26 26
     "escape-string-regexp": "1.0.5",
@@ -48,7 +48,7 @@
48 48
     "jest": "24.5.0",
49 49
     "metro-react-native-babel-preset": "0.53.1",
50 50
     "react": "16.8.3",
51
-    "react-native": "0.59.1",
51
+    "react-native": "0.60.5",
52 52
     "semantic-release": "15.10.3",
53 53
     "typescript": "3.3.3333"
54 54
   },

+ 4
- 5
src/WebView.android.tsx Voir le fichier

@@ -15,7 +15,6 @@ import invariant from 'invariant';
15 15
 import {
16 16
   defaultOriginWhitelist,
17 17
   createOnShouldStartLoadWithRequest,
18
-  getViewManagerConfig,
19 18
   defaultRenderError,
20 19
   defaultRenderLoading,
21 20
 } from './WebViewShared';
@@ -68,7 +67,7 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
68 67
 
69 68
   webViewRef = React.createRef<NativeWebViewAndroid>();
70 69
 
71
-  getCommands = () => getViewManagerConfig('RNCWebView').Commands;
70
+  getCommands = () => UIManager.getViewManagerConfig('RNCWebView').Commands;
72 71
 
73 72
   goForward = () => {
74 73
     UIManager.dispatchViewManagerCommand(
@@ -107,9 +106,9 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
107 106
 
108 107
   requestFocus = () => {
109 108
     UIManager.dispatchViewManagerCommand(
110
-        this.getWebViewHandle(),
111
-        this.getCommands().requestFocus,
112
-        null,
109
+      this.getWebViewHandle(),
110
+      this.getCommands().requestFocus,
111
+      null,
113 112
     );
114 113
   };
115 114
 

+ 13
- 79
src/WebView.ios.tsx Voir le fichier

@@ -13,7 +13,6 @@ import invariant from 'invariant';
13 13
 import {
14 14
   defaultOriginWhitelist,
15 15
   createOnShouldStartLoadWithRequest,
16
-  getViewManagerConfig,
17 16
   defaultRenderError,
18 17
   defaultRenderLoading,
19 18
 } from './WebViewShared';
@@ -28,7 +27,6 @@ import {
28 27
   ViewManager,
29 28
   State,
30 29
   CustomUIManager,
31
-  WebViewNativeConfig,
32 30
 } from './WebViewTypes';
33 31
 
34 32
 import styles from './WebView.styles';
@@ -36,8 +34,6 @@ import styles from './WebView.styles';
36 34
 const UIManager = NotTypedUIManager as CustomUIManager;
37 35
 
38 36
 const { resolveAssetSource } = Image;
39
-let didWarnAboutUIWebViewUsage = false;
40
-// Imported from https://github.com/facebook/react-native/blob/master/Libraries/Components/ScrollView/processDecelerationRate.js
41 37
 const processDecelerationRate = (
42 38
   decelerationRate: DecelerationRateConstant | number | undefined,
43 39
 ) => {
@@ -50,19 +46,14 @@ const processDecelerationRate = (
50 46
   return newDecelerationRate;
51 47
 };
52 48
 
53
-const RNCUIWebViewManager = NativeModules.RNCUIWebViewManager as ViewManager;
54
-const RNCWKWebViewManager = NativeModules.RNCWKWebViewManager as ViewManager;
49
+const RNCWebViewManager = NativeModules.RNCWebViewManager as ViewManager;
55 50
 
56
-const RNCUIWebView: typeof NativeWebViewIOS = requireNativeComponent(
57
-  'RNCUIWebView',
58
-);
59
-const RNCWKWebView: typeof NativeWebViewIOS = requireNativeComponent(
60
-  'RNCWKWebView',
51
+const RNCWebView: typeof NativeWebViewIOS = requireNativeComponent(
52
+  'RNCWebView',
61 53
 );
62 54
 
63 55
 class WebView extends React.Component<IOSWebViewProps, State> {
64 56
   static defaultProps = {
65
-    useWebKit: true,
66 57
     javaScriptEnabled: true,
67 58
     cacheEnabled: true,
68 59
     originWhitelist: defaultOriginWhitelist,
@@ -81,44 +72,8 @@ class WebView extends React.Component<IOSWebViewProps, State> {
81 72
 
82 73
   webViewRef = React.createRef<NativeWebViewIOS>();
83 74
 
84
-  // eslint-disable-next-line camelcase
85
-  UNSAFE_componentWillMount() {
86
-    if (!this.props.useWebKit && !didWarnAboutUIWebViewUsage) {
87
-      didWarnAboutUIWebViewUsage = true;
88
-      console.warn(
89
-        'UIWebView is deprecated and will be removed soon, please use WKWebView (do not override useWebkit={true} prop),'
90
-          + ' more infos here: https://github.com/react-native-community/react-native-webview/issues/312',
91
-      );
92
-    }
93
-    if (
94
-      this.props.useWebKit === true
95
-      && this.props.scalesPageToFit !== undefined
96
-    ) {
97
-      console.warn(
98
-        'The scalesPageToFit property is not supported when useWebKit = true',
99
-      );
100
-    }
101
-    if (
102
-      !this.props.useWebKit
103
-      && this.props.allowsBackForwardNavigationGestures
104
-    ) {
105
-      console.warn(
106
-        'The allowsBackForwardNavigationGestures property is not supported when useWebKit = false',
107
-      );
108
-    }
109
-
110
-    if (!this.props.useWebKit && this.props.incognito) {
111
-      console.warn(
112
-        'The incognito property is not supported when useWebKit = false',
113
-      );
114
-    }
115
-  }
116
-
117 75
   // eslint-disable-next-line react/sort-comp
118
-  getCommands = () =>
119
-    !this.props.useWebKit
120
-      ? getViewManagerConfig('RNCUIWebView').Commands
121
-      : getViewManagerConfig('RNCWKWebView').Commands;
76
+  getCommands = () => UIManager.getViewManagerConfig('RNCWebView').Commands;
122 77
 
123 78
   /**
124 79
    * Go forward one page in the web view's history.
@@ -170,9 +125,9 @@ class WebView extends React.Component<IOSWebViewProps, State> {
170 125
    */
171 126
   requestFocus = () => {
172 127
     UIManager.dispatchViewManagerCommand(
173
-        this.getWebViewHandle(),
174
-        this.getCommands().requestFocus,
175
-        null,
128
+      this.getWebViewHandle(),
129
+      this.getCommands().requestFocus,
130
+      null,
176 131
     );
177 132
   };
178 133
 
@@ -285,32 +240,18 @@ class WebView extends React.Component<IOSWebViewProps, State> {
285 240
     _url: string,
286 241
     lockIdentifier: number,
287 242
   ) => {
288
-    let { viewManager }: WebViewNativeConfig = this.props.nativeConfig || {};
243
+    const viewManager
244
+      = (this.props.nativeConfig && this.props.nativeConfig.viewManager)
245
+      || RNCWebViewManager;
289 246
 
290
-    if (this.props.useWebKit) {
291
-      viewManager = viewManager || RNCWKWebViewManager;
292
-    } else {
293
-      viewManager = viewManager || RNCUIWebViewManager;
294
-    }
295
-    invariant(viewManager != null, 'viewManager expected to be non-null');
296 247
     viewManager.startLoadWithResult(!!shouldStart, lockIdentifier);
297 248
   };
298 249
 
299 250
   componentDidUpdate(prevProps: IOSWebViewProps) {
300
-    if (!(prevProps.useWebKit && this.props.useWebKit)) {
301
-      return;
302
-    }
303
-
304 251
     this.showRedboxOnPropChanges(prevProps, 'allowsInlineMediaPlayback');
305 252
     this.showRedboxOnPropChanges(prevProps, 'incognito');
306 253
     this.showRedboxOnPropChanges(prevProps, 'mediaPlaybackRequiresUserAction');
307 254
     this.showRedboxOnPropChanges(prevProps, 'dataDetectorTypes');
308
-
309
-    if (this.props.scalesPageToFit !== undefined) {
310
-      console.warn(
311
-        'The scalesPageToFit property is not supported when useWebKit = true',
312
-      );
313
-    }
314 255
   }
315 256
 
316 257
   showRedboxOnPropChanges(
@@ -333,9 +274,7 @@ class WebView extends React.Component<IOSWebViewProps, State> {
333 274
       originWhitelist,
334 275
       renderError,
335 276
       renderLoading,
336
-      scalesPageToFit = this.props.useWebKit ? undefined : true,
337 277
       style,
338
-      useWebKit,
339 278
       ...otherProps
340 279
     } = this.props;
341 280
 
@@ -368,13 +307,9 @@ class WebView extends React.Component<IOSWebViewProps, State> {
368 307
 
369 308
     const decelerationRate = processDecelerationRate(decelerationRateProp);
370 309
 
371
-    let NativeWebView = nativeConfig.component as typeof NativeWebViewIOS;
372
-
373
-    if (useWebKit) {
374
-      NativeWebView = NativeWebView || RNCWKWebView;
375
-    } else {
376
-      NativeWebView = NativeWebView || RNCUIWebView;
377
-    }
310
+    const NativeWebView
311
+      = (nativeConfig.component as typeof NativeWebViewIOS | undefined)
312
+      || RNCWebView;
378 313
 
379 314
     const webView = (
380 315
       <NativeWebView
@@ -390,7 +325,6 @@ class WebView extends React.Component<IOSWebViewProps, State> {
390 325
         onScroll={this.props.onScroll}
391 326
         onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
392 327
         ref={this.webViewRef}
393
-        scalesPageToFit={scalesPageToFit}
394 328
         // TODO: find a better way to type this.
395 329
         source={resolveAssetSource(this.props.source as ImageSourcePropType)}
396 330
         style={webViewStyles}

+ 1
- 20
src/WebViewShared.tsx Voir le fichier

@@ -1,21 +1,12 @@
1 1
 import escapeStringRegexp from 'escape-string-regexp';
2 2
 import React from 'react';
3
-import {
4
-  Linking,
5
-  UIManager as NotTypedUIManager,
6
-  View,
7
-  ActivityIndicator,
8
-  Text,
9
-} from 'react-native';
3
+import { Linking, View, ActivityIndicator, Text } from 'react-native';
10 4
 import {
11 5
   WebViewNavigationEvent,
12 6
   OnShouldStartLoadWithRequest,
13
-  CustomUIManager,
14 7
 } from './WebViewTypes';
15 8
 import styles from './WebView.styles';
16 9
 
17
-const UIManager = NotTypedUIManager as CustomUIManager;
18
-
19 10
 const defaultOriginWhitelist = ['http://*', 'https://*'];
20 11
 
21 12
 const extractOrigin = (url: string): string => {
@@ -65,15 +56,6 @@ const createOnShouldStartLoadWithRequest = (
65 56
   };
66 57
 };
67 58
 
68
-const getViewManagerConfig = (
69
-  viewManagerName: 'RNCUIWebView' | 'RNCWKWebView' | 'RNCWebView',
70
-) => {
71
-  if (!UIManager.getViewManagerConfig) {
72
-    return UIManager[viewManagerName];
73
-  }
74
-  return UIManager.getViewManagerConfig(viewManagerName);
75
-};
76
-
77 59
 const defaultRenderLoading = () => (
78 60
   <View style={styles.loadingOrErrorView}>
79 61
     <ActivityIndicator />
@@ -95,7 +77,6 @@ const defaultRenderError = (
95 77
 export {
96 78
   defaultOriginWhitelist,
97 79
   createOnShouldStartLoadWithRequest,
98
-  getViewManagerConfig,
99 80
   defaultRenderLoading,
100 81
   defaultRenderError,
101 82
 };

+ 31
- 36
src/WebViewTypes.ts Voir le fichier

@@ -22,7 +22,7 @@ export interface WebViewCommands {
22 22
 }
23 23
 
24 24
 export interface CustomUIManager extends UIManagerStatic {
25
-  getViewManagerConfig?: (
25
+  getViewManagerConfig: (
26 26
     name: string,
27 27
   ) => {
28 28
     Commands: WebViewCommands;
@@ -32,12 +32,6 @@ export interface CustomUIManager extends UIManagerStatic {
32 32
     command: Function,
33 33
     params: object | null,
34 34
   ) => void;
35
-  RNCUIWebView: {
36
-    Commands: WebViewCommands;
37
-  };
38
-  RNCWKWebView: {
39
-    Commands: WebViewCommands;
40
-  };
41 35
   RNCWebView: {
42 36
     Commands: WebViewCommands;
43 37
   };
@@ -125,7 +119,9 @@ export interface WebViewError extends WebViewNativeEvent {
125 119
 
126 120
 export type WebViewEvent = NativeSyntheticEvent<WebViewNativeEvent>;
127 121
 
128
-export type WebViewProgressEvent = NativeSyntheticEvent<WebViewNativeProgressEvent>;
122
+export type WebViewProgressEvent = NativeSyntheticEvent<
123
+  WebViewNativeProgressEvent
124
+>;
129 125
 
130 126
 export type WebViewNavigationEvent = NativeSyntheticEvent<WebViewNavigation>;
131 127
 
@@ -133,8 +129,8 @@ export type WebViewMessageEvent = NativeSyntheticEvent<WebViewMessage>;
133 129
 
134 130
 export type WebViewErrorEvent = NativeSyntheticEvent<WebViewError>;
135 131
 
136
-export type DataDetectorTypes
137
-  = | 'phoneNumber'
132
+export type DataDetectorTypes =
133
+  | 'phoneNumber'
138 134
   | 'link'
139 135
   | 'address'
140 136
   | 'calendarEvent'
@@ -224,7 +220,6 @@ export interface CommonNativeWebViewProps extends ViewProps {
224 220
   onLoadingStart: (event: WebViewNavigationEvent) => void;
225 221
   onMessage: (event: WebViewMessageEvent) => void;
226 222
   onShouldStartLoadWithRequest: (event: WebViewNavigationEvent) => void;
227
-  scalesPageToFit?: boolean;
228 223
   showsHorizontalScrollIndicator?: boolean;
229 224
   showsVerticalScrollIndicator?: boolean;
230 225
   // TODO: find a better way to type this.
@@ -239,6 +234,7 @@ export interface CommonNativeWebViewProps extends ViewProps {
239 234
 
240 235
 export interface AndroidNativeWebViewProps extends CommonNativeWebViewProps {
241 236
   allowFileAccess?: boolean;
237
+  scalesPageToFit?: boolean;
242 238
   allowUniversalAccessFromFileURLs?: boolean;
243 239
   androidHardwareAccelerationDisabled?: boolean;
244 240
   domStorageEnabled?: boolean;
@@ -261,7 +257,11 @@ export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
261 257
   automaticallyAdjustContentInsets?: boolean;
262 258
   bounces?: boolean;
263 259
   contentInset?: ContentInsetProp;
264
-  contentInsetAdjustmentBehavior?: 'automatic'| 'scrollableAxes' | 'never' | 'always';
260
+  contentInsetAdjustmentBehavior?:
261
+    | 'automatic'
262
+    | 'scrollableAxes'
263
+    | 'never'
264
+    | 'always';
265 265
   dataDetectorTypes?: DataDetectorTypes | ReadonlyArray<DataDetectorTypes>;
266 266
   decelerationRate?: number;
267 267
   directionalLockEnabled?: boolean;
@@ -272,12 +272,6 @@ export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
272 272
 }
273 273
 
274 274
 export interface IOSWebViewProps extends WebViewSharedProps {
275
-  /**
276
-   * If true, use WKWebView instead of UIWebView.
277
-   * @platform ios
278
-   */
279
-  useWebKit?: boolean;
280
-
281 275
   /**
282 276
    * Does not store any data within the lifetime of the WebView.
283 277
    */
@@ -331,7 +325,11 @@ export interface IOSWebViewProps extends WebViewSharedProps {
331 325
    * content area of the scroll view. The default value of this property is
332 326
    * "never". Available on iOS 11 and later.
333 327
    */
334
-  contentInsetAdjustmentBehavior?: 'automatic'| 'scrollableAxes' | 'never' | 'always'
328
+  contentInsetAdjustmentBehavior?:
329
+    | 'automatic'
330
+    | 'scrollableAxes'
331
+    | 'never'
332
+    | 'always';
335 333
 
336 334
   /**
337 335
    * The amount by which the web view content is inset from the edges of
@@ -408,8 +406,8 @@ export interface IOSWebViewProps extends WebViewSharedProps {
408 406
   allowsLinkPreview?: boolean;
409 407
 
410 408
   /**
411
-   * Set true if shared cookies from HTTPCookieStorage should used for every load request in the
412
-   * `RNCWKWebView`. The default value is `false`.
409
+   * Set true if shared cookies from HTTPCookieStorage should used for every load request.
410
+   * The default value is `false`.
413 411
    * @platform ios
414 412
    */
415 413
   sharedCookiesEnabled?: boolean;
@@ -437,9 +435,8 @@ export interface IOSWebViewProps extends WebViewSharedProps {
437 435
   /**
438 436
    * A String value that indicates which URLs the WebView's file can then
439 437
    * reference in scripts, AJAX requests, and CSS imports. This is only used
440
-   * in `RNCWKWebView` for WebViews that are loaded with a source.uri set to a
441
-   * `'file://'` URL.
442
-   * 
438
+   * for WebViews that are loaded with a source.uri set to a `'file://'` URL.
439
+   *
443 440
    * If not provided, the default is to only allow read access to the URL
444 441
    * provided in source.uri itself.
445 442
    * @platform ios
@@ -463,6 +460,13 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
463 460
    */
464 461
   overScrollMode?: OverScrollModeType;
465 462
 
463
+  /**
464
+   * Boolean that controls whether the web content is scaled to fit
465
+   * the view and enables the user to change the scale. The default value
466
+   * is `true`.
467
+   */
468
+  scalesPageToFit?: boolean;
469
+
466 470
   /**
467 471
    * Sets whether Geolocation is enabled. The default is false.
468 472
    * @platform android
@@ -543,10 +547,10 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
543 547
    * @platform android
544 548
    */
545 549
   mixedContentMode?: 'never' | 'always' | 'compatibility';
546
-  
550
+
547 551
   /**
548 552
    * Sets ability to open fullscreen videos on Android devices.
549
-  */
553
+   */
550 554
   allowsFullscreenVideo?: boolean;
551 555
 }
552 556
 
@@ -562,7 +566,7 @@ export interface WebViewSharedProps extends ViewProps {
562 566
    * @platform android
563 567
    */
564 568
   javaScriptEnabled?: boolean;
565
-  
569
+
566 570
   /**
567 571
    * Function that returns a view to show if there's an error.
568 572
    */
@@ -645,15 +649,6 @@ export interface WebViewSharedProps extends ViewProps {
645 649
    */
646 650
   showsVerticalScrollIndicator?: boolean;
647 651
 
648
-  /**
649
-   * Boolean that controls whether the web content is scaled to fit
650
-   * the view and enables the user to change the scale. The default value
651
-   * is `true`.
652
-   *
653
-   * On iOS, when `useWebKit=true`, this prop will not work.
654
-   */
655
-  scalesPageToFit?: boolean;
656
-
657 652
   /**
658 653
    * Boolean that determines whether HTML5 audio and video requires the user
659 654
    * to tap them before they start playing. The default value is `true`.