Add WebView integration example to cookies example

Reviewed By: dmmiller

Differential Revision: D3207659

fb-gh-sync-id: f87d70d53de9a8215bb593502368d16251ebb358
fbshipit-source-id: f87d70d53de9a8215bb593502368d16251ebb358
This commit is contained in:
Alexander Blom 2016-04-25 09:43:12 -07:00 committed by Facebook Github Bot 9
parent 61c53d4939
commit 69c083b27d
1 changed files with 20 additions and 0 deletions

View File

@ -22,6 +22,7 @@ var {
Text,
TouchableHighlight,
View,
WebView,
} = ReactNative;
var RCTNetworking = require('RCTNetworking');
@ -45,6 +46,7 @@ class XHRExampleCookies extends React.Component {
var url = `https://${domain}/cookies/set?a=${a}&b=${b}`;
fetch(url).then((response) => {
this.setStatus(`Cookies a=${a}, b=${b} set`);
this.refreshWebview();
});
this.setState({
@ -59,6 +61,7 @@ class XHRExampleCookies extends React.Component {
return response.json();
}).then((data) => {
this.setStatus(`Got cookies ${JSON.stringify(data.cookies)} from server`);
this.refreshWebview();
});
this.setStatus('Getting cookies...');
@ -67,9 +70,14 @@ class XHRExampleCookies extends React.Component {
clearCookies() {
RCTNetworking.clearCookies((cleared) => {
this.setStatus('Cookies cleared, had cookies=' + cleared);
this.refreshWebview();
});
}
refreshWebview() {
this.refs.webview.reload();
}
setStatus(status: string) {
this.setState({status});
}
@ -113,6 +121,18 @@ class XHRExampleCookies extends React.Component {
</View>
</TouchableHighlight>
<Text>{this.state.status}</Text>
<TouchableHighlight
style={styles.wrapper}
onPress={this.refreshWebview.bind(this)}>
<View style={styles.button}>
<Text>Refresh Webview</Text>
</View>
</TouchableHighlight>
<WebView
ref="webview"
source={{uri: 'http://httpbin.org/cookies'}}
style={{height: 100}}
/>
</View>
);
}