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