Skip to content

Commit

Permalink
fix(android)!: change Image getSize failure parameter type
Browse files Browse the repository at this point in the history
BREAKING CHANGE:: failure parameter on Android used to be a String, now is an object
  • Loading branch information
wwwcg authored and hippy-actions[bot] committed Nov 22, 2023
1 parent 7ed0049 commit 4dbb0fe
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
public class ImageLoaderModule extends HippyNativeModuleBase {

private final VfsManager mVfsManager;
private static final String ERROR_KEY_MESSAGE = "message";

public ImageLoaderModule(HippyEngineContext context) {
super(context);
Expand All @@ -50,7 +51,9 @@ private void decodeImageData(@NonNull final String url, @NonNull byte[] data, fi
jsObject.set("height", options.outHeight);
promise.resolve(jsObject);
} catch (OutOfMemoryError | Exception e) {
promise.reject("Fetch image failed, url=" + url + ", msg=" + e.getMessage());
JSObject jsObject = new JSObject();
jsObject.set(ERROR_KEY_MESSAGE, "Fetch image failed, url=" + url + ", msg=" + e.getMessage());
promise.reject(jsObject);
}
}

Expand All @@ -64,7 +67,9 @@ private HashMap<String, String> generateRequestParams() {
@HippyMethod(name = "getSize")
public void getSize(final String url, final Promise promise) {
if (TextUtils.isEmpty(url)) {
promise.reject("Url parameter is empty!");
JSObject jsObject = new JSObject();
jsObject.set(ERROR_KEY_MESSAGE, "Url parameter is empty!");
promise.reject(jsObject);
return;
}
mVfsManager.fetchResourceAsync(url, null, generateRequestParams(),
Expand All @@ -77,7 +82,10 @@ public void onFetchCompleted(@NonNull final ResourceDataHolder dataHolder) {
|| bytes.length <= 0) {
String message =
dataHolder.errorMessage != null ? dataHolder.errorMessage : "";
promise.reject("Fetch image failed, url=" + url + ", msg=" + message);
String errorMsg = "Fetch image failed, url=" + url + ", msg=" + message;
JSObject jsObject = new JSObject();
jsObject.set(ERROR_KEY_MESSAGE, errorMsg);
promise.reject(jsObject);
} else {
decodeImageData(url, bytes, promise);
}
Expand Down

0 comments on commit 4dbb0fe

Please sign in to comment.