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