add onLoading* prop for WebView

Summary:
add onLoadingStart,onLoadingError,onLoadingFinish prop for WebView
Closes https://github.com/facebook/react-native/pull/5335

Reviewed By: svcscm

Differential Revision: D2834003

Pulled By: nicklockwood

fb-gh-sync-id: bbe84297ebeb5a6c2bf1caaacee8c59e0bcef1db
This commit is contained in:
Horcrux 2016-01-15 09:30:47 -08:00 committed by facebook-github-bot-3
parent b68170a489
commit 274a3e0585
2 changed files with 36 additions and 0 deletions

View File

@ -40,6 +40,10 @@ var WebView = React.createClass({
...View.propTypes,
renderError: PropTypes.func,
renderLoading: PropTypes.func,
onLoad: PropTypes.func,
onLoadEnd: PropTypes.func,
onLoadStart: PropTypes.func,
onError: PropTypes.func,
url: PropTypes.string,
html: PropTypes.string,
automaticallyAdjustContentInsets: PropTypes.bool,
@ -189,11 +193,16 @@ var WebView = React.createClass({
},
onLoadingStart: function(event) {
var onLoadStart = this.props.onLoadStart;
onLoadStart && onLoadStart(event);
this.updateNavigationState(event);
},
onLoadingError: function(event) {
event.persist(); // persist this event because we need to store it
var {onError, onLoadEnd} = this.props;
onError && onError(event);
onLoadEnd && onLoadEnd(event);
console.error('Encountered an error loading page', event.nativeEvent);
this.setState({
@ -203,6 +212,9 @@ var WebView = React.createClass({
},
onLoadingFinish: function(event) {
var {onLoad, onLoadEnd} = this.props;
onLoad && onLoad(event);
onLoadEnd && onLoadEnd(event);
this.setState({
viewState: WebViewState.IDLE,
});

View File

@ -97,6 +97,22 @@ var WebView = React.createClass({
* Function that returns a loading indicator.
*/
renderLoading: PropTypes.func,
/**
* Invoked when load finish
*/
onLoad: PropTypes.func,
/**
* Invoked when load either succeeds or fails
*/
onLoadEnd: PropTypes.func,
/**
* Invoked on load start
*/
onLoadStart: PropTypes.func,
/**
* Invoked when load fails
*/
onError: PropTypes.func,
/**
* @platform ios
*/
@ -279,11 +295,16 @@ var WebView = React.createClass({
},
onLoadingStart: function(event: Event) {
var onLoadStart = this.props.onLoadStart;
onLoadStart && onLoadStart(event);
this.updateNavigationState(event);
},
onLoadingError: function(event: Event) {
event.persist(); // persist this event because we need to store it
var {onError, onLoadEnd} = this.props;
onError && onError(event);
onLoadEnd && onLoadEnd(event);
console.warn('Encountered an error loading page', event.nativeEvent);
this.setState({
@ -293,6 +314,9 @@ var WebView = React.createClass({
},
onLoadingFinish: function(event: Event) {
var {onLoad, onLoadEnd} = this.props;
onLoad && onLoad(event);
onLoadEnd && onLoadEnd(event);
this.setState({
viewState: WebViewState.IDLE,
});