Browse Source

Merge branch 'master' into master

Michael Diarmid 6 years ago
parent
commit
9d2bba932b
No account linked to committer's email address
8 changed files with 83 additions and 8 deletions
  1. 23
    0
      docs/Reference.md
  2. 2
    0
      ios/RNCWKWebView.h
  3. 6
    3
      ios/RNCWKWebView.m
  4. 2
    0
      ios/RNCWKWebViewManager.m
  5. 2
    0
      js/WebView.ios.js
  6. 18
    0
      js/WebViewTypes.js
  7. 1
    1
      package.json
  8. 29
    4
      typings/index.d.ts

+ 23
- 0
docs/Reference.md View File

@@ -47,6 +47,8 @@ This document lays out the current public properties and methods for the React N
47 47
 - [`allowFileAccess`](Reference.md#allowFileAccess)
48 48
 - [`saveFormDataDisabled`](Reference.md#saveFormDataDisabled)
49 49
 - [`enableCache`](Reference.md#enableCache)
50
+- [`pagingEnabled`](Reference.md#pagingEnabled)
51
+- [`allowsLinkPreview`](Reference.md#allowsLinkPreview)
50 52
 
51 53
 ## Methods Index
52 54
 
@@ -528,6 +530,27 @@ Sets whether WebView & WKWebView should use browser caching.
528 530
 | ------- | -------- | ------- |
529 531
 | boolean | No       | true    |
530 532
 
533
+---
534
+
535
+### `pagingEnabled`
536
+
537
+If the value of this property is true, the scroll view stops on multiples of the scroll view’s bounds when the user scrolls. The default value is false.
538
+
539
+| Type    | Required | Platform |
540
+| ------- | -------- | -------- |
541
+| boolean | No       | iOS      |
542
+
543
+---
544
+
545
+### `allowsLinkPreview`
546
+
547
+A Boolean value that determines whether pressing on a link displays a preview of the destination for the link. In iOS this property is available on devices that support 3D Touch. In iOS 10 and later, the default value is true; before that, the default value is false.
548
+
549
+| Type    | Required | Platform |
550
+| ------- | -------- | -------- |
551
+| boolean | No       | iOS      |
552
+
553
+
531 554
 ## Methods
532 555
 
533 556
 ### `extraNativeComponentConfig()`

+ 2
- 0
ios/RNCWKWebView.h View File

@@ -26,6 +26,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
26 26
 @property (nonatomic, assign) BOOL messagingEnabled;
27 27
 @property (nonatomic, copy) NSString *injectedJavaScript;
28 28
 @property (nonatomic, assign) BOOL scrollEnabled;
29
+@property (nonatomic, assign) BOOL pagingEnabled;
29 30
 @property (nonatomic, assign) CGFloat decelerationRate;
30 31
 @property (nonatomic, assign) BOOL allowsInlineMediaPlayback;
31 32
 @property (nonatomic, assign) BOOL bounces;
@@ -39,6 +40,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
39 40
 @property (nonatomic, assign) BOOL allowsBackForwardNavigationGestures;
40 41
 @property (nonatomic, copy) NSString *userAgent;
41 42
 @property (nonatomic, assign) BOOL enableCache;
43
+@property (nonatomic, assign) BOOL allowsLinkPreview;
42 44
 
43 45
 - (void)postMessage:(NSString *)message;
44 46
 - (void)injectJavaScript:(NSString *)script;

+ 6
- 3
ios/RNCWKWebView.m View File

@@ -70,7 +70,7 @@ static NSString *const MessageHanderName = @"ReactNative";
70 70
     _automaticallyAdjustContentInsets = YES;
71 71
     _contentInset = UIEdgeInsetsZero;
72 72
   }
73
-    
73
+
74 74
   // Workaround for a keyboard dismissal bug present in iOS 12
75 75
   // https://openradar.appspot.com/radar?id=5018321736957952
76 76
   if (@available(iOS 12.0, *)) {
@@ -114,9 +114,12 @@ static NSString *const MessageHanderName = @"ReactNative";
114 114
     _webView.UIDelegate = self;
115 115
     _webView.navigationDelegate = self;
116 116
     _webView.scrollView.scrollEnabled = _scrollEnabled;
117
+    _webView.scrollView.pagingEnabled = _pagingEnabled;
117 118
     _webView.scrollView.bounces = _bounces;
119
+    _webView.allowsLinkPreview = _allowsLinkPreview;
118 120
     [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
119 121
     _webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures;
122
+
120 123
     if (_userAgent) {
121 124
       _webView.customUserAgent = _userAgent;
122 125
     }
@@ -140,7 +143,7 @@ static NSString *const MessageHanderName = @"ReactNative";
140 143
         [_webView removeFromSuperview];
141 144
         _webView = nil;
142 145
     }
143
-    
146
+
144 147
     [super removeFromSuperview];
145 148
 }
146 149
 
@@ -149,7 +152,7 @@ static NSString *const MessageHanderName = @"ReactNative";
149 152
     keyboardTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(keyboardDisplacementFix) userInfo:nil repeats:false];
150 153
     [[NSRunLoop mainRunLoop] addTimer:keyboardTimer forMode:NSRunLoopCommonModes];
151 154
 }
152
-  
155
+
153 156
 -(void)keyboardWillShow
154 157
 {
155 158
     if (keyboardTimer != nil) {

+ 2
- 0
ios/RNCWKWebViewManager.m View File

@@ -45,8 +45,10 @@ RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
45 45
 RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
46 46
 RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL)
47 47
 RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
48
+RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
48 49
 RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
49 50
 RCT_EXPORT_VIEW_PROPERTY(enableCache, BOOL)
51
+RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL)
50 52
 
51 53
 /**
52 54
  * Expose methods to enable messaging the webview.

+ 2
- 0
js/WebView.ios.js View File

@@ -270,6 +270,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
270 270
         injectedJavaScript={this.props.injectedJavaScript}
271 271
         bounces={this.props.bounces}
272 272
         scrollEnabled={this.props.scrollEnabled}
273
+        pagingEnabled={this.props.pagingEnabled}
273 274
         decelerationRate={decelerationRate}
274 275
         contentInset={this.props.contentInset}
275 276
         automaticallyAdjustContentInsets={
@@ -291,6 +292,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
291 292
           this.props.mediaPlaybackRequiresUserAction
292 293
         }
293 294
         dataDetectorTypes={this.props.dataDetectorTypes}
295
+        allowsLinkPreview={this.props.allowsLinkPreview}
294 296
         {...nativeConfig.props}
295 297
       />
296 298
     );

+ 18
- 0
js/WebViewTypes.js View File

@@ -168,6 +168,14 @@ export type IOSWebViewProps = $ReadOnly<{|
168 168
    */
169 169
   scrollEnabled?: ?boolean,
170 170
 
171
+  /**
172
+   * If the value of this property is true, the scroll view stops on multiples
173
+   * of the scroll view’s bounds when the user scrolls.
174
+   * The default value is false.
175
+   * @platform ios
176
+   */
177
+  pagingEnabled?: ?boolean,
178
+
171 179
   /**
172 180
    * The amount by which the web view content is inset from the edges of
173 181
    * the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
@@ -233,6 +241,16 @@ export type IOSWebViewProps = $ReadOnly<{|
233 241
    * The custom user agent string.
234 242
    */
235 243
   userAgent?: ?string,
244
+
245
+  /**
246
+   * A Boolean value that determines whether pressing on a link
247
+   * displays a preview of the destination for the link.
248
+   *
249
+   * This property is available on devices that support 3D Touch.
250
+   * In iOS 10 and later, the default value is `true`; before that, the default value is `false`.
251
+   * @platform ios
252
+   */
253
+  allowsLinkPreview?: ?boolean,
236 254
 |}>;
237 255
 
238 256
 export type AndroidWebViewProps = $ReadOnly<{|

+ 1
- 1
package.json View File

@@ -8,7 +8,7 @@
8 8
     "Thibault Malbranche <malbranche.thibault@gmail.com>"
9 9
   ],
10 10
   "license": "MIT",
11
-  "version": "2.10.0",
11
+  "version": "2.13.0",
12 12
   "homepage": "https://github.com/react-native-community/react-native-webview#readme",
13 13
   "scripts": {
14 14
     "test:ios:flow": "flow check",

+ 29
- 4
typings/index.d.ts View File

@@ -9,6 +9,12 @@ export interface WebViewNativeEvent {
9 9
   readonly canGoForward: boolean;
10 10
 }
11 11
 
12
+export interface WebViewIOSLoadRequestEvent extends WebViewNativeEvent {
13
+  target: number;
14
+  lockIdentifier: number;
15
+  navigationType: "click" | "formsubmit" | "backforward" | "reload" | "formresubmit" | "other";
16
+}
17
+
12 18
 export interface WebViewProgressEvent extends WebViewNativeEvent {
13 19
   readonly progress: number;
14 20
 }
@@ -145,6 +151,14 @@ export interface IOSWebViewProps {
145 151
    */
146 152
   scrollEnabled?: boolean;
147 153
 
154
+  /**
155
+   * If the value of this property is true, the scroll view stops on multiples
156
+   * of the scroll view’s bounds when the user scrolls.
157
+   * The default value is false.
158
+   * @platform ios
159
+   */
160
+  pagingEnabled?: boolean,
161
+
148 162
   /**
149 163
    * The amount by which the web view content is inset from the edges of
150 164
    * the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
@@ -182,7 +196,7 @@ export interface IOSWebViewProps {
182 196
    * to stop loading.
183 197
    * @platform ios
184 198
    */
185
-  onShouldStartLoadWithRequest?: (event: WebViewNativeEvent) => any;
199
+  onShouldStartLoadWithRequest?: (event: WebViewIOSLoadRequestEvent) => any;
186 200
 
187 201
   /**
188 202
    * Boolean that determines whether HTML5 videos play inline or use the
@@ -202,7 +216,17 @@ export interface IOSWebViewProps {
202 216
   /**
203 217
    * If true, this will be able horizontal swipe gestures when using the WKWebView. The default value is `false`.
204 218
    */
205
-  allowsBackForwardNavigationGestures?: boolean
219
+  allowsBackForwardNavigationGestures?: boolean;
220
+
221
+  /**
222
+   * A Boolean value that determines whether pressing on a link
223
+   * displays a preview of the destination for the link.
224
+   *
225
+   * This property is available on devices that support 3D Touch.
226
+   * In iOS 10 and later, the default value is `true`; before that, the default value is `false`.
227
+   * @platform ios
228
+   */
229
+  allowsLinkPreview?: boolean;
206 230
 }
207 231
 
208 232
 export interface AndroidWebViewProps {
@@ -374,7 +398,7 @@ export interface WebViewSharedProps extends ViewProps, IOSWebViewProps, AndroidW
374 398
    * Boolean value that forces the `WebView` to show the loading view
375 399
    * on the first load.
376 400
    */
377
-  startInLoadingState?: string;
401
+  startInLoadingState?: boolean;
378 402
 
379 403
   /**
380 404
    * Set this to provide JavaScript that will be injected into the web page
@@ -421,5 +445,6 @@ export class WebView extends Component<WebViewSharedProps> {
421 445
   public goBack: () => void;
422 446
   public reload: () => void;
423 447
   public stopLoading: () => void;
424
-  public injectJavaScript: (js: string) => void
448
+  public postMessage: (msg: string) => void;
449
+  public injectJavaScript: (js: string) => void;
425 450
 }