diff --git a/Android/doric/src/main/java/pub/doric/shader/ImageNode.java b/Android/doric/src/main/java/pub/doric/shader/ImageNode.java index 29a77b41..9157c80d 100644 --- a/Android/doric/src/main/java/pub/doric/shader/ImageNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/ImageNode.java @@ -34,6 +34,7 @@ import com.bumptech.glide.request.target.Target; import pub.doric.DoricContext; import pub.doric.extension.bridge.DoricPlugin; +import pub.doric.utils.DoricUtils; import com.github.pengfeizhou.jscore.JSONBuilder; import com.github.pengfeizhou.jscore.JSValue; @@ -77,8 +78,8 @@ public class ImageNode extends ViewNode { public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { if (!TextUtils.isEmpty(loadCallbackId)) { callJSResponse(loadCallbackId, new JSONBuilder() - .put("width", resource.getIntrinsicWidth()) - .put("height", resource.getIntrinsicHeight()) + .put("width", DoricUtils.px2dp(resource.getIntrinsicWidth())) + .put("height", DoricUtils.px2dp(resource.getIntrinsicHeight())) .toJSONObject()); } return false; diff --git a/demo/src/ImageDemo.ts b/demo/src/ImageDemo.ts index a26c4cee..15ce8d55 100644 --- a/demo/src/ImageDemo.ts +++ b/demo/src/ImageDemo.ts @@ -1,4 +1,4 @@ -import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, Text, scroller, layoutConfig, image, IView, IVLayout, ScaleType } from "doric"; +import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, Text, scroller, layoutConfig, image, IView, IVLayout, ScaleType, Image } from "doric"; import { colors, label } from "./utils"; import { img_base64 } from "./image_base64"; const imageUrl = 'https://img.zcool.cn/community/01e75b5da933daa801209e1ffa4649.jpg@1280w_1l_2o_100sh.jpg' @@ -6,6 +6,7 @@ const imageUrl = 'https://img.zcool.cn/community/01e75b5da933daa801209e1ffa4649. @Entry class ImageDemo extends Panel { build(rootView: Group): void { + let imageView: Image scroller(vlayout([ text({ text: "Image Demo", @@ -38,9 +39,13 @@ class ImageDemo extends Panel { } }), label('WebP'), - image({ + imageView = image({ imageUrl: "https://p.upyun.com/demo/webp/webp/jpg-0.webp", loadCallback: (ret) => { + if (ret) { + imageView.width = ret.width + imageView.height = ret.height + } } }), label('ScaleToFill'), diff --git a/iOS/Doric.podspec b/iOS/Doric.podspec index 36590515..8eb2cf33 100644 --- a/iOS/Doric.podspec +++ b/iOS/Doric.podspec @@ -39,8 +39,9 @@ TODO: Add long description of the pod here. s.public_header_files = 'Pod/Classes/**/*.h' # s.frameworks = 'UIKit', 'MapKit' # s.dependency 'AFNetworking', '~> 2.3' - s.dependency 'SDWebImage', '~> 4.4.7' - s.dependency 'SDWebImage/WebP' + # s.dependency 'SDWebImage', '~> 5.0' + s.dependency 'YYWebImage', '~>1.0.5' + s.dependency 'YYImage/WebP' s.dependency 'SocketRocket', '~> 0.5.1' s.dependency 'GCDWebServer', '~> 3.0' s.dependency 'YYCache', '~> 1.0.4' diff --git a/iOS/Example/Podfile.lock b/iOS/Example/Podfile.lock index 1283d0e3..801a54e6 100644 --- a/iOS/Example/Podfile.lock +++ b/iOS/Example/Podfile.lock @@ -1,30 +1,23 @@ PODS: - Doric (0.1.0): - GCDWebServer (~> 3.0) - - SDWebImage (~> 4.4.7) - - SDWebImage/WebP - SocketRocket (~> 0.5.1) - YYCache (~> 1.0.4) + - YYImage/WebP + - YYWebImage - GCDWebServer (3.5.3): - GCDWebServer/Core (= 3.5.3) - GCDWebServer/Core (3.5.3) - - libwebp (1.0.3): - - libwebp/demux (= 1.0.3) - - libwebp/mux (= 1.0.3) - - libwebp/webp (= 1.0.3) - - libwebp/demux (1.0.3): - - libwebp/webp - - libwebp/mux (1.0.3): - - libwebp/demux - - libwebp/webp (1.0.3) - - SDWebImage (4.4.7): - - SDWebImage/Core (= 4.4.7) - - SDWebImage/Core (4.4.7) - - SDWebImage/WebP (4.4.7): - - libwebp (< 2.0, >= 0.5) - - SDWebImage/Core - SocketRocket (0.5.1) - YYCache (1.0.4) + - YYImage (1.0.4): + - YYImage/Core (= 1.0.4) + - YYImage/Core (1.0.4) + - YYImage/WebP (1.0.4): + - YYImage/Core + - YYWebImage (1.0.5): + - YYCache + - YYImage DEPENDENCIES: - Doric (from `../`) @@ -32,22 +25,22 @@ DEPENDENCIES: SPEC REPOS: https://github.com/cocoapods/specs.git: - GCDWebServer - - libwebp - - SDWebImage - SocketRocket - YYCache + - YYImage + - YYWebImage EXTERNAL SOURCES: Doric: :path: "../" SPEC CHECKSUMS: - Doric: c71287d68afeeb79bfd3c680ed2dd3b90d515c12 + Doric: e73b17b0e46198994f5c3d8af49f26fd9f49df09 GCDWebServer: c0ab22c73e1b84f358d1e2f74bf6afd1c60829f2 - libwebp: 057912d6d0abfb6357d8bb05c0ea470301f5d61e - SDWebImage: c10d14a8883ebd89664f02a422006f66a85c0c5d SocketRocket: d57c7159b83c3c6655745cd15302aa24b6bae531 YYCache: 8105b6638f5e849296c71f331ff83891a4942952 + YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54 + YYWebImage: 5f7f36aee2ae293f016d418c7d6ba05c4863e928 PODFILE CHECKSUM: 012563d71439e7e33e976dca3b59664ed56cee39 diff --git a/iOS/Pod/Classes/Shader/DoricImageNode.m b/iOS/Pod/Classes/Shader/DoricImageNode.m index 6670a4fd..95cfd878 100644 --- a/iOS/Pod/Classes/Shader/DoricImageNode.m +++ b/iOS/Pod/Classes/Shader/DoricImageNode.m @@ -22,7 +22,7 @@ #import "DoricImageNode.h" #import "Doric.h" -#import +#import "YYWebImage.h" @interface DoricImageNode () @property(nonatomic, copy) NSString *loadCallbackId; @@ -31,7 +31,7 @@ @interface DoricImageNode () @implementation DoricImageNode - (UIImageView *)build { - return [[UIImageView new] also:^(UIImageView *it) { + return [[YYAnimatedImageView new] also:^(UIImageView *it) { it.clipsToBounds = YES; }]; } @@ -39,7 +39,7 @@ - (UIImageView *)build { - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id)prop { if ([@"imageUrl" isEqualToString:name]) { __weak typeof(self) _self = self; - [view sd_setImageWithURL:[NSURL URLWithString:prop] completed:^(UIImage *_Nullable image, NSError *_Nullable error, SDImageCacheType cacheType, NSURL *_Nullable imageURL) { + [view yy_setImageWithURL:[NSURL URLWithString:prop] placeholder:nil options:0 completion:^(UIImage *image, NSURL *url, YYWebImageFromType from, YYWebImageStage stage, NSError *error) { __strong typeof(_self) self = _self; if (error) { if (self.loadCallbackId.length > 0) { @@ -53,7 +53,6 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id } [self requestLayout]; } - }]; } else if ([@"scaleType" isEqualToString:name]) { switch ([prop integerValue]) { diff --git a/iOS/Pod/Classes/Shader/DoricLayouts.m b/iOS/Pod/Classes/Shader/DoricLayouts.m index 902b4478..c1e0adfb 100644 --- a/iOS/Pod/Classes/Shader/DoricLayouts.m +++ b/iOS/Pod/Classes/Shader/DoricLayouts.m @@ -176,8 +176,6 @@ - (void)layoutSubviews { @interface DoricStackView () -@property(nonatomic, assign) CGFloat contentWidth; -@property(nonatomic, assign) CGFloat contentHeight; @end @implementation DoricStackView