add iOS Image Node
This commit is contained in:
@@ -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 {
|
||||
|
16
iOS/Pod/Classes/Shader/DoricImageNode.h
Normal file
16
iOS/Pod/Classes/Shader/DoricImageNode.h
Normal 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
|
36
iOS/Pod/Classes/Shader/DoricImageNode.m
Normal file
36
iOS/Pod/Classes/Shader/DoricImageNode.m
Normal 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
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user