add iOS Image Node

This commit is contained in:
pengfei.zhou
2019-08-06 20:06:34 +08:00
parent 471e87badc
commit f1efee6a3e
90 changed files with 82 additions and 2108 deletions

View File

@@ -12,6 +12,7 @@
#import "DoricVLayoutNode.h"
#import "DoricHLayoutNode.h"
#import "DoricTextNode.h"
#import "DoricImageNode.h"
@interface DoricRegistry ()
@@ -41,7 +42,7 @@ - (void)innerRegister {
[self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"];
[self registerViewNode:DoricHLayoutNode.class withName:@"HLayout"];
[self registerViewNode:DoricTextNode.class withName:@"Text"];
[self registerViewNode:DoricImageNode.class withName:@"Image"];
}
- (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name {

View File

@@ -0,0 +1,16 @@
//
// DoricImageNode.h
// Doric
//
// Created by pengfei.zhou on 2019/8/6.
//
#import "DoricViewNode.h"
NS_ASSUME_NONNULL_BEGIN
@interface DoricImageNode : DoricViewNode<UIImageView *>
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,36 @@
//
// DoricImageNode.m
// Doric
//
// Created by pengfei.zhou on 2019/8/6.
//
#import "DoricImageNode.h"
#import <SDWebImage/SDWebImage.h>
@implementation DoricImageNode
- (UIView *)build:(NSDictionary *)props {
return [[UIImageView alloc] init];
}
- (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id)prop {
if ([name isEqualToString:@"imageUrl"]) {
__weak typeof(self) _self = self;
[view sd_setImageWithURL:[NSURL URLWithString:prop] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
__strong typeof(_self) self = _self;
[self requestLayout];
}];
} else {
[super blendView:view forPropName:name propValue:prop];
}
}
- (void)measureByParent:(DoricGroupNode *)parent {
DoricLayoutDesc widthSpec = self.layoutParams.width;
DoricLayoutDesc heightSpec = self.layoutParams.height;
if (widthSpec == LAYOUT_WRAP_CONTENT || heightSpec == LAYOUT_WRAP_CONTENT) {
[self.view sizeToFit];
}
}
@end

View File

@@ -14,8 +14,11 @@ - (void)setupRootView:(UIView *)view {
- (void)render:(NSDictionary *)props {
[self blend:props];
[self requestLayout];
}
- (void)requestLayout {
[self measureByParent:self];
[self layoutByParent:self];
}
@end

View File

@@ -53,6 +53,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)layoutByParent:(DoricGroupNode *)parent;
+ (DoricViewNode *)create:(DoricContext *)context withType:(NSString *)type;
- (void)requestLayout;
@end
NS_ASSUME_NONNULL_END

View File

@@ -178,7 +178,11 @@ - (CGFloat)measuredHeight {
}
- (void)measureByParent:(DoricGroupNode *)parent {
DoricLayoutDesc widthSpec = self.layoutParams.width;
DoricLayoutDesc heightSpec = self.layoutParams.height;
if (widthSpec == LAYOUT_WRAP_CONTENT || heightSpec == LAYOUT_WRAP_CONTENT) {
[self.view sizeToFit];
}
}
- (void)layoutByParent:(DoricGroupNode *)parent {
@@ -296,4 +300,8 @@ - (void)setCenterY:(CGFloat)centerY {
((UIView *)self.view).centerY = centerY;
}
- (void)requestLayout {
[self.parent requestLayout];
}
@end