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