Skip to content

Commit

Permalink
add onLoading* prop for WebView
Browse files Browse the repository at this point in the history
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 authored and facebook-github-bot-3 committed Jan 15, 2016
1 parent b68170a commit 274a3e0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Libraries/Components/WebView/WebView.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand All @@ -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,
});
Expand Down
24 changes: 24 additions & 0 deletions Libraries/Components/WebView/WebView.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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({
Expand All @@ -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,
});
Expand Down

0 comments on commit 274a3e0

Please sign in to comment.