2018-09-20 02:27:09 +00:00
# React Native WebView API Reference
This document lays out the current public properties and methods for the React Native WebView.
## Props Index
- [`source` ](Reference.md#source )
- [`automaticallyAdjustContentInsets` ](Reference.md#automaticallyadjustcontentinsets )
- [`injectedJavaScript` ](Reference.md#injectedjavascript )
2020-03-17 21:01:20 +00:00
- [`injectedJavaScriptBeforeContentLoaded` ](Reference.md#injectedjavascriptbeforecontentloaded )
- [`injectedJavaScriptForMainFrameOnly` ](Reference.md#injectedjavascriptformainframeonly )
- [`injectedJavaScriptBeforeContentLoadedForMainFrameOnly` ](Reference.md#injectedjavascriptbeforecontentloadedformainframeonly )
2018-09-20 02:27:09 +00:00
- [`mediaPlaybackRequiresUserAction` ](Reference.md#mediaplaybackrequiresuseraction )
- [`nativeConfig` ](Reference.md#nativeconfig )
- [`onError` ](Reference.md#onerror )
2020-08-06 20:21:01 +00:00
- [`onRenderProcessGone` ](Reference.md#onRenderProcessGone )
2018-09-20 02:27:09 +00:00
- [`onLoad` ](Reference.md#onload )
- [`onLoadEnd` ](Reference.md#onloadend )
- [`onLoadStart` ](Reference.md#onloadstart )
2018-10-17 13:08:52 +00:00
- [`onLoadProgress` ](Reference.md#onloadprogress )
2019-09-21 00:43:28 +00:00
- [`onHttpError` ](Reference.md#onhttperror )
2018-09-20 02:27:09 +00:00
- [`onMessage` ](Reference.md#onmessage )
- [`onNavigationStateChange` ](Reference.md#onnavigationstatechange )
2019-09-23 08:20:12 +00:00
- [`onContentProcessDidTerminate` ](Reference.md#oncontentprocessdidterminate )
2018-09-20 02:27:09 +00:00
- [`originWhitelist` ](Reference.md#originwhitelist )
- [`renderError` ](Reference.md#rendererror )
- [`renderLoading` ](Reference.md#renderloading )
- [`scalesPageToFit` ](Reference.md#scalespagetofit )
- [`onShouldStartLoadWithRequest` ](Reference.md#onshouldstartloadwithrequest )
- [`startInLoadingState` ](Reference.md#startinloadingstate )
- [`style` ](Reference.md#style )
2019-09-29 13:43:48 +00:00
- [`containerStyle` ](Reference.md#containerStyle )
2018-09-20 02:27:09 +00:00
- [`decelerationRate` ](Reference.md#decelerationrate )
- [`domStorageEnabled` ](Reference.md#domstorageenabled )
- [`javaScriptEnabled` ](Reference.md#javascriptenabled )
2020-05-28 16:54:20 +00:00
- [`javaScriptCanOpenWindowsAutomatically` ](Reference.md#javascriptcanopenwindowsautomatically )
2019-01-22 09:21:10 +00:00
- [`androidHardwareAccelerationDisabled` ](Reference.md#androidHardwareAccelerationDisabled )
2020-08-24 12:23:38 +00:00
- [`androidLayerType` ](Reference.md#androidLayerType )
2018-09-20 02:27:09 +00:00
- [`mixedContentMode` ](Reference.md#mixedcontentmode )
- [`thirdPartyCookiesEnabled` ](Reference.md#thirdpartycookiesenabled )
- [`userAgent` ](Reference.md#useragent )
2019-05-20 22:01:22 +00:00
- [`applicationNameForUserAgent` ](Reference.md#applicationNameForUserAgent )
2019-05-16 22:22:08 +00:00
- [`allowsFullscreenVideo` ](Reference.md#allowsfullscreenvideo )
2018-09-20 02:27:09 +00:00
- [`allowsInlineMediaPlayback` ](Reference.md#allowsinlinemediaplayback )
- [`bounces` ](Reference.md#bounces )
2018-10-17 14:48:19 +00:00
- [`overScrollMode` ](Reference.md#overscrollmode )
2018-09-20 02:27:09 +00:00
- [`contentInset` ](Reference.md#contentinset )
2019-08-09 08:55:35 +00:00
- [`contentInsetAdjustmentBehavior` ](Reference.md#contentInsetAdjustmentBehavior )
2020-08-15 03:16:54 +00:00
- [`contentMode` ](Reference.md#contentMode )
2018-09-20 02:27:09 +00:00
- [`dataDetectorTypes` ](Reference.md#datadetectortypes )
- [`scrollEnabled` ](Reference.md#scrollenabled )
2019-03-07 09:27:29 +00:00
- [`directionalLockEnabled` ](Reference.md#directionalLockEnabled )
2018-09-20 02:27:09 +00:00
- [`geolocationEnabled` ](Reference.md#geolocationenabled )
2019-09-29 13:50:39 +00:00
- [`allowFileAccessFromFileURLs` ](Reference.md#allowFileAccessFromFileURLs )
2018-09-20 02:27:09 +00:00
- [`allowUniversalAccessFromFileURLs` ](Reference.md#allowUniversalAccessFromFileURLs )
2019-08-29 14:53:09 +00:00
- [`allowingReadAccessToURL` ](Reference.md#allowingReadAccessToURL )
2018-09-20 02:27:09 +00:00
- [`url` ](Reference.md#url )
- [`html` ](Reference.md#html )
2019-04-29 15:46:07 +00:00
- [`keyboardDisplayRequiresUserAction` ](Reference.md#keyboardDisplayRequiresUserAction )
2018-10-17 14:59:19 +00:00
- [`hideKeyboardAccessoryView` ](Reference.md#hidekeyboardaccessoryview )
2018-10-21 21:12:59 +00:00
- [`allowsBackForwardNavigationGestures` ](Reference.md#allowsbackforwardnavigationgestures )
2019-01-11 13:59:03 +00:00
- [`incognito` ](Reference.md#incognito )
2018-11-19 10:18:49 +00:00
- [`allowFileAccess` ](Reference.md#allowFileAccess )
- [`saveFormDataDisabled` ](Reference.md#saveFormDataDisabled )
2019-01-30 09:32:46 +00:00
- [`cacheEnabled` ](Reference.md#cacheEnabled )
2019-09-29 13:45:20 +00:00
- [`cacheMode` ](Reference.md#cacheMode )
2018-11-22 12:58:07 +00:00
- [`pagingEnabled` ](Reference.md#pagingEnabled )
2018-11-25 10:17:28 +00:00
- [`allowsLinkPreview` ](Reference.md#allowsLinkPreview )
2019-04-15 08:19:10 +00:00
- [`sharedCookiesEnabled` ](Reference.md#sharedCookiesEnabled )
2019-07-02 15:38:00 +00:00
- [`textZoom` ](Reference.md#textZoom )
2020-08-17 10:07:36 +00:00
- [`pullToRefreshEnabled` ](Reference.md#pullToRefreshEnabled )
2020-04-13 15:54:47 +00:00
- [`ignoreSilentHardwareSwitch` ](Reference.md#ignoreSilentHardwareSwitch )
2020-04-29 16:09:22 +00:00
- [`onFileDownload` ](Reference.md#onFileDownload )
2020-09-15 00:42:09 +00:00
- [`autoManageStatusBarEnabled` ](Reference.md#autoManageStatusBarEnabled )
2018-09-20 02:27:09 +00:00
## Methods Index
2018-10-17 13:08:52 +00:00
- [`extraNativeComponentConfig` ](Reference.md#extranativecomponentconfig )
- [`goForward` ](Reference.md#goforward )
- [`goBack` ](Reference.md#goback )
- [`reload` ](Reference.md#reload )
- [`stopLoading` ](Reference.md#stoploading )
2018-10-30 13:48:10 +00:00
- [`injectJavaScript` ](Reference.md#injectjavascriptstr )
2019-11-12 09:09:16 +00:00
- [`clearFormData` ](Reference.md#clearFormData )
- [`clearCache` ](Reference.md#clearCache )
- [`clearHistory` ](Reference.md#clearHistory )
2019-11-13 09:43:25 +00:00
- [`requestFocus` ](Reference.md#requestFocus )
2020-05-29 20:19:11 +00:00
- [`postMessage` ](Reference.md#postMessage )
2020-02-26 06:54:06 +00:00
2018-09-20 02:27:09 +00:00
---
# Reference
## Props
2020-07-24 05:21:56 +00:00
### `source`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Loads static HTML or a URI (with optional headers) in the WebView. Note that static HTML will require setting [`originWhitelist` ](Reference.md#originwhitelist ) to `["*"]` .
The object passed to `source` can have either of the following shapes:
**Load uri**
2019-11-04 16:30:51 +00:00
- `uri` (string) - The URI to load in the `WebView` . Can be a local or remote file, and can be changed with React state or props to navigate to a new page.
2018-10-17 13:08:52 +00:00
- `method` (string) - The HTTP Method to use. Defaults to GET if not specified. On Android, the only supported methods are GET and POST.
2019-11-04 16:30:51 +00:00
- `headers` (object) - Additional HTTP headers to send with the request. On Android, this can only be used with GET requests. See the [Guide ](Guide.md#setting-custom-headers ) for more information on setting custom headers.
2018-10-17 13:08:52 +00:00
- `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.
2018-09-20 02:27:09 +00:00
**Static HTML**
2019-06-04 14:46:27 +00:00
_Note that using static HTML requires the WebView property [originWhiteList ](Reference.md#originWhiteList ) to `['*']` . For some content, such as video embeds (e.g. Twitter or Facebook posts with video), the baseUrl needs to be set for the video playback to work_
2018-09-20 04:20:56 +00:00
2018-10-17 13:08:52 +00:00
- `html` (string) - A static HTML page to display in the WebView.
2019-09-19 09:18:59 +00:00
- `baseUrl` (string) - The base URL to be used for any relative links in the HTML. This is also used for the origin header with CORS requests made from the WebView. See [Android WebView Docs ](https://developer.android.com/reference/android/webkit/WebView#loadDataWithBaseURL )
2018-09-20 02:27:09 +00:00
| Type | Required |
| ------ | -------- |
| object | No |
---
2020-07-24 05:21:56 +00:00
### `automaticallyAdjustContentInsets`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
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` .
2019-03-20 12:35:13 +00:00
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | iOS |
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `injectedJavaScript`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
2020-03-17 21:01:20 +00:00
Set this to provide JavaScript that will be injected into the web page after the document finishes loading, but before other subresources finish loading.
Make sure the string evaluates to a valid type (`true` works) and doesn't otherwise throw an exception.
2020-10-21 15:52:28 +00:00
On iOS, see [`WKUserScriptInjectionTimeAtDocumentEnd` ](https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime/wkuserscriptinjectiontimeatdocumentend?language=objc ). Be sure
to set an [`onMessage` ](Reference.md#onmessage ) handler, even if it's a no-op, or the code will not be run.
2018-09-20 02:27:09 +00:00
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ------ | -------- | ------------------- |
| string | No | iOS, Android, macOS |
2018-09-20 02:27:09 +00:00
2019-03-03 00:32:42 +00:00
To learn more, read the [Communicating between JS and Native ](Guide.md#communicating-between-js-and-native ) guide.
2019-05-16 22:24:18 +00:00
Example:
Post message a JSON object of `window.location` to be handled by [`onMessage` ](Reference.md#onmessage )
```jsx
const INJECTED_JAVASCRIPT = `(function() {
window.ReactNativeWebView.postMessage(JSON.stringify(window.location));
})();`;
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2019-05-16 22:24:18 +00:00
injectedJavaScript={INJECTED_JAVASCRIPT}
2019-12-06 10:15:02 +00:00
onMessage={this.onMessage}
/>;
```
---
2020-07-24 05:21:56 +00:00
### `injectedJavaScriptBeforeContentLoaded`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-12-06 10:15:02 +00:00
2020-03-17 21:01:20 +00:00
Set this to provide JavaScript that will be injected into the web page after the document element is created, but before other subresources finish loading.
Make sure the string evaluates to a valid type (`true` works) and doesn't otherwise throw an exception.
On iOS, see [`WKUserScriptInjectionTimeAtDocumentStart` ](https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime/wkuserscriptinjectiontimeatdocumentstart?language=objc )
2019-12-06 10:15:02 +00:00
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ------ | -------- | ---------- |
2020-03-17 21:01:20 +00:00
| string | No | iOS, macOS |
2019-12-06 10:15:02 +00:00
To learn more, read the [Communicating between JS and Native ](Guide.md#communicating-between-js-and-native ) guide.
Example:
2020-09-15 00:42:09 +00:00
Post message a JSON object of `window.location` to be handled by [`onMessage` ](Reference.md#onmessage ). `window.ReactNativeWebView.postMessage` _will_ be available at this time.
2019-12-06 10:15:02 +00:00
```jsx
const INJECTED_JAVASCRIPT = `(function() {
window.ReactNativeWebView.postMessage(JSON.stringify(window.location));
})();`;
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2019-12-06 10:15:02 +00:00
injectedJavaScriptBeforeContentLoaded={INJECTED_JAVASCRIPT}
2019-05-16 22:24:18 +00:00
onMessage={this.onMessage}
2019-08-30 10:04:32 +00:00
/>;
2019-05-16 22:24:18 +00:00
```
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `injectedJavaScriptForMainFrameOnly`[⬆](#props-index)<!-- Link generated with jump2header -->
2020-03-17 21:01:20 +00:00
2020-06-13 20:54:48 +00:00
If `true` (default; mandatory for Android), loads the `injectedJavaScript` only into the main frame.
2020-03-17 21:01:20 +00:00
2020-06-13 20:54:48 +00:00
If `false` , (only supported on iOS and macOS), loads it into all frames (e.g. iframes).
2020-03-17 21:01:20 +00:00
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ---- | -------- | ------------------------------------------------- |
2020-06-13 20:54:48 +00:00
| bool | No | iOS and macOS (only `true` supported for Android) |
2020-03-17 21:01:20 +00:00
---
2020-07-24 05:21:56 +00:00
### `injectedJavaScriptBeforeContentLoadedForMainFrameOnly`[⬆](#props-index)<!-- Link generated with jump2header -->
2020-03-17 21:01:20 +00:00
2020-06-13 20:54:48 +00:00
If `true` (default; mandatory for Android), loads the `injectedJavaScriptBeforeContentLoaded` only into the main frame.
2020-03-17 21:01:20 +00:00
2020-06-13 20:54:48 +00:00
If `false` , (only supported on iOS and macOS), loads it into all frames (e.g. iframes).
2020-03-17 21:01:20 +00:00
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ---- | -------- | ------------------------------------------------- |
2020-06-13 20:54:48 +00:00
| bool | No | iOS and macOS (only `true` supported for Android) |
2020-03-17 21:01:20 +00:00
---
2020-07-24 05:21:56 +00:00
### `mediaPlaybackRequiresUserAction`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
2019-02-28 21:10:47 +00:00
Boolean that determines whether HTML5 audio and video requires the user to tap them before they start playing. The default value is `true` . (Android API minimum version 17).
NOTE: the default `true` value might cause some videos to hang loading on iOS. Setting it to `false` could fix this issue.
2018-09-20 02:27:09 +00:00
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ---- | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| bool | No | iOS, Android, macOS |
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `nativeConfig`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Override the native component used to render the WebView. Enables a custom native WebView which uses the same JavaScript as the original WebView.
The `nativeConfig` prop expects an object with the following keys:
2018-10-17 13:08:52 +00:00
- `component` (any)
- `props` (object)
- `viewManager` (object)
2018-09-20 02:27:09 +00:00
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ------ | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| object | No | iOS, Android, macOS |
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `onError`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Function that is invoked when the `WebView` load fails.
| Type | Required |
| -------- | -------- |
| function | No |
2019-03-01 00:36:56 +00:00
Example:
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2020-09-15 00:42:09 +00:00
onError={(syntheticEvent) => {
2019-03-20 12:35:13 +00:00
const { nativeEvent } = syntheticEvent;
console.warn('WebView error: ', nativeEvent);
}}
/>
2019-03-01 00:36:56 +00:00
```
Function passed to `onError` is called with a SyntheticEvent wrapping a nativeEvent with these properties:
```
2019-03-20 12:35:13 +00:00
canGoBack
canGoForward
code
description
didFailProvisionalNavigation
domain
loading
target
title
url
```
2019-03-01 00:36:56 +00:00
> **_Note_**
> Domain is only used on iOS
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `onLoad`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Function that is invoked when the `WebView` has finished loading.
| Type | Required |
| -------- | -------- |
| function | No |
2019-03-01 00:36:56 +00:00
Example:
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2020-09-15 00:42:09 +00:00
onLoad={(syntheticEvent) => {
2019-03-01 00:36:56 +00:00
const { nativeEvent } = syntheticEvent;
this.url = nativeEvent.url;
}}
/>
```
Function passed to `onLoad` is called with a SyntheticEvent wrapping a nativeEvent with these properties:
2019-03-20 12:35:13 +00:00
```
canGoBack
canGoForward
loading
target
title
url
2019-03-01 00:36:56 +00:00
```
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `onLoadEnd`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Function that is invoked when the `WebView` load succeeds or fails.
| Type | Required |
| -------- | -------- |
| function | No |
2019-03-01 00:36:56 +00:00
Example:
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2020-09-15 00:42:09 +00:00
onLoadEnd={(syntheticEvent) => {
2019-03-01 00:36:56 +00:00
// update component to be aware of loading status
const { nativeEvent } = syntheticEvent;
this.isLoading = nativeEvent.loading;
}}
/>
```
Function passed to `onLoadEnd` is called with a SyntheticEvent wrapping a nativeEvent with these properties:
2019-03-20 12:35:13 +00:00
```
canGoBack
canGoForward
loading
target
title
url
2019-03-01 00:36:56 +00:00
```
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `onLoadStart`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Function that is invoked when the `WebView` starts loading.
| Type | Required |
| -------- | -------- |
| function | No |
2019-03-01 00:36:56 +00:00
Example:
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev/=' }}
2020-09-15 00:42:09 +00:00
onLoadStart={(syntheticEvent) => {
2019-03-01 00:36:56 +00:00
// update component to be aware of loading status
const { nativeEvent } = syntheticEvent;
this.isLoading = nativeEvent.loading;
}}
/>
```
Function passed to `onLoadStart` is called with a SyntheticEvent wrapping a nativeEvent with these properties:
2019-03-20 12:35:13 +00:00
```
canGoBack
canGoForward
loading
target
title
url
2019-03-01 00:36:56 +00:00
```
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `onLoadProgress`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-10-17 13:08:52 +00:00
Function that is invoked when the `WebView` is loading.
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| -------- | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| function | No | iOS, Android, macOS |
2018-10-17 13:08:52 +00:00
2019-03-01 00:36:56 +00:00
Example:
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2019-03-20 12:35:13 +00:00
onLoadProgress={({ nativeEvent }) => {
this.loadingProgress = nativeEvent.progress;
}}
/>
2019-03-01 00:36:56 +00:00
```
Function passed to `onLoadProgress` is called with a SyntheticEvent wrapping a nativeEvent with these properties:
2019-03-20 12:35:13 +00:00
```
canGoBack
canGoForward
loading
progress
target
title
url
2019-03-01 00:36:56 +00:00
```
2018-10-17 13:08:52 +00:00
---
2020-07-24 05:21:56 +00:00
### `onHttpError`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-09-21 00:43:28 +00:00
Function that is invoked when the `WebView` receives an http error.
2019-09-29 13:43:48 +00:00
2019-09-21 00:43:28 +00:00
> **_Note_**
> Android API minimum level 23.
| Type | Required |
| -------- | -------- |
| function | No |
Example:
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2020-09-15 00:42:09 +00:00
onHttpError={(syntheticEvent) => {
2019-09-21 00:43:28 +00:00
const { nativeEvent } = syntheticEvent;
2019-09-29 13:43:48 +00:00
console.warn(
'WebView received error status code: ',
nativeEvent.statusCode,
);
2019-09-21 00:43:28 +00:00
}}
/>
```
Function passed to `onHttpError` is called with a SyntheticEvent wrapping a nativeEvent with these properties:
```
canGoBack
canGoForward
description
loading
statusCode
target
title
url
```
> **_Note_**
> Description is only used on Android
---
2020-08-06 20:21:01 +00:00
### `onRenderProcessGone`[⬆](#props-index)<!-- Link generated with jump2header -->
Function that is invoked when the `WebView` process crashes or is killed by the OS on Android.
> **_Note_**
> Android API minimum level 26. Android Only
| Type | Required |
| -------- | -------- |
| function | No |
Example:
```jsx
< WebView
source={{ uri: 'https://reactnative.dev' }}
onRenderProcessGone={syntheticEvent => {
const { nativeEvent } = syntheticEvent;
console.warn(
'WebView Crashed: ',
nativeEvent.didCrash,
);
}}
/>
```
Function passed to `onRenderProcessGone` is called with a SyntheticEvent wrapping a nativeEvent with these properties:
```
didCrash
```
---
2020-07-24 05:21:56 +00:00
### `onMessage`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
2019-02-01 21:04:11 +00:00
Function that is invoked when the webview calls `window.ReactNativeWebView.postMessage` . Setting this property will inject this global into your webview.
2018-09-20 02:27:09 +00:00
2019-02-01 21:04:11 +00:00
`window.ReactNativeWebView.postMessage` accepts one argument, `data` , which will be available on the event object, `event.nativeEvent.data` . `data` must be a string.
2018-09-20 02:27:09 +00:00
| Type | Required |
| -------- | -------- |
| function | No |
2019-03-03 00:32:42 +00:00
To learn more, read the [Communicating between JS and Native ](Guide.md#communicating-between-js-and-native ) guide.
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `onNavigationStateChange`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Function that is invoked when the `WebView` loading starts or ends.
| Type | Required |
| -------- | -------- |
| function | No |
2019-03-01 00:36:56 +00:00
Example:
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2020-09-15 00:42:09 +00:00
onNavigationStateChange={(navState) => {
2019-03-01 00:36:56 +00:00
// Keep track of going back navigation within component
this.canGoBack = navState.canGoBack;
2019-03-20 12:35:13 +00:00
}}
/>
2019-03-01 00:36:56 +00:00
```
The `navState` object includes these properties:
2019-03-20 12:35:13 +00:00
```
canGoBack
canGoForward
loading
navigationType
target
title
url
2019-03-01 00:36:56 +00:00
```
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `onContentProcessDidTerminate`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-09-23 08:20:12 +00:00
Function that is invoked when the `WebView` content process is terminated.
2020-02-12 23:39:11 +00:00
| Type | Required | Platform |
| -------- | -------- | ----------------------- |
| function | No | iOS and macOS WKWebView |
2019-09-23 08:20:12 +00:00
Example:
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2020-09-15 00:42:09 +00:00
onContentProcessDidTerminate={(syntheticEvent) => {
2019-09-23 08:20:12 +00:00
const { nativeEvent } = syntheticEvent;
console.warn('Content process terminated, reloading', nativeEvent);
2019-09-29 13:43:48 +00:00
this.refs.webview.reload();
2019-09-23 08:20:12 +00:00
}}
/>
```
Function passed to onContentProcessDidTerminate is called with a SyntheticEvent wrapping a nativeEvent with these properties:
```
canGoBack
canGoForward
loading
target
title
url
```
---
2020-07-24 05:21:56 +00:00
### `originWhitelist`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
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://*".
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ---------------- | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| array of strings | No | iOS, Android, macOS |
2018-09-20 02:27:09 +00:00
2019-03-01 00:36:56 +00:00
Example:
```jsx
//only allow URIs that begin with https:// or git://
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2019-03-20 12:35:13 +00:00
originWhitelist={['https://*', 'git://*']}
/>
2019-03-01 00:36:56 +00:00
```
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `renderError`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Function that returns a view to show if there's an error.
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| -------- | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| function | No | iOS, Android, macOS |
2018-09-20 02:27:09 +00:00
2019-03-01 00:36:56 +00:00
Example:
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2020-09-15 00:42:09 +00:00
renderError={(errorName) => < Error name = {errorName} / > }
2019-03-20 12:35:13 +00:00
/>
2019-03-01 00:36:56 +00:00
```
2019-03-20 12:35:13 +00:00
The function passed to `renderError` will be called with the name of the error
2019-03-01 00:36:56 +00:00
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `renderLoading`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Function that returns a loading indicator. The startInLoadingState prop must be set to true in order to use this prop.
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| -------- | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| function | No | iOS, Android, macOS |
2018-09-20 02:27:09 +00:00
2019-03-01 00:36:56 +00:00
Example:
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2019-03-20 12:35:13 +00:00
startInLoadingState={true}
renderLoading={() => < Loading / > }
/>
2019-03-01 00:36:56 +00:00
```
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `scalesPageToFit`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
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` .
2019-08-30 10:04:32 +00:00
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | Android |
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `onShouldStartLoadWithRequest`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
2019-03-20 12:35:13 +00:00
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.
2018-09-20 02:27:09 +00:00
2019-02-08 11:31:17 +00:00
On Android, is not called on the first load.
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| -------- | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| function | No | iOS, Android, macOS |
2018-09-20 02:27:09 +00:00
2019-03-01 00:27:17 +00:00
Example:
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2020-09-15 00:42:09 +00:00
onShouldStartLoadWithRequest={(request) => {
2019-03-01 00:27:17 +00:00
// Only allow navigating within this website
2020-02-26 06:54:06 +00:00
return request.url.startsWith('https://reactnative.dev');
2019-03-01 00:27:17 +00:00
}}
/>
```
The `request` object includes these properties:
```
title
url
loading
target
canGoBack
canGoForward
lockIdentifier
2019-06-13 06:59:52 +00:00
mainDocumentURL (iOS only)
2019-03-01 00:27:17 +00:00
navigationType
2020-08-15 09:21:38 +00:00
isTopFrame
2019-03-01 00:27:17 +00:00
```
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `startInLoadingState`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
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.
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ---- | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| bool | No | iOS, Android, macOS |
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `style`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-01-07 13:56:48 +00:00
2019-01-18 01:26:20 +00:00
A style object that allow you to customize the `WebView` style. Please note that there are default styles (example: you need to add `flex: 0` to the style if you want to use `height` property).
2019-01-07 13:56:48 +00:00
| Type | Required |
| ----- | -------- |
| style | No |
2019-03-01 00:36:56 +00:00
Example:
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2019-03-20 12:35:13 +00:00
style={{ marginTop: 20 }}
/>
2019-03-01 00:36:56 +00:00
```
2019-01-07 13:56:48 +00:00
---
2020-07-24 05:21:56 +00:00
### `containerStyle`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-09-29 13:43:48 +00:00
A style object that allow you to customize the `WebView` container style. Please note that there are default styles (example: you need to add `flex: 0` to the style if you want to use `height` property).
| Type | Required |
| ----- | -------- |
| style | No |
Example:
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2019-09-29 13:43:48 +00:00
containerStyle={{ marginTop: 20 }}
/>
```
---
2020-07-24 05:21:56 +00:00
### `decelerationRate`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
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:
2018-10-17 13:08:52 +00:00
- normal: 0.998
- fast: 0.99 (the default for iOS web view)
2018-09-20 02:27:09 +00:00
| Type | Required | Platform |
| ------ | -------- | -------- |
| number | No | iOS |
---
2020-07-24 05:21:56 +00:00
### `domStorageEnabled`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Boolean value to control whether DOM Storage is enabled. Used only in Android.
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | Android |
---
2020-07-24 05:21:56 +00:00
### `javaScriptEnabled`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
2019-12-06 10:16:56 +00:00
Boolean value to enable JavaScript in the `WebView` . The default value is `true` .
2018-09-20 02:27:09 +00:00
2019-12-06 10:16:56 +00:00
| Type | Required |
| ---- | -------- |
| bool | No |
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `javaScriptCanOpenWindowsAutomatically`[⬆](#props-index)<!-- Link generated with jump2header -->
2020-05-28 16:54:20 +00:00
A Boolean value indicating whether JavaScript can open windows without user interaction. The default value is `false` .
| Type | Required |
| ---- | -------- |
| bool | No |
---
2020-07-24 05:21:56 +00:00
### `androidHardwareAccelerationDisabled`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-01-22 09:21:10 +00:00
2020-08-24 12:23:38 +00:00
**Deprecated.** Use the `androidLayerType` prop instead.
2019-01-22 09:21:10 +00:00
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | Android |
---
2020-08-24 12:23:38 +00:00
### `androidLayerType`[⬆](#props-index)<!-- Link generated with jump2header -->
Specifies the layer type.
Possible values for `androidLayerType` are:
- `none` (default) - The view does not have a layer.
- `software` - The view has a software layer. A software layer is backed by a bitmap and causes the view to be rendered using Android's software rendering pipeline, even if hardware acceleration is enabled.
- `hardware` - The view has a hardware layer. A hardware layer is backed by a hardware specific texture and causes the view to be rendered using Android's hardware rendering pipeline, but only if hardware acceleration is turned on for the view hierarchy.
Avoid setting both `androidLayerType` and `androidHardwareAccelerationDisabled` props at the same time, as this may cause undefined behaviour.
| Type | Required | Platform |
| ------ | -------- | -------- |
| string | No | Android |
---
2020-07-24 05:21:56 +00:00
### `mixedContentMode`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.
Possible values for `mixedContentMode` are:
2018-10-17 13:08:52 +00:00
- `never` (default) - WebView will not allow a secure origin to load content from an insecure origin.
- `always` - WebView will allow a secure origin to load content from any other origin, even if that origin is insecure.
- `compatibility` - WebView will attempt to be compatible with the approach of a modern web browser with regard to mixed content.
2018-09-20 02:27:09 +00:00
| Type | Required | Platform |
| ------ | -------- | -------- |
| string | No | Android |
---
2020-07-24 05:21:56 +00:00
### `thirdPartyCookiesEnabled`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
2019-11-04 16:30:51 +00:00
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` . For more on cookies, read the [Guide ](Guide.md#Managing-Cookies )
2018-09-20 02:27:09 +00:00
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | Android |
---
2020-07-24 05:21:56 +00:00
### `userAgent`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
2019-08-30 10:04:32 +00:00
Sets the user-agent for the `WebView` .
2018-09-20 02:27:09 +00:00
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ------ | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| string | No | iOS, Android, macOS |
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `applicationNameForUserAgent`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-05-20 22:01:22 +00:00
2019-08-30 10:04:32 +00:00
Append to the existing user-agent. Setting `userAgent` will override this.
2019-05-20 22:01:22 +00:00
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ------ | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| string | No | iOS, Android, macOS |
2019-08-02 08:46:03 +00:00
```jsx
< WebView
2020-02-26 06:54:06 +00:00
source={{ uri: 'https://reactnative.dev' }}
2019-08-30 10:04:32 +00:00
applicationNameForUserAgent={'DemoApp/1.1.0'}
2019-08-02 08:46:03 +00:00
/>
// Resulting User-Agent will look like:
// Mozilla/5.0 (Linux; Android 8.1.0; Android SDK built for x86 Build/OSM1.180201.021; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36 DemoApp/1.1.0
// Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 DemoApp/1.1.0
```
2019-05-20 22:01:22 +00:00
2020-07-24 05:21:56 +00:00
### `allowsFullscreenVideo`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-05-16 22:22:08 +00:00
Boolean that determines whether videos are allowed to be played in fullscreen. The default value is `false` .
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | Android |
---
2020-07-24 05:21:56 +00:00
### `allowsInlineMediaPlayback`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Boolean that determines whether HTML5 videos play inline or use the native full-screen controller. The default value is `false` .
> **NOTE**
>
> 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.
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | iOS |
---
2020-07-24 05:21:56 +00:00
### `bounces`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Boolean value that determines whether the web view bounces when it reaches the edge of the content. The default value is `true` .
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | iOS |
---
2020-07-24 05:21:56 +00:00
### `overScrollMode`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-10-17 14:48:19 +00:00
Specifies the over scroll mode.
Possible values for `overScrollMode` are:
- `always` (default) - Always allow a user to over-scroll this view, provided it is a view that can scroll.
- `content` - Allow a user to over-scroll this view only if the content is large enough to meaningfully scroll, provided it is a view that can scroll.
- `never` - Never allow a user to over-scroll this view.
| Type | Required | Platform |
| ------ | -------- | -------- |
| string | No | Android |
---
2020-07-24 05:21:56 +00:00
### `contentInset`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
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}.
| Type | Required | Platform |
| ------------------------------------------------------------------ | -------- | -------- |
| object: {top: number, left: number, bottom: number, right: number} | No | iOS |
---
2020-07-24 05:21:56 +00:00
### `contentInsetAdjustmentBehavior`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-08-09 08:55:35 +00:00
This property specifies how the safe area insets are used to modify the content area of the scroll view. The default value of this property is "never". Available on iOS 11 and later. Defaults to `never` .
Possible values:
- `automatic`
- `scrollableAxes`
- `never`
- `always`
| Type | Required | Platform |
| ------ | -------- | -------- |
| string | No | iOS |
---
2020-08-15 03:16:54 +00:00
### `contentMode`[⬆](#props-index)<!-- Link generated with jump2header -->
Controls the type of content to load. Available on iOS 13 and later. Defaults to `recommended` , which loads mobile content on iPhone & iPad Mini but desktop content on larger iPads.
See [Introducing Desktop-class Browsing on iPad ](https://developer.apple.com/videos/play/wwdc2019/203/ ) for more.
Possible values:
- `recommended`
- `mobile`
- `desktop`
| Type | Required | Platform |
| ------ | -------- | -------- |
| string | No | iOS |
---
2020-07-24 05:21:56 +00:00
### `dataDetectorTypes`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Determines the types of data converted to clickable URLs in the web view's content. By default only phone numbers are detected.
You can provide one type or an array of many types.
Possible values for `dataDetectorTypes` are:
2018-10-17 13:08:52 +00:00
- `phoneNumber`
- `link`
- `address`
- `calendarEvent`
- `none`
- `all`
- `trackingNumber`
- `flightNumber`
- `lookupSuggestion`
2018-09-20 02:27:09 +00:00
| Type | Required | Platform |
| ---------------- | -------- | -------- |
| string, or array | No | iOS |
---
2020-07-24 05:21:56 +00:00
### `scrollEnabled`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
2019-02-28 21:01:42 +00:00
Boolean value that determines whether scrolling is enabled in the `WebView` . The default value is `true` . Setting this to `false` will prevent the webview from moving the document body when the keyboard appears over an input.
2018-09-20 02:27:09 +00:00
2020-02-12 23:39:11 +00:00
| Type | Required | Platform |
| ---- | -------- | ------------- |
| bool | No | iOS and macOS |
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `directionalLockEnabled`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-03-07 09:27:29 +00:00
A Boolean value that determines whether scrolling is disabled in a particular direction.
The default value is `true` .
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | iOS |
---
2020-07-24 05:21:56 +00:00
### `showsHorizontalScrollIndicator`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-02-12 13:47:24 +00:00
Boolean value that determines whether a horizontal scroll indicator is shown in the `WebView` . The default value is `true` .
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ---- | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| bool | No | iOS, Android, macOS |
2019-02-12 13:47:24 +00:00
---
2020-07-24 05:21:56 +00:00
### `showsVerticalScrollIndicator`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-02-12 13:47:24 +00:00
Boolean value that determines whether a vertical scroll indicator is shown in the `WebView` . The default value is `true` .
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ---- | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| bool | No | iOS, Android, macOS |
2019-02-12 13:47:24 +00:00
---
2020-07-24 05:21:56 +00:00
### `geolocationEnabled`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
Set whether Geolocation is enabled in the `WebView` . The default value is `false` . Used only in Android.
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | Android |
---
2020-07-24 05:21:56 +00:00
### `allowFileAccessFromFileURLs`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-09-29 13:50:39 +00:00
2019-11-04 16:30:51 +00:00
Boolean that sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from other file scheme URLs. The default value is `false` .
2019-09-29 13:50:39 +00:00
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ---- | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| bool | No | iOS, Android, macOS |
2019-09-29 13:50:39 +00:00
---
2020-07-24 05:21:56 +00:00
### `allowUniversalAccessFromFileURLs`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
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` .
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | Android |
---
2020-07-24 05:21:56 +00:00
### `allowingReadAccessToURL`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-08-29 14:53:09 +00:00
2019-08-30 10:04:32 +00:00
A String value that indicates which URLs the WebView's file can then reference in scripts, AJAX requests, and CSS imports. This is only used in for WebViews that are loaded with a source.uri set to a `'file://'` URL. If not provided, the default is to only allow read access to the URL provided in source.uri itself.
2018-09-20 02:27:09 +00:00
2020-02-12 23:39:11 +00:00
| Type | Required | Platform |
| ------ | -------- | ------------- |
| string | No | iOS and macOS |
2018-09-20 02:27:09 +00:00
---
2020-07-24 05:21:56 +00:00
### `url`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
**Deprecated.** Use the `source` prop instead.
| Type | Required |
| ------ | -------- |
| string | No |
---
2020-07-24 05:21:56 +00:00
### `html`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
**Deprecated.** Use the `source` prop instead.
| Type | Required |
| ------ | -------- |
| string | No |
2018-10-17 14:59:19 +00:00
---
2020-07-24 05:21:56 +00:00
### `keyboardDisplayRequiresUserAction`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-04-29 15:46:07 +00:00
2019-08-30 10:04:32 +00:00
If false, web content can programmatically display the keyboard. The default value is `true` .
2019-04-29 15:46:07 +00:00
| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | iOS |
---
2020-07-24 05:21:56 +00:00
### `hideKeyboardAccessoryView`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-10-17 14:59:19 +00:00
2019-08-30 10:04:32 +00:00
If true, this will hide the keyboard accessory view (< > and Done).
2018-10-17 14:59:19 +00:00
| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | iOS |
2018-10-21 21:12:59 +00:00
---
2020-07-24 05:21:56 +00:00
### `allowsBackForwardNavigationGestures`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-10-21 21:12:59 +00:00
2019-08-30 10:04:32 +00:00
If true, this will be able horizontal swipe gestures. The default value is `false` .
2018-10-21 21:12:59 +00:00
2020-02-26 06:54:06 +00:00
| Type | Required | Platform |
| ------- | -------- | ------------- |
| boolean | No | iOS and macOS |
2018-10-21 21:12:59 +00:00
2018-11-19 10:25:28 +00:00
---
2020-07-24 05:21:56 +00:00
### `incognito`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-01-11 13:59:03 +00:00
Does not store any data within the lifetime of the WebView.
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| ------- | -------- | ------------------- |
2020-03-17 02:30:25 +00:00
| boolean | No | iOS, Android, macOS |
2019-01-11 13:59:03 +00:00
---
2020-07-24 05:21:56 +00:00
### `allowFileAccess`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-11-19 10:18:49 +00:00
If true, this will allow access to the file system via `file://` URI's. The default value is `false` .
| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | Android |
2018-11-19 10:25:28 +00:00
---
2020-07-24 05:21:56 +00:00
### `saveFormDataDisabled`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-11-19 10:18:49 +00:00
Sets whether the WebView should disable saving form data. The default value is `false` . This function does not have any effect from Android API level 26 onwards as there is an Autofill feature which stores form data.
| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | Android |
2018-10-21 21:12:59 +00:00
2018-11-22 12:58:07 +00:00
---
2020-07-24 05:21:56 +00:00
### `cacheEnabled`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-01-30 09:32:46 +00:00
2019-08-30 10:04:32 +00:00
Sets whether WebView should use browser caching.
2019-01-30 09:32:46 +00:00
2020-09-15 00:42:09 +00:00
| Type | Required | Default | Platform |
| ------- | -------- | ------- | ------------------- |
2020-03-17 02:30:25 +00:00
| boolean | No | true | iOS, Android, macOS |
2019-01-30 09:32:46 +00:00
---
2020-07-24 05:21:56 +00:00
### `cacheMode`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-09-29 13:45:20 +00:00
Overrides the way the cache is used. The way the cache is used is based on the navigation type. For a normal page load, the cache is checked and content is re-validated as needed. When navigating back, content is not revalidated, instead the content is just retrieved from the cache. This property allows the client to override this behavior.
Possible values are:
2019-11-04 16:30:51 +00:00
2019-09-29 13:45:20 +00:00
- `LOAD_DEFAULT` - Default cache usage mode. If the navigation type doesn't impose any specific behavior, use cached resources when they are available and not expired, otherwise load resources from the network.
- `LOAD_CACHE_ELSE_NETWORK` - Use cached resources when they are available, even if they have expired. Otherwise load resources from the network.
- `LOAD_NO_CACHE` - Don't use the cache, load from the network.
2019-11-04 16:30:51 +00:00
- `LOAD_CACHE_ONLY` - Don't use the network, load from the cache.
| Type | Required | Default | Platform |
| ------ | -------- | ------------ | -------- |
| string | No | LOAD_DEFAULT | Android |
2019-09-29 13:45:20 +00:00
---
2020-07-24 05:21:56 +00:00
### `pagingEnabled`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-11-22 12:58:07 +00:00
If the value of this property is true, the scroll view stops on multiples of the scroll view’ s bounds when the user scrolls. The default value is false.
| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | iOS |
2018-11-25 10:17:28 +00:00
---
2020-07-24 05:21:56 +00:00
### `allowsLinkPreview`[⬆](#props-index)<!-- Link generated with jump2header -->
2018-11-25 10:17:28 +00:00
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.
2020-02-26 06:54:06 +00:00
| Type | Required | Platform |
| ------- | -------- | ------------- |
| boolean | No | iOS and macOS |
2018-11-25 10:17:28 +00:00
2019-04-15 08:19:10 +00:00
---
2020-07-24 05:21:56 +00:00
### `sharedCookiesEnabled`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-04-15 08:19:10 +00:00
2019-11-04 16:30:51 +00:00
Set `true` if shared cookies from `[NSHTTPCookieStorage sharedHTTPCookieStorage]` should used for every load request in the WebView. The default value is `false` . For more on cookies, read the [Guide ](Guide.md#Managing-Cookies )
2019-04-15 08:19:10 +00:00
2020-02-26 06:54:06 +00:00
| Type | Required | Platform |
| ------- | -------- | ------------- |
| boolean | No | iOS and macOS |
2019-04-15 08:19:10 +00:00
2019-07-02 15:38:00 +00:00
---
2020-07-24 05:21:56 +00:00
### `textZoom`[⬆](#props-index)<!-- Link generated with jump2header -->
2019-07-02 15:38:00 +00:00
If the user has set a custom font size in the Android system, an undesirable scale of the site interface in WebView occurs.
When setting the standard textZoom (100) parameter size, this undesirable effect disappears.
| Type | Required | Platform |
| ------ | -------- | -------- |
| number | No | Android |
Example:
`<WebView textZoom={100} />`
2020-08-17 10:07:36 +00:00
---
### `pullToRefreshEnabled`[⬆](#props-index)<!-- Link generated with jump2header -->
Boolean value that determines whether a pull to refresh gesture is available in the `WebView` . The default value is `false` . If `true` , sets `bounces` automatically to `true` .
| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | iOS |
2020-07-24 05:21:56 +00:00
### `ignoreSilentHardwareSwitch`[⬆](#props-index)<!-- Link generated with jump2header -->
2020-04-13 15:54:47 +00:00
(ios only)
When set to true the hardware silent switch is ignored. Default: `false`
| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | iOS |
2020-07-24 05:21:56 +00:00
### `onFileDownload`[⬆](#props-index)<!-- Link generated with jump2header -->
2020-04-29 16:09:22 +00:00
This property is iOS-only.
Function that is invoked when the client needs to download a file.
iOS 13+ only: If the webview navigates to a URL that results in an HTTP
response with a Content-Disposition header 'attachment...', then
this will be called.
iOS 8+: If the MIME type indicates that the content is not renderable by the
webview, that will also cause this to be called. On iOS versions before 13,
this is the only condition that will cause this function to be called.
The application will need to provide its own code to actually download
the file.
If not provided, the default is to let the webview try to render the file.
Example:
2020-09-15 00:42:09 +00:00
2020-04-29 16:09:22 +00:00
```jsx
< WebView
source={{ uri: 'https://reactnative.dev' }}
2020-09-15 00:42:09 +00:00
onFileDownload={({ nativeEvent: { downloadUrl } }) => {
2020-04-29 16:09:22 +00:00
// You use downloadUrl which is a string to download files however you want.
}}
2020-09-15 00:42:09 +00:00
/>
2020-04-29 16:09:22 +00:00
```
2020-09-15 00:42:09 +00:00
| Type | Required | Platform |
| -------- | -------- | -------- |
| function | No | iOS |
---
### `autoManageStatusBarEnabled`
If set to `true` , the status bar will be automatically hidden/shown by WebView, specifically when full screen video is being watched. If `false` , WebView will not manage the status bar at all. The default value is `true` .
2020-04-29 16:09:22 +00:00
| Type | Required | Platform |
| ------- | -------- | -------- |
2020-09-15 00:42:09 +00:00
| boolean | No | iOS |
Example:
```javascript
< WebView autoManageStatusBarEnabled = {false} / >
```
2020-04-29 16:09:22 +00:00
2018-09-20 02:27:09 +00:00
## Methods
2020-07-24 05:21:56 +00:00
### `extraNativeComponentConfig()`[⬆](#methods-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
```javascript
static extraNativeComponentConfig()
```
2020-07-24 05:21:56 +00:00
### `goForward()`[⬆](#methods-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
```javascript
goForward();
```
Go forward one page in the web view's history.
2020-07-24 05:21:56 +00:00
### `goBack()`[⬆](#methods-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
```javascript
goBack();
```
Go back one page in the web view's history.
2020-07-24 05:21:56 +00:00
### `reload()`[⬆](#methods-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
```javascript
reload();
```
Reloads the current page.
2020-07-24 05:21:56 +00:00
### `stopLoading()`[⬆](#methods-index)<!-- Link generated with jump2header -->
2018-09-20 02:27:09 +00:00
```javascript
stopLoading();
```
Stop loading the current page.
2020-07-24 05:21:56 +00:00
### `injectJavaScript(str)`[⬆](#methods-index)<!-- Link generated with jump2header -->
2018-10-30 13:48:10 +00:00
```javascript
2018-11-19 10:25:28 +00:00
injectJavaScript('... javascript string ...');
2018-10-30 13:48:10 +00:00
```
Executes the JavaScript string.
2019-03-03 00:32:42 +00:00
To learn more, read the [Communicating between JS and Native ](Guide.md#communicating-between-js-and-native ) guide.
2020-07-24 05:21:56 +00:00
### `requestFocus()`[⬆](#methods-index)<!-- Link generated with jump2header -->
2019-11-13 09:43:25 +00:00
```javascript
requestFocus();
```
Request the webView to ask for focus. (People working on TV apps might want having a look at this!)
2020-07-24 05:21:56 +00:00
### `postMessage(str)`[⬆](#methods-index)<!-- Link generated with jump2header -->
2020-05-29 20:19:11 +00:00
```javascript
postMessage('message');
```
2020-09-15 00:42:09 +00:00
2020-05-29 20:19:11 +00:00
Post a message to WebView, handled by [`onMessage` ](Reference.md#onmessage ).
2020-07-24 05:21:56 +00:00
### `clearFormData()`[⬆](#methods-index)<!-- Link generated with jump2header -->
2020-02-26 06:54:06 +00:00
2019-11-12 09:09:16 +00:00
(android only)
```javascript
clearFormData();
```
2020-02-26 06:54:06 +00:00
Removes the autocomplete popup from the currently focused form field, if present. [developer.android.com reference ](<https://developer.android.com/reference/android/webkit/WebView.html#clearFormData( )>)
2019-11-12 09:09:16 +00:00
2020-07-24 05:21:56 +00:00
### `clearCache(bool)`[⬆](#methods-index)<!-- Link generated with jump2header -->
2020-02-26 06:54:06 +00:00
2019-11-12 09:09:16 +00:00
(android only)
2020-02-26 06:54:06 +00:00
2019-11-12 09:09:16 +00:00
```javascript
clearCache(true);
```
2020-02-26 06:54:06 +00:00
Clears the resource cache. Note that the cache is per-application, so this will clear the cache for all WebViews used. [developer.android.com reference ](<https://developer.android.com/reference/android/webkit/WebView.html#clearCache(boolean )>)
2019-11-12 09:09:16 +00:00
2020-07-24 05:21:56 +00:00
### `clearHistory()`[⬆](#methods-index)<!-- Link generated with jump2header -->
2020-02-26 06:54:06 +00:00
2019-11-12 09:09:16 +00:00
(android only)
2020-02-26 06:54:06 +00:00
2019-11-12 09:09:16 +00:00
```javascript
clearHistory();
```
2020-02-26 06:54:06 +00:00
Tells this WebView to clear its internal back/forward list. [developer.android.com reference ](<https://developer.android.com/reference/android/webkit/WebView.html#clearHistory( )>)
2019-11-12 09:09:16 +00:00
2018-09-20 02:27:09 +00:00
## Other Docs
Also check out our [Getting Started Guide ](Getting-Started.md ) and [In-Depth Guide ](Guide.md ).