|
@@ -0,0 +1,495 @@
|
|
1
|
+# React Native WebView API Reference
|
|
2
|
+
|
|
3
|
+This document lays out the current public properties and methods for the React Native WebView.
|
|
4
|
+
|
|
5
|
+> **Security Warning:** Currently, `onMessage` and `postMessage` do not allow specifying an origin. This can lead to cross-site scripting attacks if an unexpected document is loaded within a `WebView` instance. Please refer to the MDN documentation for [`Window.postMessage()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) for more details on the security implications of this.
|
|
6
|
+
|
|
7
|
+## Props Index
|
|
8
|
+
|
|
9
|
+- [`source`](Reference.md#source)
|
|
10
|
+- [`automaticallyAdjustContentInsets`](Reference.md#automaticallyadjustcontentinsets)
|
|
11
|
+- [`injectJavaScript`](Reference.md#injectjavascript)
|
|
12
|
+- [`injectedJavaScript`](Reference.md#injectedjavascript)
|
|
13
|
+- [`mediaPlaybackRequiresUserAction`](Reference.md#mediaplaybackrequiresuseraction)
|
|
14
|
+- [`nativeConfig`](Reference.md#nativeconfig)
|
|
15
|
+- [`onError`](Reference.md#onerror)
|
|
16
|
+- [`onLoad`](Reference.md#onload)
|
|
17
|
+- [`onLoadEnd`](Reference.md#onloadend)
|
|
18
|
+- [`onLoadStart`](Reference.md#onloadstart)
|
|
19
|
+- [`onMessage`](Reference.md#onmessage)
|
|
20
|
+- [`onNavigationStateChange`](Reference.md#onnavigationstatechange)
|
|
21
|
+- [`originWhitelist`](Reference.md#originwhitelist)
|
|
22
|
+- [`renderError`](Reference.md#rendererror)
|
|
23
|
+- [`renderLoading`](Reference.md#renderloading)
|
|
24
|
+- [`scalesPageToFit`](Reference.md#scalespagetofit)
|
|
25
|
+- [`onShouldStartLoadWithRequest`](Reference.md#onshouldstartloadwithrequest)
|
|
26
|
+- [`startInLoadingState`](Reference.md#startinloadingstate)
|
|
27
|
+- [`style`](Reference.md#style)
|
|
28
|
+- [`decelerationRate`](Reference.md#decelerationrate)
|
|
29
|
+- [`domStorageEnabled`](Reference.md#domstorageenabled)
|
|
30
|
+- [`javaScriptEnabled`](Reference.md#javascriptenabled)
|
|
31
|
+- [`mixedContentMode`](Reference.md#mixedcontentmode)
|
|
32
|
+- [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
|
|
33
|
+- [`userAgent`](Reference.md#useragent)
|
|
34
|
+- [`allowsInlineMediaPlayback`](Reference.md#allowsinlinemediaplayback)
|
|
35
|
+- [`bounces`](Reference.md#bounces)
|
|
36
|
+- [`contentInset`](Reference.md#contentinset)
|
|
37
|
+- [`dataDetectorTypes`](Reference.md#datadetectortypes)
|
|
38
|
+- [`scrollEnabled`](Reference.md#scrollenabled)
|
|
39
|
+- [`geolocationEnabled`](Reference.md#geolocationenabled)
|
|
40
|
+- [`allowUniversalAccessFromFileURLs`](Reference.md#allowUniversalAccessFromFileURLs)
|
|
41
|
+- [`useWebKit`](Reference.md#usewebkit)
|
|
42
|
+- [`url`](Reference.md#url)
|
|
43
|
+- [`html`](Reference.md#html)
|
|
44
|
+
|
|
45
|
+## Methods Index
|
|
46
|
+
|
|
47
|
+* [`extraNativeComponentConfig`](Reference.md#extranativecomponentconfig)
|
|
48
|
+* [`goForward`](Reference.md#goforward)
|
|
49
|
+* [`goBack`](Reference.md#goback)
|
|
50
|
+* [`reload`](Reference.md#reload)
|
|
51
|
+* [`stopLoading`](Reference.md#stoploading)
|
|
52
|
+
|
|
53
|
+---
|
|
54
|
+
|
|
55
|
+# Reference
|
|
56
|
+
|
|
57
|
+## Props
|
|
58
|
+
|
|
59
|
+### `source`
|
|
60
|
+
|
|
61
|
+Loads static HTML or a URI (with optional headers) in the WebView. Note that static HTML will require setting [`originWhitelist`](Reference.md#originwhitelist) to `["*"]`.
|
|
62
|
+
|
|
63
|
+The object passed to `source` can have either of the following shapes:
|
|
64
|
+
|
|
65
|
+**Load uri**
|
|
66
|
+
|
|
67
|
+* `uri` (string) - The URI to load in the `WebView`. Can be a local or remote file.
|
|
68
|
+* `method` (string) - The HTTP Method to use. Defaults to GET if not specified. On Android, the only supported methods are GET and POST.
|
|
69
|
+* `headers` (object) - Additional HTTP headers to send with the request. On Android, this can only be used with GET requests.
|
|
70
|
+* `body` (string) - The HTTP body to send with the request. This must be a valid UTF-8 string, and will be sent exactly as specified, with no additional encoding (e.g. URL-escaping or base64) applied. On Android, this can only be used with POST requests.
|
|
71
|
+
|
|
72
|
+**Static HTML**
|
|
73
|
+
|
|
74
|
+_Note that using static HTML requires the WebView property [originWhiteList](Reference.md#originWhiteList) to `['*']`._
|
|
75
|
+
|
|
76
|
+* `html` (string) - A static HTML page to display in the WebView.
|
|
77
|
+* `baseUrl` (string) - The base URL to be used for any relative links in the HTML.
|
|
78
|
+
|
|
79
|
+| Type | Required |
|
|
80
|
+| ------ | -------- |
|
|
81
|
+| object | No |
|
|
82
|
+
|
|
83
|
+---
|
|
84
|
+
|
|
85
|
+### `automaticallyAdjustContentInsets`
|
|
86
|
+
|
|
87
|
+Controls whether to adjust the content inset for web views that are placed behind a navigation bar, tab bar, or toolbar. The default value is `true`.
|
|
88
|
+
|
|
89
|
+| Type | Required |
|
|
90
|
+| ---- | -------- |
|
|
91
|
+| bool | No |
|
|
92
|
+
|
|
93
|
+---
|
|
94
|
+
|
|
95
|
+### `injectJavaScript`
|
|
96
|
+
|
|
97
|
+Function that accepts a string that will be passed to the WebView and executed immediately as JavaScript.
|
|
98
|
+
|
|
99
|
+| Type | Required |
|
|
100
|
+| -------- | -------- |
|
|
101
|
+| function | No |
|
|
102
|
+
|
|
103
|
+---
|
|
104
|
+
|
|
105
|
+### `injectedJavaScript`
|
|
106
|
+
|
|
107
|
+Set this to provide JavaScript that will be injected into the web page when the view loads.
|
|
108
|
+
|
|
109
|
+| Type | Required |
|
|
110
|
+| ------ | -------- |
|
|
111
|
+| string | No |
|
|
112
|
+
|
|
113
|
+---
|
|
114
|
+
|
|
115
|
+### `mediaPlaybackRequiresUserAction`
|
|
116
|
+
|
|
117
|
+Boolean that determines whether HTML5 audio and video requires the user to tap them before they start playing. The default value is `true`.
|
|
118
|
+
|
|
119
|
+| Type | Required |
|
|
120
|
+| ---- | -------- |
|
|
121
|
+| bool | No |
|
|
122
|
+
|
|
123
|
+---
|
|
124
|
+
|
|
125
|
+### `nativeConfig`
|
|
126
|
+
|
|
127
|
+Override the native component used to render the WebView. Enables a custom native WebView which uses the same JavaScript as the original WebView.
|
|
128
|
+
|
|
129
|
+The `nativeConfig` prop expects an object with the following keys:
|
|
130
|
+
|
|
131
|
+* `component` (any)
|
|
132
|
+* `props` (object)
|
|
133
|
+* `viewManager` (object)
|
|
134
|
+
|
|
135
|
+| Type | Required |
|
|
136
|
+| ------ | -------- |
|
|
137
|
+| object | No |
|
|
138
|
+
|
|
139
|
+---
|
|
140
|
+
|
|
141
|
+### `onError`
|
|
142
|
+
|
|
143
|
+Function that is invoked when the `WebView` load fails.
|
|
144
|
+
|
|
145
|
+| Type | Required |
|
|
146
|
+| -------- | -------- |
|
|
147
|
+| function | No |
|
|
148
|
+
|
|
149
|
+---
|
|
150
|
+
|
|
151
|
+### `onLoad`
|
|
152
|
+
|
|
153
|
+Function that is invoked when the `WebView` has finished loading.
|
|
154
|
+
|
|
155
|
+| Type | Required |
|
|
156
|
+| -------- | -------- |
|
|
157
|
+| function | No |
|
|
158
|
+
|
|
159
|
+---
|
|
160
|
+
|
|
161
|
+### `onLoadEnd`
|
|
162
|
+
|
|
163
|
+Function that is invoked when the `WebView` load succeeds or fails.
|
|
164
|
+
|
|
165
|
+| Type | Required |
|
|
166
|
+| -------- | -------- |
|
|
167
|
+| function | No |
|
|
168
|
+
|
|
169
|
+---
|
|
170
|
+
|
|
171
|
+### `onLoadStart`
|
|
172
|
+
|
|
173
|
+Function that is invoked when the `WebView` starts loading.
|
|
174
|
+
|
|
175
|
+| Type | Required |
|
|
176
|
+| -------- | -------- |
|
|
177
|
+| function | No |
|
|
178
|
+
|
|
179
|
+---
|
|
180
|
+
|
|
181
|
+### `onMessage`
|
|
182
|
+
|
|
183
|
+A function that is invoked when the webview calls `window.postMessage`. Setting this property will inject a `postMessage` global into your webview, but will still call pre-existing values of `postMessage`.
|
|
184
|
+
|
|
185
|
+`window.postMessage` accepts one argument, `data`, which will be available on the event object, `event.nativeEvent.data`. `data` must be a string.
|
|
186
|
+
|
|
187
|
+| Type | Required |
|
|
188
|
+| -------- | -------- |
|
|
189
|
+| function | No |
|
|
190
|
+
|
|
191
|
+---
|
|
192
|
+
|
|
193
|
+### `onNavigationStateChange`
|
|
194
|
+
|
|
195
|
+Function that is invoked when the `WebView` loading starts or ends.
|
|
196
|
+
|
|
197
|
+| Type | Required |
|
|
198
|
+| -------- | -------- |
|
|
199
|
+| function | No |
|
|
200
|
+
|
|
201
|
+---
|
|
202
|
+
|
|
203
|
+### `originWhitelist`
|
|
204
|
+
|
|
205
|
+List of origin strings to allow being navigated to. The strings allow wildcards and get matched against _just_ the origin (not the full URL). If the user taps to navigate to a new page but the new page is not in this whitelist, the URL will be handled by the OS. The default whitelisted origins are "http://*" and "https://*".
|
|
206
|
+
|
|
207
|
+| Type | Required |
|
|
208
|
+| ---------------- | -------- |
|
|
209
|
+| array of strings | No |
|
|
210
|
+
|
|
211
|
+---
|
|
212
|
+
|
|
213
|
+### `renderError`
|
|
214
|
+
|
|
215
|
+Function that returns a view to show if there's an error.
|
|
216
|
+
|
|
217
|
+| Type | Required |
|
|
218
|
+| -------- | -------- |
|
|
219
|
+| function | No |
|
|
220
|
+
|
|
221
|
+---
|
|
222
|
+
|
|
223
|
+### `renderLoading`
|
|
224
|
+
|
|
225
|
+Function that returns a loading indicator. The startInLoadingState prop must be set to true in order to use this prop.
|
|
226
|
+
|
|
227
|
+| Type | Required |
|
|
228
|
+| -------- | -------- |
|
|
229
|
+| function | No |
|
|
230
|
+
|
|
231
|
+---
|
|
232
|
+
|
|
233
|
+### `scalesPageToFit`
|
|
234
|
+
|
|
235
|
+Boolean that controls whether the web content is scaled to fit the view and enables the user to change the scale. The default value is `true`.
|
|
236
|
+
|
|
237
|
+On iOS, when [`useWebKit=true`](Reference.md#usewebkit), this prop will not work.
|
|
238
|
+
|
|
239
|
+| Type | Required |
|
|
240
|
+| ---- | -------- |
|
|
241
|
+| bool | No |
|
|
242
|
+
|
|
243
|
+---
|
|
244
|
+
|
|
245
|
+### `onShouldStartLoadWithRequest`
|
|
246
|
+
|
|
247
|
+Function that allows custom handling of any web view requests. Return `true` from the function to continue loading the request and `false` to stop loading.
|
|
248
|
+
|
|
249
|
+| Type | Required | Platform |
|
|
250
|
+| -------- | -------- | -------- |
|
|
251
|
+| function | No | iOS |
|
|
252
|
+
|
|
253
|
+---
|
|
254
|
+
|
|
255
|
+### `startInLoadingState`
|
|
256
|
+
|
|
257
|
+Boolean value that forces the `WebView` to show the loading view on the first load. This prop must be set to `true` in order for the `renderLoading` prop to work.
|
|
258
|
+
|
|
259
|
+| Type | Required |
|
|
260
|
+| ---- | -------- |
|
|
261
|
+| bool | No |
|
|
262
|
+
|
|
263
|
+---
|
|
264
|
+
|
|
265
|
+### `decelerationRate`
|
|
266
|
+
|
|
267
|
+A floating-point number that determines how quickly the scroll view decelerates after the user lifts their finger. You may also use the string shortcuts `"normal"` and `"fast"` which match the underlying iOS settings for `UIScrollViewDecelerationRateNormal` and `UIScrollViewDecelerationRateFast` respectively:
|
|
268
|
+
|
|
269
|
+* normal: 0.998
|
|
270
|
+* fast: 0.99 (the default for iOS web view)
|
|
271
|
+
|
|
272
|
+| Type | Required | Platform |
|
|
273
|
+| ------ | -------- | -------- |
|
|
274
|
+| number | No | iOS |
|
|
275
|
+
|
|
276
|
+---
|
|
277
|
+
|
|
278
|
+### `domStorageEnabled`
|
|
279
|
+
|
|
280
|
+Boolean value to control whether DOM Storage is enabled. Used only in Android.
|
|
281
|
+
|
|
282
|
+| Type | Required | Platform |
|
|
283
|
+| ---- | -------- | -------- |
|
|
284
|
+| bool | No | Android |
|
|
285
|
+
|
|
286
|
+---
|
|
287
|
+
|
|
288
|
+### `javaScriptEnabled`
|
|
289
|
+
|
|
290
|
+Boolean value to enable JavaScript in the `WebView`. Used on Android only as JavaScript is enabled by default on iOS. The default value is `true`.
|
|
291
|
+
|
|
292
|
+| Type | Required | Platform |
|
|
293
|
+| ---- | -------- | -------- |
|
|
294
|
+| bool | No | Android |
|
|
295
|
+
|
|
296
|
+---
|
|
297
|
+
|
|
298
|
+### `mixedContentMode`
|
|
299
|
+
|
|
300
|
+Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.
|
|
301
|
+
|
|
302
|
+Possible values for `mixedContentMode` are:
|
|
303
|
+
|
|
304
|
+* `never` (default) - WebView will not allow a secure origin to load content from an insecure origin.
|
|
305
|
+* `always` - WebView will allow a secure origin to load content from any other origin, even if that origin is insecure.
|
|
306
|
+* `compatibility` - WebView will attempt to be compatible with the approach of a modern web browser with regard to mixed content.
|
|
307
|
+
|
|
308
|
+| Type | Required | Platform |
|
|
309
|
+| ------ | -------- | -------- |
|
|
310
|
+| string | No | Android |
|
|
311
|
+
|
|
312
|
+---
|
|
313
|
+
|
|
314
|
+### `thirdPartyCookiesEnabled`
|
|
315
|
+
|
|
316
|
+Boolean value to enable third party cookies in the `WebView`. Used on Android Lollipop and above only as third party cookies are enabled by default on Android Kitkat and below and on iOS. The default value is `true`.
|
|
317
|
+
|
|
318
|
+| Type | Required | Platform |
|
|
319
|
+| ---- | -------- | -------- |
|
|
320
|
+| bool | No | Android |
|
|
321
|
+
|
|
322
|
+---
|
|
323
|
+
|
|
324
|
+### `userAgent`
|
|
325
|
+
|
|
326
|
+Sets the user-agent for the `WebView`.
|
|
327
|
+
|
|
328
|
+| Type | Required | Platform |
|
|
329
|
+| ------ | -------- | -------- |
|
|
330
|
+| string | No | Android |
|
|
331
|
+
|
|
332
|
+---
|
|
333
|
+
|
|
334
|
+### `allowsInlineMediaPlayback`
|
|
335
|
+
|
|
336
|
+Boolean that determines whether HTML5 videos play inline or use the native full-screen controller. The default value is `false`.
|
|
337
|
+
|
|
338
|
+> **NOTE**
|
|
339
|
+>
|
|
340
|
+> In order for video to play inline, not only does this property need to be set to `true`, but the video element in the HTML document must also include the `webkit-playsinline` attribute.
|
|
341
|
+
|
|
342
|
+| Type | Required | Platform |
|
|
343
|
+| ---- | -------- | -------- |
|
|
344
|
+| bool | No | iOS |
|
|
345
|
+
|
|
346
|
+---
|
|
347
|
+
|
|
348
|
+### `bounces`
|
|
349
|
+
|
|
350
|
+Boolean value that determines whether the web view bounces when it reaches the edge of the content. The default value is `true`.
|
|
351
|
+
|
|
352
|
+| Type | Required | Platform |
|
|
353
|
+| ---- | -------- | -------- |
|
|
354
|
+| bool | No | iOS |
|
|
355
|
+
|
|
356
|
+---
|
|
357
|
+
|
|
358
|
+### `contentInset`
|
|
359
|
+
|
|
360
|
+The amount by which the web view content is inset from the edges of the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
|
|
361
|
+
|
|
362
|
+| Type | Required | Platform |
|
|
363
|
+| ------------------------------------------------------------------ | -------- | -------- |
|
|
364
|
+| object: {top: number, left: number, bottom: number, right: number} | No | iOS |
|
|
365
|
+
|
|
366
|
+---
|
|
367
|
+
|
|
368
|
+### `dataDetectorTypes`
|
|
369
|
+
|
|
370
|
+Determines the types of data converted to clickable URLs in the web view's content. By default only phone numbers are detected.
|
|
371
|
+
|
|
372
|
+You can provide one type or an array of many types.
|
|
373
|
+
|
|
374
|
+Possible values for `dataDetectorTypes` are:
|
|
375
|
+
|
|
376
|
+* `phoneNumber`
|
|
377
|
+* `link`
|
|
378
|
+* `address`
|
|
379
|
+* `calendarEvent`
|
|
380
|
+* `none`
|
|
381
|
+* `all`
|
|
382
|
+
|
|
383
|
+With the [new WebKit](Reference.md#usewebkit) implementation, we have three new values:
|
|
384
|
+
|
|
385
|
+* `trackingNumber`
|
|
386
|
+* `flightNumber`
|
|
387
|
+* `lookupSuggestion`
|
|
388
|
+
|
|
389
|
+| Type | Required | Platform |
|
|
390
|
+| ---------------- | -------- | -------- |
|
|
391
|
+| string, or array | No | iOS |
|
|
392
|
+
|
|
393
|
+---
|
|
394
|
+
|
|
395
|
+### `scrollEnabled`
|
|
396
|
+
|
|
397
|
+Boolean value that determines whether scrolling is enabled in the `WebView`. The default value is `true`.
|
|
398
|
+
|
|
399
|
+| Type | Required | Platform |
|
|
400
|
+| ---- | -------- | -------- |
|
|
401
|
+| bool | No | iOS |
|
|
402
|
+
|
|
403
|
+---
|
|
404
|
+
|
|
405
|
+### `geolocationEnabled`
|
|
406
|
+
|
|
407
|
+Set whether Geolocation is enabled in the `WebView`. The default value is `false`. Used only in Android.
|
|
408
|
+
|
|
409
|
+| Type | Required | Platform |
|
|
410
|
+| ---- | -------- | -------- |
|
|
411
|
+| bool | No | Android |
|
|
412
|
+
|
|
413
|
+---
|
|
414
|
+
|
|
415
|
+### `allowUniversalAccessFromFileURLs`
|
|
416
|
+
|
|
417
|
+Boolean that sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from any origin. Including accessing content from other file scheme URLs. The default value is `false`.
|
|
418
|
+
|
|
419
|
+| Type | Required | Platform |
|
|
420
|
+| ---- | -------- | -------- |
|
|
421
|
+| bool | No | Android |
|
|
422
|
+
|
|
423
|
+---
|
|
424
|
+
|
|
425
|
+### `useWebKit`
|
|
426
|
+
|
|
427
|
+If true, use WKWebView instead of UIWebView.
|
|
428
|
+
|
|
429
|
+| Type | Required | Platform |
|
|
430
|
+| ------- | -------- | -------- |
|
|
431
|
+| boolean | No | iOS |
|
|
432
|
+
|
|
433
|
+---
|
|
434
|
+
|
|
435
|
+### `url`
|
|
436
|
+
|
|
437
|
+**Deprecated.** Use the `source` prop instead.
|
|
438
|
+
|
|
439
|
+| Type | Required |
|
|
440
|
+| ------ | -------- |
|
|
441
|
+| string | No |
|
|
442
|
+
|
|
443
|
+---
|
|
444
|
+
|
|
445
|
+### `html`
|
|
446
|
+
|
|
447
|
+**Deprecated.** Use the `source` prop instead.
|
|
448
|
+
|
|
449
|
+| Type | Required |
|
|
450
|
+| ------ | -------- |
|
|
451
|
+| string | No |
|
|
452
|
+
|
|
453
|
+## Methods
|
|
454
|
+
|
|
455
|
+### `extraNativeComponentConfig()`
|
|
456
|
+
|
|
457
|
+```javascript
|
|
458
|
+static extraNativeComponentConfig()
|
|
459
|
+```
|
|
460
|
+
|
|
461
|
+### `goForward()`
|
|
462
|
+
|
|
463
|
+```javascript
|
|
464
|
+goForward();
|
|
465
|
+```
|
|
466
|
+
|
|
467
|
+Go forward one page in the web view's history.
|
|
468
|
+
|
|
469
|
+### `goBack()`
|
|
470
|
+
|
|
471
|
+```javascript
|
|
472
|
+goBack();
|
|
473
|
+```
|
|
474
|
+
|
|
475
|
+Go back one page in the web view's history.
|
|
476
|
+
|
|
477
|
+### `reload()`
|
|
478
|
+
|
|
479
|
+```javascript
|
|
480
|
+reload();
|
|
481
|
+```
|
|
482
|
+
|
|
483
|
+Reloads the current page.
|
|
484
|
+
|
|
485
|
+### `stopLoading()`
|
|
486
|
+
|
|
487
|
+```javascript
|
|
488
|
+stopLoading();
|
|
489
|
+```
|
|
490
|
+
|
|
491
|
+Stop loading the current page.
|
|
492
|
+
|
|
493
|
+## Other Docs
|
|
494
|
+
|
|
495
|
+Also check out our [Getting Started Guide](Getting-Started.md) and [In-Depth Guide](Guide.md).
|