Skip to content

Commit e87e181

Browse files
Adam ComellaFacebook Github Bot
authored andcommitted
Android: Expose Image's onError event to JavaScript
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
1 parent 191db90 commit e87e181

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Libraries/Image/Image.android.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ var Image = React.createClass({
119119
* Invoked on load start
120120
*/
121121
onLoadStart: PropTypes.func,
122+
/**
123+
* Invoked on load error
124+
*/
125+
onError: PropTypes.func,
122126
/**
123127
* Invoked when load completes successfully
124128
*/
@@ -284,10 +288,10 @@ var Image = React.createClass({
284288
sources = source;
285289
}
286290

287-
const {onLoadStart, onLoad, onLoadEnd} = this.props;
291+
const {onLoadStart, onLoad, onLoadEnd, onError} = this.props;
288292
const nativeProps = merge(this.props, {
289293
style,
290-
shouldNotifyLoadEvents: !!(onLoadStart || onLoad || onLoadEnd),
294+
shouldNotifyLoadEvents: !!(onLoadStart || onLoad || onLoadEnd || onError),
291295
src: sources,
292296
loadingIndicatorSrc: loadingIndicatorSource ? loadingIndicatorSource.uri : null,
293297
});

Libraries/Image/Image.ios.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ const Image = React.createClass({
255255
onProgress: PropTypes.func,
256256
/**
257257
* Invoked on load error with `{nativeEvent: {error}}`.
258-
* @platform ios
259258
*/
260259
onError: PropTypes.func,
261260
/**

ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ public void setLoadHandlersRegistered(ReactImageView view, boolean shouldNotifyL
178178
MapBuilder.of("registrationName", "onLoadStart"),
179179
ImageLoadEvent.eventNameForType(ImageLoadEvent.ON_LOAD),
180180
MapBuilder.of("registrationName", "onLoad"),
181+
ImageLoadEvent.eventNameForType(ImageLoadEvent.ON_ERROR),
182+
MapBuilder.of("registrationName", "onError"),
181183
ImageLoadEvent.eventNameForType(ImageLoadEvent.ON_LOAD_END),
182184
MapBuilder.of("registrationName", "onLoadEnd"));
183185
}

0 commit comments

Comments
 (0)