Kaynağa Gözat

merge upstream/master

KaFai Choi 6 yıl önce
ebeveyn
işleme
db6909cf82

+ 11
- 0
docs/Reference.md Dosyayı Görüntüle

@@ -47,6 +47,7 @@ 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
 - [`pagingEnabled`](Reference.md#pagingEnabled)
50
+- [`allowsLinkPreview`](Reference.md#allowsLinkPreview)
50 51
 
51 52
 ## Methods Index
52 53
 
@@ -528,6 +529,16 @@ If the value of this property is true, the scroll view stops on multiples of the
528 529
 | ------- | -------- | -------- |
529 530
 | boolean | No       | iOS      |
530 531
 
532
+---
533
+
534
+### `allowsLinkPreview`
535
+
536
+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.
537
+
538
+| Type    | Required | Platform |
539
+| ------- | -------- | -------- |
540
+| boolean | No       | iOS      |
541
+
531 542
 ## Methods
532 543
 
533 544
 ### `extraNativeComponentConfig()`

+ 1
- 0
ios/RNCWKWebView.h Dosyayı Görüntüle

@@ -39,6 +39,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
39 39
 @property (nonatomic, assign) BOOL hideKeyboardAccessoryView;
40 40
 @property (nonatomic, assign) BOOL allowsBackForwardNavigationGestures;
41 41
 @property (nonatomic, copy) NSString *userAgent;
42
+@property (nonatomic, assign) BOOL allowsLinkPreview;
42 43
 
43 44
 - (void)postMessage:(NSString *)message;
44 45
 - (void)injectJavaScript:(NSString *)script;

+ 2
- 0
ios/RNCWKWebView.m Dosyayı Görüntüle

@@ -113,8 +113,10 @@ static NSString *const MessageHanderName = @"ReactNative";
113 113
     _webView.scrollView.scrollEnabled = _scrollEnabled;
114 114
     _webView.scrollView.pagingEnabled = _pagingEnabled;
115 115
     _webView.scrollView.bounces = _bounces;
116
+    _webView.allowsLinkPreview = _allowsLinkPreview;
116 117
     [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
117 118
     _webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures;
119
+
118 120
     if (_userAgent) {
119 121
       _webView.customUserAgent = _userAgent;
120 122
     }

+ 1
- 0
ios/RNCWKWebViewManager.m Dosyayı Görüntüle

@@ -47,6 +47,7 @@ RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL)
47 47
 RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
48 48
 RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
49 49
 RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
50
+RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL)
50 51
 
51 52
 /**
52 53
  * Expose methods to enable messaging the webview.

+ 468
- 0
js/WebViewTypes.js Dosyayı Görüntüle

@@ -0,0 +1,468 @@
1
+/**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow
9
+ */
10
+
11
+'use strict';
12
+
13
+import type {Node, Element, ComponentType} from 'react';
14
+
15
+import type {SyntheticEvent} from 'CoreEventTypes';
16
+import type {EdgeInsetsProp} from 'EdgeInsetsPropType';
17
+import type {ViewStyleProp} from 'StyleSheet';
18
+import type {ViewProps} from 'ViewPropTypes';
19
+
20
+export type WebViewNativeEvent = $ReadOnly<{|
21
+  url: string,
22
+  loading: boolean,
23
+  title: string,
24
+  canGoBack: boolean,
25
+  canGoForward: boolean,
26
+|}>;
27
+
28
+export type WebViewProgressEvent = $ReadOnly<{|
29
+    ...WebViewNativeEvent,
30
+    progress: number,
31
+|}>
32
+
33
+export type WebViewNavigation = $ReadOnly<{|
34
+  ...WebViewNativeEvent,
35
+  navigationType:
36
+    | 'click'
37
+    | 'formsubmit'
38
+    | 'backforward'
39
+    | 'reload'
40
+    | 'formresubmit'
41
+    | 'other',
42
+|}>;
43
+
44
+export type WebViewMessage = $ReadOnly<{|
45
+  ...WebViewNativeEvent,
46
+  data: string,
47
+|}>;
48
+
49
+export type WebViewError = $ReadOnly<{|
50
+  ...WebViewNativeEvent,
51
+  /**
52
+   * `domain` is only used on iOS
53
+   */
54
+  domain: ?string,
55
+  code: number,
56
+  description: string,
57
+|}>;
58
+
59
+export type WebViewEvent = SyntheticEvent<WebViewNativeEvent>;
60
+
61
+export type WebViewNavigationEvent = SyntheticEvent<WebViewNavigation>;
62
+
63
+export type WebViewMessageEvent = SyntheticEvent<WebViewMessage>;
64
+
65
+export type WebViewErrorEvent = SyntheticEvent<WebViewError>;
66
+
67
+export type DataDetectorTypes =
68
+  | 'phoneNumber'
69
+  | 'link'
70
+  | 'address'
71
+  | 'calendarEvent'
72
+  | 'trackingNumber'
73
+  | 'flightNumber'
74
+  | 'lookupSuggestion'
75
+  | 'none'
76
+  | 'all';
77
+
78
+export type OverScrollModeType = 'always' | 'content' | 'never';
79
+
80
+export type WebViewSourceUri = $ReadOnly<{|
81
+  /**
82
+   * The URI to load in the `WebView`. Can be a local or remote file.
83
+   */
84
+  uri?: ?string,
85
+
86
+  /**
87
+   * The HTTP Method to use. Defaults to GET if not specified.
88
+   * NOTE: On Android, only GET and POST are supported.
89
+   */
90
+  method?: string,
91
+
92
+  /**
93
+   * Additional HTTP headers to send with the request.
94
+   * NOTE: On Android, this can only be used with GET requests.
95
+   */
96
+  headers?: Object,
97
+
98
+  /**
99
+   * The HTTP body to send with the request. This must be a valid
100
+   * UTF-8 string, and will be sent exactly as specified, with no
101
+   * additional encoding (e.g. URL-escaping or base64) applied.
102
+   * NOTE: On Android, this can only be used with POST requests.
103
+   */
104
+  body?: string,
105
+|}>;
106
+
107
+export type WebViewSourceHtml = $ReadOnly<{|
108
+  /**
109
+   * A static HTML page to display in the WebView.
110
+   */
111
+  html?: ?string,
112
+  /**
113
+   * The base URL to be used for any relative links in the HTML.
114
+   */
115
+  baseUrl?: ?string,
116
+|}>;
117
+
118
+export type WebViewSource = WebViewSourceUri | WebViewSourceHtml;
119
+
120
+export type WebViewNativeConfig = $ReadOnly<{|
121
+  /*
122
+   * The native component used to render the WebView.
123
+   */
124
+  component?: ComponentType<WebViewSharedProps>,
125
+  /*
126
+   * Set props directly on the native component WebView. Enables custom props which the
127
+   * original WebView doesn't pass through.
128
+   */
129
+  props?: ?Object,
130
+  /*
131
+   * Set the ViewManager to use for communication with the native side.
132
+   * @platform ios
133
+   */
134
+  viewManager?: ?Object,
135
+|}>;
136
+
137
+export type IOSWebViewProps = $ReadOnly<{|
138
+  /**
139
+   * If true, use WKWebView instead of UIWebView.
140
+   * @platform ios
141
+   */
142
+  useWebKit?: ?boolean,
143
+
144
+  /**
145
+   * Boolean value that determines whether the web view bounces
146
+   * when it reaches the edge of the content. The default value is `true`.
147
+   * @platform ios
148
+   */
149
+  bounces?: ?boolean,
150
+
151
+  /**
152
+   * A floating-point number that determines how quickly the scroll view
153
+   * decelerates after the user lifts their finger. You may also use the
154
+   * string shortcuts `"normal"` and `"fast"` which match the underlying iOS
155
+   * settings for `UIScrollViewDecelerationRateNormal` and
156
+   * `UIScrollViewDecelerationRateFast` respectively:
157
+   *
158
+   *   - normal: 0.998
159
+   *   - fast: 0.99 (the default for iOS web view)
160
+   * @platform ios
161
+   */
162
+  decelerationRate?: ?('fast' | 'normal' | number),
163
+
164
+  /**
165
+   * Boolean value that determines whether scrolling is enabled in the
166
+   * `WebView`. The default value is `true`.
167
+   * @platform ios
168
+   */
169
+  scrollEnabled?: ?boolean,
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
+
179
+  /**
180
+   * The amount by which the web view content is inset from the edges of
181
+   * the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
182
+   * @platform ios
183
+   */
184
+  contentInset?: ?EdgeInsetsProp,
185
+
186
+  /**
187
+   * Determines the types of data converted to clickable URLs in the web view's content.
188
+   * By default only phone numbers are detected.
189
+   *
190
+   * You can provide one type or an array of many types.
191
+   *
192
+   * Possible values for `dataDetectorTypes` are:
193
+   *
194
+   * - `'phoneNumber'`
195
+   * - `'link'`
196
+   * - `'address'`
197
+   * - `'calendarEvent'`
198
+   * - `'none'`
199
+   * - `'all'`
200
+   *
201
+   * With the new WebKit implementation, we have three new values:
202
+   * - `'trackingNumber'`,
203
+   * - `'flightNumber'`,
204
+   * - `'lookupSuggestion'`,
205
+   *
206
+   * @platform ios
207
+   */
208
+  dataDetectorTypes?:
209
+    | ?DataDetectorTypes
210
+    | $ReadOnlyArray<DataDetectorTypes>,
211
+
212
+  /**
213
+   * Function that allows custom handling of any web view requests. Return
214
+   * `true` from the function to continue loading the request and `false`
215
+   * to stop loading.
216
+   * @platform ios
217
+   */
218
+  onShouldStartLoadWithRequest?: (event: WebViewEvent) => mixed,
219
+
220
+  /**
221
+   * Boolean that determines whether HTML5 videos play inline or use the
222
+   * native full-screen controller. The default value is `false`.
223
+   *
224
+   * **NOTE** : In order for video to play inline, not only does this
225
+   * property need to be set to `true`, but the video element in the HTML
226
+   * document must also include the `webkit-playsinline` attribute.
227
+   * @platform ios
228
+   */
229
+  allowsInlineMediaPlayback?: ?boolean,
230
+  /**
231
+   * Hide the accessory view when the keyboard is open. Default is false to be
232
+   * backward compatible.
233
+   */
234
+  hideKeyboardAccessoryView?: ?boolean,
235
+  /**
236
+   * A Boolean value indicating whether horizontal swipe gestures will trigger
237
+   * back-forward list navigations.
238
+   */
239
+  allowsBackForwardNavigationGestures?: ?boolean,
240
+  /**
241
+   * The custom user agent string.
242
+   */
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,
254
+|}>;
255
+
256
+export type AndroidWebViewProps = $ReadOnly<{|
257
+  onNavigationStateChange?: (event: WebViewNavigation) => mixed,
258
+  onContentSizeChange?: (event: WebViewEvent) => mixed,
259
+
260
+  /**
261
+   * https://developer.android.com/reference/android/view/View#OVER_SCROLL_NEVER
262
+   * Sets the overScrollMode. Possible values are:
263
+   *
264
+   * - `'always'` (default)
265
+   * - `'content'`
266
+   * - `'never'`
267
+   *
268
+   * @platform android
269
+   */
270
+  overScrollMode?: ?OverScrollModeType,
271
+
272
+  /**
273
+   * Sets whether Geolocation is enabled. The default is false.
274
+   * @platform android
275
+   */
276
+  geolocationEnabled?: ?boolean,
277
+
278
+  /**
279
+   * Boolean that sets whether JavaScript running in the context of a file
280
+   * scheme URL should be allowed to access content from any origin.
281
+   * Including accessing content from other file scheme URLs
282
+   * @platform android
283
+   */
284
+  allowUniversalAccessFromFileURLs?: ?boolean,
285
+
286
+  /**
287
+   * Sets whether the webview allow access to file system.
288
+   * @platform android
289
+   */
290
+  allowFileAccess?: ?boolean,
291
+
292
+  /**
293
+   * Used on Android only, controls whether form autocomplete data should be saved
294
+   * @platform android
295
+   */
296
+  saveFormDataDisabled?: ?boolean,
297
+
298
+  /*
299
+   * Used on Android only, controls whether the given list of URL prefixes should
300
+   * make {@link com.facebook.react.views.webview.ReactWebViewClient} to launch a
301
+   * default activity intent for those URL instead of loading it within the webview.
302
+   * Use this to list URLs that WebView cannot handle, e.g. a PDF url.
303
+   * @platform android
304
+   */
305
+  urlPrefixesForDefaultIntent?: $ReadOnlyArray<string>,
306
+
307
+  /**
308
+   * Boolean value to enable JavaScript in the `WebView`. Used on Android only
309
+   * as JavaScript is enabled by default on iOS. The default value is `true`.
310
+   * @platform android
311
+   */
312
+  javaScriptEnabled?: ?boolean,
313
+
314
+  /**
315
+   * Boolean value to enable third party cookies in the `WebView`. Used on
316
+   * Android Lollipop and above only as third party cookies are enabled by
317
+   * default on Android Kitkat and below and on iOS. The default value is `true`.
318
+   * @platform android
319
+   */
320
+  thirdPartyCookiesEnabled?: ?boolean,
321
+
322
+  /**
323
+   * Boolean value to control whether DOM Storage is enabled. Used only in
324
+   * Android.
325
+   * @platform android
326
+   */
327
+  domStorageEnabled?: ?boolean,
328
+
329
+  /**
330
+   * Sets the user-agent for the `WebView`.
331
+   * @platform android
332
+   */
333
+  userAgent?: ?string,
334
+
335
+  /**
336
+   * Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.
337
+   *
338
+   * Possible values for `mixedContentMode` are:
339
+   *
340
+   * - `'never'` (default) - WebView will not allow a secure origin to load content from an insecure origin.
341
+   * - `'always'` - WebView will allow a secure origin to load content from any other origin, even if that origin is insecure.
342
+   * - `'compatibility'` -  WebView will attempt to be compatible with the approach of a modern web browser with regard to mixed content.
343
+   * @platform android
344
+   */
345
+  mixedContentMode?: ?('never' | 'always' | 'compatibility'),
346
+|}>;
347
+
348
+export type WebViewSharedProps =  $ReadOnly<{|
349
+  ...ViewProps,
350
+  ...IOSWebViewProps,
351
+  ...AndroidWebViewProps,
352
+  /**
353
+   * Deprecated. Use `source` instead.
354
+   */
355
+  url?: ?string,
356
+  /**
357
+   * Deprecated. Use `source` instead.
358
+   */
359
+  html?: ?string,
360
+
361
+  /**
362
+   * Loads static html or a uri (with optional headers) in the WebView.
363
+   */
364
+  source?: ?WebViewSource,
365
+
366
+  /**
367
+   * Function that returns a view to show if there's an error.
368
+   */
369
+  renderError: (errorDomain: ?string, errorCode: number, errorDesc: string) => Element<any>, // view to show if there's an error
370
+
371
+  /**
372
+   * Function that returns a loading indicator.
373
+   */
374
+  renderLoading: () => Element<any>,
375
+
376
+  /**
377
+   * Function that is invoked when the `WebView` has finished loading.
378
+   */
379
+  onLoad: (event: WebViewNavigationEvent) => mixed,
380
+
381
+  /**
382
+   * Function that is invoked when the `WebView` load succeeds or fails.
383
+   */
384
+  onLoadEnd: (event: WebViewNavigationEvent | WebViewErrorEvent) => mixed,
385
+
386
+  /**
387
+   * Function that is invoked when the `WebView` starts loading.
388
+   */
389
+  onLoadStart: (event: WebViewNavigationEvent) => mixed,
390
+
391
+  /**
392
+   * Function that is invoked when the `WebView` load fails.
393
+   */
394
+  onError: (event: WebViewErrorEvent) => mixed,
395
+
396
+  /**
397
+   * Controls whether to adjust the content inset for web views that are
398
+   * placed behind a navigation bar, tab bar, or toolbar. The default value
399
+   * is `true`.
400
+   */
401
+  automaticallyAdjustContentInsets?: ?boolean,
402
+
403
+  /**
404
+   * Function that is invoked when the `WebView` loading starts or ends.
405
+   */
406
+  onNavigationStateChange?: (event: WebViewNavigation) => mixed,
407
+
408
+  /**
409
+   * A function that is invoked when the webview calls `window.postMessage`.
410
+   * Setting this property will inject a `postMessage` global into your
411
+   * webview, but will still call pre-existing values of `postMessage`.
412
+   *
413
+   * `window.postMessage` accepts one argument, `data`, which will be
414
+   * available on the event object, `event.nativeEvent.data`. `data`
415
+   * must be a string.
416
+   */
417
+  onMessage?: (event: WebViewMessageEvent) => mixed,
418
+
419
+  /**
420
+   * Function that is invoked when the `WebView` is loading.
421
+   */
422
+  onLoadProgress?: (event: WebViewProgressEvent) => mixed,
423
+
424
+  /**
425
+   * Boolean value that forces the `WebView` to show the loading view
426
+   * on the first load.
427
+   */
428
+  startInLoadingState?: ?boolean,
429
+
430
+  /**
431
+   * Set this to provide JavaScript that will be injected into the web page
432
+   * when the view loads.
433
+   */
434
+  injectedJavaScript?: ?string,
435
+
436
+  /**
437
+   * Boolean that controls whether the web content is scaled to fit
438
+   * the view and enables the user to change the scale. The default value
439
+   * is `true`.
440
+   *
441
+   * On iOS, when `useWebKit=true`, this prop will not work.
442
+   */
443
+  scalesPageToFit?: ?boolean,
444
+
445
+  /**
446
+   * Boolean that determines whether HTML5 audio and video requires the user
447
+   * to tap them before they start playing. The default value is `true`.
448
+   */
449
+  mediaPlaybackRequiresUserAction?: ?boolean,
450
+
451
+  /**
452
+   * List of origin strings to allow being navigated to. The strings allow
453
+   * wildcards and get matched against *just* the origin (not the full URL).
454
+   * If the user taps to navigate to a new page but the new page is not in
455
+   * this whitelist, we will open the URL in Safari.
456
+   * The default whitelisted origins are "http://*" and "https://*".
457
+   */
458
+  originWhitelist?: $ReadOnlyArray<string>,
459
+
460
+  /**
461
+   * Override the native component used to render the WebView. Enables a custom native
462
+   * WebView which uses the same JavaScript as the original WebView.
463
+   */
464
+  nativeConfig?: ?WebViewNativeConfig,
465
+
466
+  style?: ViewStyleProp,
467
+  children: Node,
468
+|}>;

+ 1
- 1
package.json Dosyayı Görüntüle

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

+ 1
- 0
src/WebView.ios.tsx Dosyayı Görüntüle

@@ -281,6 +281,7 @@ export default class WebView extends React.Component<
281 281
           this.props.mediaPlaybackRequiresUserAction
282 282
         }
283 283
         dataDetectorTypes={this.props.dataDetectorTypes}
284
+        allowsLinkPreview={this.props.allowsLinkPreview}
284 285
         {...nativeConfig.props}
285 286
       />
286 287
     );

+ 10
- 0
src/types/WebViewTypes.ts Dosyayı Görüntüle

@@ -238,6 +238,16 @@ export interface IOSWebViewProps {
238 238
    * If true, this will be able horizontal swipe gestures when using the WKWebView. The default value is `false`.
239 239
    */
240 240
   allowsBackForwardNavigationGestures?: boolean;
241
+
242
+  /**
243
+   * A Boolean value that determines whether pressing on a link
244
+   * displays a preview of the destination for the link.
245
+   *
246
+   * This property is available on devices that support 3D Touch.
247
+   * In iOS 10 and later, the default value is `true`; before that, the default value is `false`.
248
+   * @platform ios
249
+   */
250
+  allowsLinkPreview?: boolean;
241 251
 }
242 252
 
243 253
 export interface AndroidWebViewProps {