Browse Source

Merge pull request #56 from react-native-community/docs-folder

Migrate Documentation
Jamon Holmgren 6 years ago
parent
commit
861e5538f5
No account linked to committer's email address
6 changed files with 1094 additions and 4 deletions
  1. 4
    4
      README.md
  2. 255
    0
      docs/Custom-Android.md
  3. 229
    0
      docs/Custom-iOS.md
  4. 59
    0
      docs/Getting-Started.md
  5. 52
    0
      docs/Guide.md
  6. 495
    0
      docs/Reference.md

+ 4
- 4
README.md View File

10
 * [x] Android
10
 * [x] Android
11
 * [ ] Windows 10 (coming soon)
11
 * [ ] Windows 10 (coming soon)
12
 
12
 
13
-## Installation
13
+## Getting Started
14
 
14
 
15
 *Note: this is currently a work-in-progress and not yet published to NPM.*
15
 *Note: this is currently a work-in-progress and not yet published to NPM.*
16
 
16
 
19
 $ react-native link react-native-webview
19
 $ react-native link react-native-webview
20
 ```
20
 ```
21
 
21
 
22
+Read our [Getting Started Guide](./docs/Getting-Started.md) for more.
23
+
22
 ## Usage
24
 ## Usage
23
 
25
 
24
 Import the `WebView` component from `react-native-webview` and use it like so:
26
 Import the `WebView` component from `react-native-webview` and use it like so:
41
 }
43
 }
42
 ```
44
 ```
43
 
45
 
