Ported source prop over to iOS WebView

Summary:
public
https://github.com/facebook/react-native/pull/5494 added a new `source` property to WebView on Android that provides a better API, as well as allowing for request headers to be set.

This diff ports that functionality over to iOS, so we can have a consistent API cross-platform.

I've also extended the API to include `method` (GET or POST) and `body` when setting the WebView content with a URI, and `baseUrl` when setting static HTML.

Reviewed By: javache

Differential Revision: D2884643

fb-gh-sync-id: 83f24494bdbb4e1408aa8f3b7428fee33888ae3a
This commit is contained in:
Nick Lockwood
2016-02-01 18:00:18 -08:00
committed by facebook-github-bot-1
parent 5ec1d354c2
commit 46106f756a
8 changed files with 220 additions and 49 deletions

View File

@@ -49,7 +49,11 @@ var WebViewExample = React.createClass({
inputText: '',
handleTextInputChange: function(event) {
this.inputText = event.nativeEvent.text;
var url = event.nativeEvent.text;
if (!/^[a-zA-Z-_]:/.test(url)) {
url = 'http://' + url;
}
this.inputText = url;
},
render: function() {
@@ -93,7 +97,7 @@ var WebViewExample = React.createClass({
ref={WEBVIEW_REF}
automaticallyAdjustContentInsets={false}
style={styles.webView}
url={this.state.url}
source={{uri: this.state.url}}
javaScriptEnabled={true}
domStorageEnabled={true}
decelerationRate="normal"
@@ -232,7 +236,26 @@ exports.title = '<WebView>';
exports.description = 'Base component to display web content';
exports.examples = [
{
title: 'WebView',
title: 'Simple Browser',
render(): ReactElement { return <WebViewExample />; }
},
{
title: 'POST Test',
render(): ReactElement {
return (
<WebView
style={{
backgroundColor: BGWASH,
height: 100,
}}
source={{
uri: 'http://www.posttestserver.com/post.php',
method: 'POST',
body: 'foo=bar&bar=foo'
}}
scalesPageToFit={false}
/>
);
}
}
];