Skip to content
Permalink
Browse files

add onLoading* prop for WebView

Summary:
add onLoadingStart,onLoadingError,onLoadingFinish prop for WebView
Closes #5335

Reviewed By: svcscm

Differential Revision: D2834003

Pulled By: nicklockwood

fb-gh-sync-id: bbe84297ebeb5a6c2bf1caaacee8c59e0bcef1db
  • Loading branch information...
Horcrux facebook-github-bot-3
Horcrux authored and facebook-github-bot-3 committed Jan 15, 2016
1 parent b68170a commit 274a3e05858a51af3d0eb8bdea2f7975f7f61169
Showing with 36 additions and 0 deletions.
  1. +12 −0 Libraries/Components/WebView/WebView.android.js
  2. +24 −0 Libraries/Components/WebView/WebView.ios.js
@@ -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,
});
@@ -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,
});

0 comments on commit 274a3e0

Please sign in to comment.
You can’t perform that action at this time.