Skip to content

Commit

Permalink
Android: Expose Image's onError event to JavaScript
Browse files Browse the repository at this point in the history
Summary:
iOS supports an Image onError event. Android was firing the event but it was never reaching JavaScript because Android didn't include this event in `getExportedCustomDirectEventTypeConstants`.

**Test plan (required)**

Verified that the `onError` event now fires in a test app.

My team uses this change in our app.

Adam Comella
Microsoft Corp.
Closes #10902

Differential Revision: D4180149

Pulled By: ericvicenti

fbshipit-source-id: 4bf0b9aa7dc221d838d7b6b3e88bb47196dcadef
  • Loading branch information
Adam Comella authored and Facebook Github Bot committed Nov 15, 2016
1 parent 191db90 commit e87e181
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Libraries/Image/Image.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ var Image = React.createClass({
* Invoked on load start
*/
onLoadStart: PropTypes.func,
/**
* Invoked on load error
*/
onError: PropTypes.func,
/**
* Invoked when load completes successfully
*/
Expand Down Expand Up @@ -284,10 +288,10 @@ var Image = React.createClass({
sources = source;
}

const {onLoadStart, onLoad, onLoadEnd} = this.props;
const {onLoadStart, onLoad, onLoadEnd, onError} = this.props;
const nativeProps = merge(this.props, {
style,
shouldNotifyLoadEvents: !!(onLoadStart || onLoad || onLoadEnd),
shouldNotifyLoadEvents: !!(onLoadStart || onLoad || onLoadEnd || onError),
src: sources,
loadingIndicatorSrc: loadingIndicatorSource ? loadingIndicatorSource.uri : null,
});
Expand Down
1 change: 0 additions & 1 deletion Libraries/Image/Image.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ const Image = React.createClass({
onProgress: PropTypes.func,
/**
* Invoked on load error with `{nativeEvent: {error}}`.
* @platform ios
*/
onError: PropTypes.func,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ public void setLoadHandlersRegistered(ReactImageView view, boolean shouldNotifyL
MapBuilder.of("registrationName", "onLoadStart"),
ImageLoadEvent.eventNameForType(ImageLoadEvent.ON_LOAD),
MapBuilder.of("registrationName", "onLoad"),
ImageLoadEvent.eventNameForType(ImageLoadEvent.ON_ERROR),
MapBuilder.of("registrationName", "onError"),
ImageLoadEvent.eventNameForType(ImageLoadEvent.ON_LOAD_END),
MapBuilder.of("registrationName", "onLoadEnd"));
}
Expand Down

0 comments on commit e87e181

Please sign in to comment.