mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Android: Add error description to Image onError callback (#22737)
Summary: fixes #19073 Changelog: ---------- [Android] [Fixed] - Add error description to Image onError callback Pull Request resolved: https://github.com/facebook/react-native/pull/22737 Differential Revision: D13676224 Pulled By: hramos fbshipit-source-id: 0dea7e97ae6517b8980ad02827f19d22cd3ef933
This commit is contained in:
committed by
Facebook Github Bot
parent
527fc9d192
commit
7795a672d3
@@ -33,13 +33,18 @@ public class ImageLoadEvent extends Event<ImageLoadEvent> {
|
||||
private final @Nullable String mImageUri;
|
||||
private final int mWidth;
|
||||
private final int mHeight;
|
||||
private final @Nullable String mImageError;
|
||||
|
||||
public ImageLoadEvent(int viewId, @ImageEventType int eventType) {
|
||||
this(viewId, eventType, null);
|
||||
}
|
||||
|
||||
public ImageLoadEvent(int viewId, @ImageEventType int eventType, boolean error, String message) {
|
||||
this(viewId, eventType, null, 0, 0, message);
|
||||
}
|
||||
|
||||
public ImageLoadEvent(int viewId, @ImageEventType int eventType, String imageUri) {
|
||||
this(viewId, eventType, imageUri, 0, 0);
|
||||
this(viewId, eventType, imageUri, 0, 0, null);
|
||||
}
|
||||
|
||||
public ImageLoadEvent(
|
||||
@@ -48,11 +53,22 @@ public class ImageLoadEvent extends Event<ImageLoadEvent> {
|
||||
@Nullable String imageUri,
|
||||
int width,
|
||||
int height) {
|
||||
this(viewId, eventType, imageUri, width, height, null);
|
||||
}
|
||||
|
||||
public ImageLoadEvent(
|
||||
int viewId,
|
||||
@ImageEventType int eventType,
|
||||
@Nullable String imageUri,
|
||||
int width,
|
||||
int height,
|
||||
@Nullable String message) {
|
||||
super(viewId);
|
||||
mEventType = eventType;
|
||||
mImageUri = imageUri;
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
mImageError = message;
|
||||
}
|
||||
|
||||
public static String eventNameForType(@ImageEventType int eventType) {
|
||||
@@ -88,7 +104,7 @@ public class ImageLoadEvent extends Event<ImageLoadEvent> {
|
||||
public void dispatch(RCTEventEmitter rctEventEmitter) {
|
||||
WritableMap eventData = null;
|
||||
|
||||
if (mImageUri != null || mEventType == ON_LOAD) {
|
||||
if (mImageUri != null || (mEventType == ON_LOAD || mEventType == ON_ERROR)) {
|
||||
eventData = Arguments.createMap();
|
||||
|
||||
if (mImageUri != null) {
|
||||
@@ -103,6 +119,8 @@ public class ImageLoadEvent extends Event<ImageLoadEvent> {
|
||||
source.putString("url", mImageUri);
|
||||
}
|
||||
eventData.putMap("source", source);
|
||||
} else if (mEventType == ON_ERROR) {
|
||||
eventData.putString("error", mImageError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -262,9 +262,8 @@ public class ReactImageView extends GenericDraweeView {
|
||||
@Override
|
||||
public void onFailure(String id, Throwable throwable) {
|
||||
mEventDispatcher.dispatchEvent(
|
||||
new ImageLoadEvent(getId(), ImageLoadEvent.ON_ERROR));
|
||||
mEventDispatcher.dispatchEvent(
|
||||
new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END));
|
||||
new ImageLoadEvent(getId(), ImageLoadEvent.ON_ERROR,
|
||||
true, throwable.getMessage()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user