feat:Image add imageFilePath

This commit is contained in:
pengfei.zhou 2021-08-05 17:42:45 +08:00 committed by osborn
parent 57cfdd38e1
commit bfa865fe5d
11 changed files with 86 additions and 20 deletions

View File

@ -51,6 +51,8 @@ import com.github.pengfeizhou.jscore.JSONBuilder;
import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue;
import java.io.File;
import jp.wasabeef.glide.transformations.BlurTransformation;
import pub.doric.DoricContext;
import pub.doric.extension.bridge.DoricPlugin;
@ -422,6 +424,14 @@ public class ImageNode extends ViewNode<ImageView> {
}
}
break;
case "imageFilePath":
if (!prop.isString()) {
return;
}
String filePath = prop.asString().value();
File file = new File(filePath);
loadIntoTarget(Glide.with(getContext()).load(file));
break;
default:
super.blend(view, name, prop);
break;

View File

@ -345,16 +345,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
}
} else if ([@"imageRes" isEqualToString:name]) {
#if __has_include(<YYWebImage/YYWebImage.h>)
YYImage *image = [YYImage imageNamed:prop];
#elif __has_include(<SDWebImage/SDWebImage.h>)
UIImage *image = [SDAnimatedImage imageNamed:prop];
if (!image) {
image = [UIImage imageNamed:prop];
}
#else
UIImage *image = [UIImage imageNamed:prop];
#endif
UIImage *image = [self imageNamed:prop];
if (image) {
view.image = image;
} else {
@ -375,16 +366,20 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *fullPath = [path stringByAppendingPathComponent:prop];
NSData *imgData = [[NSData alloc] initWithContentsOfFile:fullPath];
#if __has_include(<YYWebImage/YYWebImage.h>)
YYImage *image = [YYImage imageWithData:imgData scale:self.imageScale];
#elif __has_include(<SDWebImage/SDWebImage.h>)
UIImage *image = [SDAnimatedImage imageWithData:imgData scale:self.imageScale];
if (!image) {
image = [UIImage imageWithData:imgData scale:self.imageScale];
UIImage *image = [self imageFromData:imgData];
view.image = image;
if (self.loadCallbackId.length > 0) {
if (image) {
[self callJSResponse:self.loadCallbackId,
@{@"width": @(image.size.width), @"height": @(image.size.height)},
nil];
} else {
[self callJSResponse:self.loadCallbackId, nil];
}
}
#else
UIImage *image = [UIImage imageWithData:imgData scale:self.imageScale];
#endif
} else if ([@"imageFilePath" isEqualToString:name]) {
NSData *imgData = [[NSData alloc] initWithContentsOfFile:prop];
UIImage *image = [self imageFromData:imgData];
view.image = image;
if (self.loadCallbackId.length > 0) {
if (image) {
@ -404,6 +399,34 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
}
}
- (UIImage *)imageNamed:(NSString *)name {
#if __has_include(<YYWebImage/YYWebImage.h>)
YYImage *image = [YYImage imageNamed:name];
#elif __has_include(<SDWebImage/SDWebImage.h>)
UIImage *image = [SDAnimatedImage imageNamed:name];
if (!image) {
image = [UIImage imageNamed:name];
}
#else
UIImage *image = [UIImage imageNamed:prop];
#endif
return image;
}
- (UIImage *)imageFromData:(NSData *)imgData {
#if __has_include(<YYWebImage/YYWebImage.h>)
YYImage *image = [YYImage imageWithData:imgData scale:self.imageScale];
#elif __has_include(<SDWebImage/SDWebImage.h>)
UIImage *image = [SDAnimatedImage imageWithData:imgData scale:self.imageScale];
if (!image) {
image = [UIImage imageWithData:imgData scale:self.imageScale];
}
#else
UIImage *image = [UIImage imageWithData:imgData scale:self.imageScale];
#endif
return image;
}
- (void)afterBlended:(NSDictionary *)props {
if (self.stretchInsetDic != nil) {
CGFloat left = [self.stretchInsetDic[@"left"] floatValue];

View File

@ -2035,6 +2035,10 @@ var Image = /** @class */ (function (_super) {
Property,
__metadata$9("design:type", String)
], Image.prototype, "imageUrl", void 0);
__decorate$9([
Property,
__metadata$9("design:type", String)
], Image.prototype, "imageFilePath", void 0);
__decorate$9([
Property,
__metadata$9("design:type", String)

View File

@ -1545,6 +1545,10 @@ __decorate$9([
Property,
__metadata$9("design:type", String)
], Image.prototype, "imageUrl", void 0);
__decorate$9([
Property,
__metadata$9("design:type", String)
], Image.prototype, "imageFilePath", void 0);
__decorate$9([
Property,
__metadata$9("design:type", String)

View File

@ -3066,6 +3066,10 @@ __decorate$9([
Property,
__metadata$9("design:type", String)
], Image.prototype, "imageUrl", void 0);
__decorate$9([
Property,
__metadata$9("design:type", String)
], Image.prototype, "imageFilePath", void 0);
__decorate$9([
Property,
__metadata$9("design:type", String)

4
doric-js/index.d.ts vendored
View File

@ -528,6 +528,10 @@ declare module 'doric/lib/src/widget/image' {
}
export class Image extends View {
imageUrl?: string;
/**
* Read image from local file system.
*/
imageFilePath?: string;
/**
* Read image from local path
* For android,it based on assets dir.

View File

@ -7,6 +7,10 @@ export declare enum ScaleType {
}
export declare class Image extends View {
imageUrl?: string;
/**
* Read image from local file system.
*/
imageFilePath?: string;
/**
* Read image from local path
* For android,it based on assets dir.

View File

@ -37,6 +37,10 @@ __decorate([
Property,
__metadata("design:type", String)
], Image.prototype, "imageUrl", void 0);
__decorate([
Property,
__metadata("design:type", String)
], Image.prototype, "imageFilePath", void 0);
__decorate([
Property,
__metadata("design:type", String)

View File

@ -27,6 +27,11 @@ export class Image extends View {
@Property
imageUrl?: string
/**
* Read image from local file system.
*/
@Property
imageFilePath?: string
/**
* Read image from local path
* For android,it based on assets dir.

View File

@ -3120,6 +3120,10 @@ __decorate$9([
Property,
__metadata$9("design:type", String)
], Image.prototype, "imageUrl", void 0);
__decorate$9([
Property,
__metadata$9("design:type", String)
], Image.prototype, "imageFilePath", void 0);
__decorate$9([
Property,
__metadata$9("design:type", String)

File diff suppressed because one or more lines are too long