44
-Additional properties are supported and will be added here; for now, refer to the previous React Native WebView documentation for more.
45
-
46
-[https://facebook.github.io/react-native/docs/webview](https://facebook.github.io/react-native/docs/webview)
46
+For more, read the [API Reference](./docs/Reference.md) and [Guide](./docs/Guide.md).
47
 
47
 
48
 ## Migrate from React Native core WebView to React Native WebView
48
 ## Migrate from React Native core WebView to React Native WebView
49
 
49
 

+ 255
- 0
docs/Custom-Android.md View File

1
+**NOTE: This document was imported from [the original WebView documentation](https://github.com/facebook/react-native-website/blob/7d3e9e120e38a7ba928f6b173eb98f88b6f2f85f/docs/custom-webview-android.md). While it may prove useful, it has not been adapted to React Native WebView yet.**
2
+
3
+While the built-in web view has a lot of features, it is not possible to handle every use-case in React Native. You can, however, extend the web view with native code without forking React Native or duplicating all the existing web view code.
4
+
5
+Before you do this, you should be familiar with the concepts in [native UI components](native-components-android). You should also familiarise yourself with the [native code for web views](https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java), as you will have to use this as a reference when implementing new features—although a deep understanding is not required.
6
+
7
+## Native Code
8
+
9
+To get started, you'll need to create a subclass of `ReactWebViewManager`, `ReactWebView`, and `ReactWebViewClient`. In your view manager, you'll then need to override:
10
+
11
+* `createReactWebViewInstance`
12
+* `getName`
13
+* `addEventEmitters`
14
+
15
+```java
16
+@ReactModule(name = CustomWebViewManager.REACT_CLASS)
17
+public class CustomWebViewManager extends ReactWebViewManager {
18
+  /* This name must match what we're referring to in JS */
19
+  protected static final String REACT_CLASS = "RCTCustomWebView";
20
+
21
+  protected static class CustomWebViewClient extends ReactWebViewClient { }
22
+
23
+  protected static class CustomWebView extends ReactWebView {
24
+    public CustomWebView(ThemedReactContext reactContext) {
25
+      super(reactContext);
26
+    }
27
+  }
28
+
29
+  @Override
30
+  protected ReactWebView createReactWebViewInstance(ThemedReactContext reactContext) {
31
+    return new CustomWebView(reactContext);
32
+  }
33
+
34
+  @Override
35
+  public String getName() {
36
+    return REACT_CLASS;
37
+  }
38
+
39
+  @Override
40
+  protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
41
+    view.setWebViewClient(new CustomWebViewClient());
42
+  }
43
+}
44
+```
45
+
46
+You'll need to follow the usual steps to [register the module](native-modules-android.md#register-the-module).
47
+
48
+### Adding New Properties
49
+
50
+To add a new property, you'll need to add it to `CustomWebView`, and then expose it in `CustomWebViewManager`.
51
+
52
+```java
53
+public class CustomWebViewManager extends ReactWebViewManager {
54
+  ...
55
+
56
+  protected static class CustomWebView extends ReactWebView {
57
+    public CustomWebView(ThemedReactContext reactContext) {
58
+      super(reactContext);
59
+    }
60
+
61
+    protected @Nullable String mFinalUrl;
62
+
63
+    public void setFinalUrl(String url) {
64
+        mFinalUrl = url;
65
+    }
66
+
67
+    public String getFinalUrl() {
68
+        return mFinalUrl;
69
+    }
70
+  }
71
+
72
+  ...
73
+
74
+  @ReactProp(name = "finalUrl")
75
+  public void setFinalUrl(WebView view, String url) {
76
+    ((CustomWebView) view).setFinalUrl(url);
77
+  }
78
+}
79
+```
80
+
81
+### Adding New Events
82
+
83
+For events, you'll first need to make create event subclass.
84
+
85
+```java
86
+// NavigationCompletedEvent.java
87
+public class NavigationCompletedEvent extends Event<NavigationCompletedEvent> {
88
+  private WritableMap mParams;
89
+
90
+  public NavigationCompletedEvent(int viewTag, WritableMap params) {
91
+    super(viewTag);
92
+    this.mParams = params;
93
+  }
94
+
95
+  @Override
96
+  public String getEventName() {
97
+    return "navigationCompleted";
98
+  }
99
+
100
+  @Override
101
+  public void dispatch(RCTEventEmitter rctEventEmitter) {
102
+    init(getViewTag());
103
+    rctEventEmitter.receiveEvent(getViewTag(), getEventName(), mParams);
104
+  }
105
+}
106
+```
107
+
108
+You can trigger the event in your web view client. You can hook existing handlers if your events are based on them.
109
+
110
+You should refer to [ReactWebViewManager.java](https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java) in the React Native codebase to see what handlers are available and how they are implemented. You can extend any methods here to provide extra functionality.
111
+
112
+```java
113
+public class NavigationCompletedEvent extends Event<NavigationCompletedEvent> {
114
+  private WritableMap mParams;
115
+
116
+  public NavigationCompletedEvent(int viewTag, WritableMap params) {
117
+    super(viewTag);
118
+    this.mParams = params;
119
+  }
120
+
121
+  @Override
122
+  public String getEventName() {
123
+    return "navigationCompleted";
124
+  }
125
+
126
+  @Override
127
+  public void dispatch(RCTEventEmitter rctEventEmitter) {
128
+    init(getViewTag());
129
+    rctEventEmitter.receiveEvent(getViewTag(), getEventName(), mParams);
130
+  }
131
+}
132
+
133
+// CustomWebViewManager.java
134
+protected static class CustomWebViewClient extends ReactWebViewClient {
135
+  @Override
136
+  public boolean shouldOverrideUrlLoading(WebView view, String url) {
137
+    boolean shouldOverride = super.shouldOverrideUrlLoading(view, url);
138
+    String finalUrl = ((CustomWebView) view).getFinalUrl();
139
+
140
+    if (!shouldOverride && url != null && finalUrl != null && new String(url).equals(finalUrl)) {
141
+      final WritableMap params = Arguments.createMap();
142
+      dispatchEvent(view, new NavigationCompletedEvent(view.getId(), params));
143
+    }
144
+
145
+    return shouldOverride;
146
+  }
147
+}
148
+```
149
+
150
+Finally, you'll need to expose the events in `CustomWebViewManager` through `getExportedCustomDirectEventTypeConstants`. Note that currently, the default implementation returns `null`, but this may change in the future.
151
+
152
+```java
153
+public class CustomWebViewManager extends ReactWebViewManager {
154
+  ...
155
+
156
+  @Override
157
+  public @Nullable
158
+  Map getExportedCustomDirectEventTypeConstants() {
159
+    Map<String, Object> export = super.getExportedCustomDirectEventTypeConstants();
160
+    if (export == null) {
161
+      export = MapBuilder.newHashMap();
162
+    }
163
+    export.put("navigationCompleted", MapBuilder.of("registrationName", "onNavigationCompleted"));
164
+    return export;
165
+  }
166
+}
167
+```
168
+
169
+## JavaScript Interface
170
+
171
+To use your custom web view, you'll need to create a class for it. Your class must:
172
+
173
+* Export all the prop types from `WebView.propTypes`
174
+* Return a `WebView` component with the prop `nativeConfig.component` set to your native component (see below)
175
+
176
+To get your native component, you must use `requireNativeComponent`: the same as for regular custom components. However, you must pass in an extra third argument, `WebView.extraNativeComponentConfig`. This third argument contains prop types that are only required for native code.
177
+
178
+```javascript
179
+import React, {Component, PropTypes} from 'react';
180
+import {WebView, requireNativeComponent} from 'react-native';
181
+
182
+export default class CustomWebView extends Component {
183
+  static propTypes = WebView.propTypes;
184
+
185
+  render() {
186
+    return (
187
+      <WebView {...this.props} nativeConfig={{component: RCTCustomWebView}} />
188
+    );
189
+  }
190
+}
191
+
192
+const RCTCustomWebView = requireNativeComponent(
193
+  'RCTCustomWebView',
194
+  CustomWebView,
195
+  WebView.extraNativeComponentConfig
196
+);
197
+```
198
+
199
+If you want to add custom props to your native component, you can use `nativeConfig.props` on the web view.
200
+
201
+For events, the event handler must always be set to a function. This means it isn't safe to use the event handler directly from `this.props`, as the user might not have provided one. The standard approach is to create a event handler in your class, and then invoking the event handler given in `this.props` if it exists.
202
+
203
+If you are unsure how something should be implemented from the JS side, look at [WebView.android.js](https://github.com/facebook/react-native/blob/master/Libraries/Components/WebView/WebView.android.js) in the React Native source.
204
+
205
+```javascript
206
+export default class CustomWebView extends Component {
207
+  static propTypes = {
208
+    ...WebView.propTypes,
209
+    finalUrl: PropTypes.string,
210
+    onNavigationCompleted: PropTypes.func,
211
+  };
212
+
213
+  static defaultProps = {
214
+    finalUrl: 'about:blank',
215
+  };
216
+
217
+  _onNavigationCompleted = (event) => {
218
+    const {onNavigationCompleted} = this.props;
219
+    onNavigationCompleted && onNavigationCompleted(event);
220
+  };
221
+
222
+  render() {
223
+    return (
224
+      <WebView
225
+        {...this.props}
226
+        nativeConfig={{
227
+          component: RCTCustomWebView,
228
+          props: {
229
+            finalUrl: this.props.finalUrl,
230
+            onNavigationCompleted: this._onNavigationCompleted,
231
+          },
232
+        }}
233
+      />
234
+    );
235
+  }
236
+}
237
+```
238
+
239
+Just like for regular native components, you must provide all your prop types in the component to have them forwarded on to the native component. However, if you have some prop types that are only used internally in component, you can add them to the `nativeOnly` property of the third argument previously mentioned. For event handlers, you have to use the value `true` instead of a regular prop type.
240
+
241
+For example, if you wanted to add an internal event handler called `onScrollToBottom`, you would use,
242
+
243
+```javascript
244
+const RCTCustomWebView = requireNativeComponent(
245
+  'RCTCustomWebView',
246
+  CustomWebView,
247
+  {
248
+    ...WebView.extraNativeComponentConfig,
249
+    nativeOnly: {
250
+      ...WebView.extraNativeComponentConfig.nativeOnly,
251
+      onScrollToBottom: true,
252
+    },
253
+  }
254
+);
255
+```

+ 229
- 0
docs/Custom-iOS.md View File

1
+**NOTE: This document was imported from [the original WebView documentation](https://github.com/facebook/react-native-website/blob/7d3e9e120e38a7ba928f6b173eb98f88b6f2f85f/docs/custom-webview-ios.md). While it may prove useful, it has not been adapted to React Native WebView yet.**
2
+
3
+While the built-in web view has a lot of features, it is not possible to handle every use-case in React Native. You can, however, extend the web view with native code without forking React Native or duplicating all the existing web view code.
4
+
5
+Before you do this, you should be familiar with the concepts in [native UI components](native-components-ios). You should also familiarise yourself with the [native code for web views](https://github.com/facebook/react-native/blob/master/React/Views/RCTWebViewManager.m), as you will have to use this as a reference when implementing new features—although a deep understanding is not required.
6
+
7
+## Native Code
8
+
9
+Like for regular native components, you need a view manager and an web view.
10
+
11
+For the view, you'll need to make a subclass of `RCTWebView`.
12
+
13
+```objc
14
+// RCTCustomWebView.h
15
+#import <React/RCTWebView.h>
16
+
17
+@interface RCTCustomWebView : RCTWebView
18
+
19
+@end
20
+
21
+// RCTCustomWebView.m
22
+#import "RCTCustomWebView.h"
23
+
24
+@interface RCTCustomWebView ()
25
+
26
+@end
27
+
28
+@implementation RCTCustomWebView { }
29
+
30
+@end
31
+```
32
+
33
+For the view manager, you need to make a subclass `RCTWebViewManager`. You must still include:
34
+
35
+* `(UIView *)view` that returns your custom view
36
+* The `RCT_EXPORT_MODULE()` tag
37
+
38
+```objc
39
+// RCTCustomWebViewManager.h
40
+#import <React/RCTWebViewManager.h>
41
+
42
+@interface RCTCustomWebViewManager : RCTWebViewManager
43
+
44
+@end
45
+
46
+// RCTCustomWebViewManager.m
47
+#import "RCTCustomWebViewManager.h"
48
+#import "RCTCustomWebView.h"
49
+
50
+@interface RCTCustomWebViewManager () <RCTWebViewDelegate>
51
+
52
+@end
53
+
54
+@implementation RCTCustomWebViewManager { }
55
+
56
+RCT_EXPORT_MODULE()
57
+
58
+- (UIView *)view
59
+{
60
+  RCTCustomWebView *webView = [RCTCustomWebView new];
61
+  webView.delegate = self;
62
+  return webView;
63
+}
64
+
65
+@end
66
+```
67
+
68
+### Adding New Events and Properties
69
+
70
+Adding new properties and events is the same as regular UI components. For properties, you define an `@property` in the header. For events, you define a `RCTDirectEventBlock` in the view's `@interface`.
71
+
72
+```objc
73
+// RCTCustomWebView.h
74
+@property (nonatomic, copy) NSString *finalUrl;
75
+
76
+// RCTCustomWebView.m
77
+@interface RCTCustomWebView ()
78
+
79
+@property (nonatomic, copy) RCTDirectEventBlock onNavigationCompleted;
80
+
81
+@end
82
+```
83
+
84
+Then expose it in the view manager's `@implementation`.
85
+
86
+```objc
87
+// RCTCustomWebViewManager.m
88
+RCT_EXPORT_VIEW_PROPERTY(onNavigationCompleted, RCTDirectEventBlock)
89
+RCT_EXPORT_VIEW_PROPERTY(finalUrl, NSString)
90
+```
91
+
92
+### Extending Existing Events
93
+
94
+You should refer to [RCTWebView.m](https://github.com/facebook/react-native/blob/master/React/Views/RCTWebView.m) in the React Native codebase to see what handlers are available and how they are implemented. You can extend any methods here to provide extra functionality.
95
+
96
+By default, most methods aren't exposed from RCTWebView. If you need to expose them, you need to create an [Objective C category](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html), and then expose all the methods you need to use.
97
+
98
+```objc
99
+// RCTWebView+Custom.h
100
+#import <React/RCTWebView.h>
101
+
102
+@interface RCTWebView (Custom)
103
+- (BOOL)webView:(__unused UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
104
+- (NSMutableDictionary<NSString *, id> *)baseEvent;
105
+@end
106
+```
107
+
108
+Once these are exposed, you can reference them in your custom web view class.
109
+
110
+```objc
111
+// RCTCustomWebView.m
112
+
113
+// Remember to import the category file.
114
+#import "RCTWebView+Custom.h"
115
+
116
+- (BOOL)webView:(__unused UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
117
+ navigationType:(UIWebViewNavigationType)navigationType
118
+{
119
+  BOOL allowed = [super webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
120
+
121
+  if (allowed) {
122
+    NSString* url = request.URL.absoluteString;
123
+    if (url && [url isEqualToString:_finalUrl]) {
124
+      if (_onNavigationCompleted) {
125
+        NSMutableDictionary<NSString *, id> *event = [self baseEvent];
126
+        _onNavigationCompleted(event);
127
+      }
128
+    }
129
+  }
130
+
131
+  return allowed;
132
+}
133
+```
134
+
135
+## JavaScript Interface
136
+
137
+To use your custom web view, you'll need to create a class for it. Your class must:
138
+
139
+* Export all the prop types from `WebView.propTypes`
140
+* Return a `WebView` component with the prop `nativeConfig.component` set to your native component (see below)
141
+
142
+To get your native component, you must use `requireNativeComponent`: the same as for regular custom components. However, you must pass in an extra third argument, `WebView.extraNativeComponentConfig`. This third argument contains prop types that are only required for native code.
143
+
144
+```javascript
145
+import React, {Component, PropTypes} from 'react';
146
+import {WebView, requireNativeComponent, NativeModules} from 'react-native';
147
+const {CustomWebViewManager} = NativeModules;
148
+
149
+export default class CustomWebView extends Component {
150
+  static propTypes = WebView.propTypes;
151
+
152
+  render() {
153
+    return (
154
+      <WebView
155
+        {...this.props}
156
+        nativeConfig={{
157
+          component: RCTCustomWebView,
158
+          viewManager: CustomWebViewManager,
159
+        }}
160
+      />
161
+    );
162
+  }
163
+}
164
+
165
+const RCTCustomWebView = requireNativeComponent(
166
+  'RCTCustomWebView',
167
+  CustomWebView,
168
+  WebView.extraNativeComponentConfig
169
+);
170
+```
171
+
172
+If you want to add custom props to your native component, you can use `nativeConfig.props` on the web view. For iOS, you should also set the `nativeConfig.viewManager` prop with your custom WebView ViewManager as in the example above.
173
+
174
+For events, the event handler must always be set to a function. This means it isn't safe to use the event handler directly from `this.props`, as the user might not have provided one. The standard approach is to create a event handler in your class, and then invoking the event handler given in `this.props` if it exists.
175
+
176
+If you are unsure how something should be implemented from the JS side, look at [WebView.ios.js](https://github.com/facebook/react-native/blob/master/Libraries/Components/WebView/WebView.ios.js) in the React Native source.
177
+
178
+```javascript
179
+export default class CustomWebView extends Component {
180
+  static propTypes = {
181
+    ...WebView.propTypes,
182
+    finalUrl: PropTypes.string,
183
+    onNavigationCompleted: PropTypes.func,
184
+  };
185
+
186
+  static defaultProps = {
187
+    finalUrl: 'about:blank',
188
+  };
189
+
190
+  _onNavigationCompleted = (event) => {
191
+    const {onNavigationCompleted} = this.props;
192
+    onNavigationCompleted && onNavigationCompleted(event);
193
+  };
194
+
195
+  render() {
196
+    return (
197
+      <WebView
198
+        {...this.props}
199
+        nativeConfig={{
200
+          component: RCTCustomWebView,
201
+          props: {
202
+            finalUrl: this.props.finalUrl,
203
+            onNavigationCompleted: this._onNavigationCompleted,
204
+          },
205
+          viewManager: CustomWebViewManager,
206
+        }}
207
+      />
208
+    );
209
+  }
210
+}
211
+```
212
+
213
+Just like for regular native components, you must provide all your prop types in the component to have them forwarded on to the native component. However, if you have some prop types that are only used internally in component, you can add them to the `nativeOnly` property of the third argument previously mentioned. For event handlers, you have to use the value `true` instead of a regular prop type.
214
+
215
+For example, if you wanted to add an internal event handler called `onScrollToBottom`, you would use,
216
+
217
+```javascript
218
+const RCTCustomWebView = requireNativeComponent(
219
+  'RCTCustomWebView',
220
+  CustomWebView,
221
+  {
222
+    ...WebView.extraNativeComponentConfig,
223
+    nativeOnly: {
224
+      ...WebView.extraNativeComponentConfig.nativeOnly,
225
+      onScrollToBottom: true,
226
+    },
227
+  }
228
+);
229
+```

+ 59
- 0
docs/Getting-Started.md View File

1
+# React Native WebView Getting Started Guide
2
+
3
+Here's how to get started quickly with the React Native WebView.
4
+
5
+#### 1. Add react-native-webview to your dependencies
6
+
7
+```
8
+$ npm install --save https://github.com/react-native-community/react-native-webview
9
+```
10
+
11
+#### 2. Link native dependencies
12
+
13
+React Native modules that include native Objective-C, Swift, Java, or Kotlin code have to be "linked" so that the compiler knows to include them in the app.
14
+
15
+Thankfully, there's a way to do this from the terminal with one command:
16
+
17
+```
18
+$ react-native link react-native-webview
19
+```
20
+
21
+_NOTE: If you ever need to uninstall React Native WebView, run `react-native unlink react-native-webview` to unlink it._
22
+
23
+#### 3. Import the webview into your component
24
+
25
+```js
26
+import React, { Component } from 'react';
27
+import { WebView } from 'react-native-webview';
28
+
29
+class MyWeb extends Component {
30
+  render() {
31
+    return (
32
+      <WebView
33
+        source={{uri: 'https://infinite.red'}}
34
+        style={{marginTop: 20}}
35
+      />
36
+    );
37
+  }
38
+}
39
+```
40
+
41
+Minimal example with inline HTML:
42
+
43
+```js
44
+import React, { Component } from 'react';
45
+import { WebView } from 'react-native-webview';
46
+
47
+class MyInlineWeb extends Component {
48
+  render() {
49
+    return (
50
+      <WebView
51
+        originWhitelist={['*']}
52
+        source={{ html: '<h1>Hello world</h1>' }}
53
+      />
54
+    );
55
+  }
56
+}
57
+```
58
+
59
+Next, check out the [API Reference](Reference.md) or [In-Depth Guide](Guide.md).

+ 52
- 0
docs/Guide.md View File

1
+# React Native WebView Guide
2
+
3
+This document walks you through the most common use cases for React Native WebView. It doesn't cover [the full API](Reference.md), but after reading it and looking at the sample code snippets you should have a good sense for how the WebView works and common patterns for using the WebView.
4
+
5
+_This guide is currently a work in progress._
6
+
7
+## Guide Index
8
+
9
+- [Basic Inline HTML](Guide.md#basic-inline-html)
10
+- [Basic URL Source](Guide.md#basic-url-source)
11
+
12
+### Basic inline HTML
13
+
14
+The simplest way to use the WebView is to simply pipe in the HTML you want to display. Note that setting an `html` source requires the [originWhiteList](Reference.md#originWhiteList) property to be set to `['*']`.
15
+
16
+```js
17
+import React, { Component } from 'react';
18
+import { WebView } from 'react-native-webview';
19
+
20
+class MyInlineWeb extends Component {
21
+  render() {
22
+    return (
23
+      <WebView
24
+        originWhitelist={['*']}
25
+        source={{ html: '<h1>This is a static HTML source!</h1>' }}
26
+      />
27
+    );
28
+  }
29
+}
30
+```
31
+
32
+Passing a new static html source will cause the WebView to rerender.
33
+
34
+### Basic URL Source
35
+
36
+This is the most common use-case for WebView.
37
+
38
+```js
39
+import React, { Component } from 'react';
40
+import { WebView } from 'react-native-webview';
41
+
42
+class MyWeb extends Component {
43
+  render() {
44
+    return (
45
+      <WebView
46
+        source={{uri: 'https://infinite.red/react-native'}}
47
+      />
48
+    );
49
+  }
50
+}
51
+```
52
+

+ 495
- 0
docs/Reference.md View File

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).