diff --git a/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java b/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java index c64bd071..7385b2d2 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java @@ -15,8 +15,8 @@ */ package pub.doric.shader; +import android.annotation.SuppressLint; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; @@ -32,10 +32,8 @@ import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.DrawableImageViewTarget; -import com.bumptech.glide.request.target.ImageViewTarget; import com.bumptech.glide.request.target.SizeReadyCallback; import com.bumptech.glide.request.target.Target; -import com.bumptech.glide.request.transition.Transition; import com.github.pengfeizhou.jscore.JSONBuilder; import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSValue; @@ -146,6 +144,11 @@ public class ImageNode extends ViewNode { private void loadImageUrl(String url) { RequestBuilder requestBuilder = Glide.with(getContext()) .load(url); + loadIntoTarget(requestBuilder); + } + + + private void loadIntoTarget(RequestBuilder requestBuilder) { try { requestBuilder = requestBuilder.apply(new RequestOptions().override(Target.SIZE_ORIGINAL)); if (isBlur) { @@ -197,6 +200,8 @@ public class ImageNode extends ViewNode { return false; } }).into(new DrawableImageViewTarget(mView) { + + @SuppressLint("MissingSuperCall") @Override public void getSize(@NonNull SizeReadyCallback cb) { cb.onSizeReady(SIZE_ORIGINAL, SIZE_ORIGINAL); @@ -247,8 +252,7 @@ public class ImageNode extends ViewNode { if (!TextUtils.isEmpty(imageType) && !TextUtils.isEmpty(base64)) { try { byte[] data = Base64.decode(base64, Base64.DEFAULT); - Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); - view.setImageBitmap(bitmap); + loadIntoTarget(Glide.with(getContext()).load(data)); } catch (Exception e) { e.printStackTrace(); } @@ -271,22 +275,7 @@ public class ImageNode extends ViewNode { "drawable", getDoricContext().getContext().getPackageName()); if (resId > 0) { - Drawable drawable = getContext().getResources().getDrawable(resId); - view.setImageResource(resId); - if (!TextUtils.isEmpty(loadCallbackId)) { - if (drawable instanceof BitmapDrawable) { - Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); - callJSResponse(loadCallbackId, new JSONBuilder() - .put("width", DoricUtils.px2dp(bitmap.getWidth())) - .put("height", DoricUtils.px2dp(bitmap.getHeight())) - .toJSONObject()); - } else { - callJSResponse(loadCallbackId, new JSONBuilder() - .put("width", DoricUtils.px2dp(drawable.getIntrinsicWidth())) - .put("height", DoricUtils.px2dp(drawable.getIntrinsicHeight())) - .toJSONObject()); - } - } + loadIntoTarget(Glide.with(getContext()).load(resId)); } else { if (!TextUtils.isEmpty(loadCallbackId)) { callJSResponse(loadCallbackId); diff --git a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m index 695108cf..b4332a76 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m @@ -197,7 +197,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id } NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64 options:NSDataBase64DecodingIgnoreUnknownCharacters]; - UIImage *image = [UIImage imageWithData:imageData]; + YYImage *image = [YYImage imageWithData:imageData]; view.image = image; } else if ([@"isBlur" isEqualToString:name]) { NSInteger value = [prop intValue];