format OC code

This commit is contained in:
pengfei.zhou
2019-10-12 14:48:19 +08:00
parent 820f1e9f8c
commit f9b599e7cf
43 changed files with 493 additions and 472 deletions

View File

@@ -9,13 +9,13 @@
NS_ASSUME_NONNULL_BEGIN
@interface DoricGroupNode <V:UIView *,P:LayoutParams *>: DoricViewNode<V>
@interface DoricGroupNode <V:UIView *, P:LayoutParams *> : DoricViewNode<V>
@property (nonatomic,strong) NSMutableDictionary *children;
@property (nonatomic,strong) NSMutableArray *indexedChildren;
@property(nonatomic, strong) NSMutableDictionary *children;
@property(nonatomic, strong) NSMutableArray *indexedChildren;
@property (nonatomic) CGFloat desiredWidth;
@property (nonatomic) CGFloat desiredHeight;
@property(nonatomic) CGFloat desiredWidth;
@property(nonatomic) CGFloat desiredHeight;
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig;

View File

@@ -10,12 +10,13 @@
@implementation DoricGroupNode
- (instancetype)initWithContext:(DoricContext *)doricContext {
if(self = [super initWithContext:doricContext]) {
if (self = [super initWithContext:doricContext]) {
_children = [[NSMutableDictionary alloc] init];
_indexedChildren = [[NSMutableArray alloc] init];
}
return self;
}
- (UIView *)build:(NSDictionary *)props {
UIView *ret = [[UIView alloc] init];
ret.clipsToBounds = YES;
@@ -23,24 +24,24 @@ - (UIView *)build:(NSDictionary *)props {
}
- (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop {
if([name isEqualToString:@"children"]) {
if ([name isEqualToString:@"children"]) {
NSArray *array = prop;
NSInteger i;
NSMutableArray *tobeRemoved = [[NSMutableArray alloc] init];
for (i = 0; i< array.count; i++) {
for (i = 0; i < array.count; i++) {
NSDictionary *val = array[i];
if (!val || (NSNull *)val == [NSNull null]) {
if (!val || (NSNull *) val == [NSNull null]) {
continue;
}
NSString *type = [val objectForKey:@"type"];
NSString *viewId = [val objectForKey:@"id"];
DoricViewNode *node = [self.children objectForKey:viewId];
NSString *type = val[@"type"];
NSString *viewId = val[@"id"];
DoricViewNode *node = self.children[viewId];
if (node == nil) {
node = [DoricViewNode create:self.doricContext withType:type];
node.index = i;
node.parent = self;
node.viewId = viewId;
[self.children setObject:node forKey:viewId];
self.children[viewId] = node;
} else {
if (i != node.index) {
[self.indexedChildren removeObjectAtIndex:i];
@@ -49,41 +50,41 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
}
[tobeRemoved removeObject:node];
}
DoricViewNode *old = i >= self.indexedChildren.count ? nil :[self.indexedChildren objectAtIndex:i];
DoricViewNode *old = i >= self.indexedChildren.count ? nil : self.indexedChildren[i];
if (old && old != node) {
[old.view removeFromSuperview];
self.indexedChildren[i] = [NSNull null];
[tobeRemoved addObject:old];
}
LayoutParams *params = node.layoutParams;
if (params == nil) {
params = [self generateDefaultLayoutParams];
node.layoutParams = params;
}
[node blend:[val objectForKey:@"props"]];
[node blend:val[@"props"]];
if (self.indexedChildren.count <= i) {
[self.view addSubview:node.view];
[self.indexedChildren addObject:node];
}else if ([self.indexedChildren objectAtIndex:i] == [NSNull null]) {
} else if (self.indexedChildren[i] == [NSNull null]) {
self.indexedChildren[i] = node;
[self.view insertSubview:node.view atIndex:i];
}
}
NSUInteger start = i;
NSInteger start = i;
while (start < self.indexedChildren.count) {
DoricViewNode *node = [self.indexedChildren objectAtIndex:start];
DoricViewNode *node = self.indexedChildren[(NSUInteger) start];
if (node) {
[self.children removeObjectForKey: node.viewId];
[self.children removeObjectForKey:node.viewId];
[node.view removeFromSuperview];
[tobeRemoved removeObject:node];
}
start++;
}
if (i < self.indexedChildren.count) {
[self.indexedChildren removeObjectsInRange:NSMakeRange(i, self.indexedChildren.count - i)];
[self.indexedChildren removeObjectsInRange:NSMakeRange((NSUInteger) i, self.indexedChildren.count - i)];
}
for (DoricViewNode *node in tobeRemoved) {
[self.children removeObjectForKey:node.viewId];
}
@@ -100,16 +101,16 @@ - (LayoutParams *)generateDefaultLayoutParams {
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig {
LayoutParams *params = child.layoutParams;
if ([params isKindOfClass:MarginLayoutParams.class]) {
MarginLayoutParams *marginParams = (MarginLayoutParams *)params;
NSDictionary *margin = [layoutconfig objectForKey:@"margin"];
MarginLayoutParams *marginParams = (MarginLayoutParams *) params;
NSDictionary *margin = layoutconfig[@"margin"];
if (margin) {
marginParams.margin.top = [(NSNumber *)[margin objectForKey:@"top"] floatValue];
marginParams.margin.left = [(NSNumber *)[margin objectForKey:@"left"] floatValue];
marginParams.margin.right = [(NSNumber *)[margin objectForKey:@"right"] floatValue];
marginParams.margin.bottom = [(NSNumber *)[margin objectForKey:@"bottom"] floatValue];
marginParams.margin.top = [(NSNumber *) margin[@"top"] floatValue];
marginParams.margin.left = [(NSNumber *) margin[@"left"] floatValue];
marginParams.margin.right = [(NSNumber *) margin[@"right"] floatValue];
marginParams.margin.bottom = [(NSNumber *) margin[@"bottom"] floatValue];
}
}
}
@end

View File

@@ -9,9 +9,9 @@
NS_ASSUME_NONNULL_BEGIN
@interface DoricHLayoutNode : DoricGroupNode<UIView *,VHLayoutParams *>
@property (nonatomic) CGFloat space;
@property (nonatomic) DoricGravity gravity;
@interface DoricHLayoutNode : DoricGroupNode<UIView *, VHLayoutParams *>
@property(nonatomic) CGFloat space;
@property(nonatomic) DoricGravity gravity;
@end
NS_ASSUME_NONNULL_END

View File

@@ -17,7 +17,7 @@ - (UIView *)build:(NSDictionary *)props {
- (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) {
[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];
}];

View File

@@ -9,8 +9,8 @@
NS_ASSUME_NONNULL_BEGIN
@interface DoricStackNode : DoricGroupNode<UIView *,StackLayoutParams *>
@property (nonatomic) DoricGravity gravity;
@interface DoricStackNode : DoricGroupNode<UIView *, StackLayoutParams *>
@property(nonatomic) DoricGravity gravity;
@end
NS_ASSUME_NONNULL_END

View File

@@ -11,7 +11,7 @@
@implementation DoricStackNode
- (instancetype)init {
if (self = [super init]){
if (self = [super init]) {
_gravity = 0;
}
return self;
@@ -20,7 +20,7 @@ - (instancetype)init {
- (void)measureByParent:(DoricGroupNode *)parent {
DoricLayoutDesc widthSpec = self.layoutParams.width;
DoricLayoutDesc heightSpec = self.layoutParams.height;
CGFloat maxWidth = 0,maxHeight = 0;
CGFloat maxWidth = 0, maxHeight = 0;
for (DoricViewNode *child in self.indexedChildren) {
[child measureByParent:self];
CGFloat placeWidth = child.measuredWidth;
@@ -30,15 +30,16 @@ - (void)measureByParent:(DoricGroupNode *)parent {
}
self.desiredWidth = maxWidth;
self.desiredHeight = maxHeight;
if (widthSpec == LAYOUT_WRAP_CONTENT) {
self.width = maxWidth;
}
if (heightSpec == LAYOUT_WRAP_CONTENT) {
self.height = maxHeight;
}
}
- (LayoutParams *)generateDefaultLayoutParams {
return [[StackLayoutParams alloc] init];
}
@@ -49,7 +50,7 @@ - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutcon
DoricLog(@"blend Stack child error,layout params not match");
return;
}
StackLayoutParams *params = (StackLayoutParams *)child.layoutParams;
StackLayoutParams *params = (StackLayoutParams *) child.layoutParams;
// NSDictionary *margin = [layoutconfig objectForKey:@"margin"];
// if (margin) {
// params.margin.top = [(NSNumber *)[margin objectForKey:@"top"] floatValue];
@@ -57,7 +58,7 @@ - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutcon
// params.margin.right = [(NSNumber *)[margin objectForKey:@"right"] floatValue];
// params.margin.bottom = [(NSNumber *)[margin objectForKey:@"bottom"] floatValue];
// }
NSNumber *alignment = [layoutconfig objectForKey:@"alignment"];
NSNumber *alignment = layoutconfig[@"alignment"];
if (alignment) {
params.alignment = [alignment integerValue];
}
@@ -73,10 +74,10 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
}
DoricGravity gravity = self.gravity;
if ([child.layoutParams isKindOfClass:StackLayoutParams.class]) {
StackLayoutParams *layoutParams = (StackLayoutParams *)child.layoutParams;
StackLayoutParams *layoutParams = (StackLayoutParams *) child.layoutParams;
gravity |= layoutParams.alignment;
}
if ((gravity & LEFT) == LEFT) {
child.left = self.left;
}

View File

@@ -18,11 +18,11 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
if ([name isEqualToString:@"text"]) {
view.text = prop;
} else if ([name isEqualToString:@"textSize"]) {
view.font = [UIFont systemFontOfSize:[(NSNumber *)prop floatValue]];
view.font = [UIFont systemFontOfSize:[(NSNumber *) prop floatValue]];
} else if ([name isEqualToString:@"textColor"]) {
view.textColor = DoricColor(prop);
} else if ([name isEqualToString:@"textAlignment"]) {
DoricGravity gravity = [(NSNumber *)prop integerValue];
DoricGravity gravity = [(NSNumber *) prop integerValue];
NSTextAlignment alignment = NSTextAlignmentCenter;
switch (gravity) {
case LEFT:

View File

@@ -9,9 +9,9 @@
NS_ASSUME_NONNULL_BEGIN
@interface DoricVLayoutNode : DoricGroupNode<UIView *,VHLayoutParams *>
@property (nonatomic) CGFloat space;
@property (nonatomic) DoricGravity gravity;
@interface DoricVLayoutNode : DoricGroupNode<UIView *, VHLayoutParams *>
@property(nonatomic) CGFloat space;
@property(nonatomic) DoricGravity gravity;
@end
NS_ASSUME_NONNULL_END

View File

@@ -19,9 +19,9 @@ - (instancetype)init {
- (void)blendView:(id)view forPropName:(NSString *)name propValue:(id)prop {
if ([name isEqualToString:@"gravity"]) {
self.gravity = [(NSNumber *)prop integerValue];
self.gravity = [(NSNumber *) prop integerValue];
} else if ([name isEqualToString:@"space"]) {
self.space = [(NSNumber *)prop floatValue];
self.space = [(NSNumber *) prop floatValue];
} else {
[super blendView:view forPropName:name propValue:prop];
}
@@ -33,15 +33,15 @@ - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutcon
DoricLog(@"blend VLayout child error,layout params not match");
return;
}
VHLayoutParams *params = (VHLayoutParams *)child.layoutParams;
NSDictionary *margin = [layoutconfig objectForKey:@"margin"];
VHLayoutParams *params = (VHLayoutParams *) child.layoutParams;
NSDictionary *margin = layoutconfig[@"margin"];
if (margin) {
params.margin.top = [(NSNumber *)[margin objectForKey:@"top"] floatValue];
params.margin.left = [(NSNumber *)[margin objectForKey:@"left"] floatValue];
params.margin.right = [(NSNumber *)[margin objectForKey:@"right"] floatValue];
params.margin.bottom = [(NSNumber *)[margin objectForKey:@"bottom"] floatValue];
params.margin.top = [(NSNumber *) margin[@"top"] floatValue];
params.margin.left = [(NSNumber *) margin[@"left"] floatValue];
params.margin.right = [(NSNumber *) margin[@"right"] floatValue];
params.margin.bottom = [(NSNumber *) margin[@"bottom"] floatValue];
}
NSNumber *alignment = [layoutconfig objectForKey:@"alignment"];
NSNumber *alignment = layoutconfig[@"alignment"];
if (alignment) {
params.alignment = [alignment integerValue];
}
@@ -54,7 +54,7 @@ - (LayoutParams *)generateDefaultLayoutParams {
- (void)measureByParent:(DoricGroupNode *)parent {
DoricLayoutDesc widthSpec = self.layoutParams.width;
DoricLayoutDesc heightSpec = self.layoutParams.height;
CGFloat maxWidth = 0,maxHeight = 0;
CGFloat maxWidth = 0, maxHeight = 0;
for (DoricViewNode *child in self.indexedChildren) {
[child measureByParent:self];
CGFloat placeWidth = child.measuredWidth;
@@ -63,14 +63,14 @@ - (void)measureByParent:(DoricGroupNode *)parent {
maxHeight += placeHeight + self.space;
}
maxHeight -= self.space;
self.desiredWidth = maxWidth;
self.desiredHeight = maxHeight;
if (widthSpec == LAYOUT_WRAP_CONTENT) {
self.width = maxWidth;
}
if (heightSpec == LAYOUT_WRAP_CONTENT) {
self.height = maxHeight;
}
@@ -90,10 +90,10 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
} else if ((self.gravity & BOTTOM) == BOTTOM) {
yStart = self.height - self.desiredHeight;
} else if ((self.gravity & CENTER_Y) == CENTER_Y) {
yStart = (self.height -self.desiredHeight)/2;
yStart = (self.height - self.desiredHeight) / 2;
}
for (DoricViewNode *child in self.indexedChildren) {
if (child.layoutParams.width == LAYOUT_MATCH_PARENT) {
child.width = self.width;
@@ -102,16 +102,16 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
child.height = self.height;
}
if ([child.layoutParams isKindOfClass:VHLayoutParams.class]) {
VHLayoutParams *layoutParams = (VHLayoutParams *)child.layoutParams;
VHLayoutParams *layoutParams = (VHLayoutParams *) child.layoutParams;
DoricGravity gravity = layoutParams.alignment | self.gravity;
if ((gravity & LEFT) == LEFT) {
child.left = 0;
} else if ((gravity & RIGHT) == RIGHT) {
child.right = self.width;
} else if ((gravity & CENTER_X) == CENTER_X) {
child.centerX = self.width/2;
child.centerX = self.width / 2;
}
}
}
child.top = yStart;
yStart = child.bottom + self.space;
[child layoutByParent:self];

View File

@@ -7,7 +7,7 @@
#import "UIView+Doric.h"
typedef NS_ENUM(NSInteger,DoricGravity) {
typedef NS_ENUM(NSInteger, DoricGravity) {
SPECIFIED = 1,
START = 1 << 1,
END = 1 << 2,
@@ -22,7 +22,7 @@ typedef NS_ENUM(NSInteger,DoricGravity) {
CENTER = CENTER_X | CENTER_Y,
};
typedef NS_ENUM(NSInteger,DoricLayoutDesc) {
typedef NS_ENUM(NSInteger, DoricLayoutDesc) {
LAYOUT_ABSOLUTE = 0,
LAYOUT_MATCH_PARENT = -1,
LAYOUT_WRAP_CONTENT = -2,
@@ -30,51 +30,50 @@ typedef NS_ENUM(NSInteger,DoricLayoutDesc) {
NS_ASSUME_NONNULL_BEGIN
@interface DoricRect :NSObject
@property (nonatomic) CGFloat left;
@property (nonatomic) CGFloat right;
@property (nonatomic) CGFloat top;
@property (nonatomic) CGFloat bottom;
@interface DoricRect : NSObject
@property(nonatomic) CGFloat left;
@property(nonatomic) CGFloat right;
@property(nonatomic) CGFloat top;
@property(nonatomic) CGFloat bottom;
@end
@interface LayoutParams : NSObject
@property (nonatomic) DoricLayoutDesc width;
@property (nonatomic) DoricLayoutDesc height;
@property(nonatomic) DoricLayoutDesc width;
@property(nonatomic) DoricLayoutDesc height;
@end
@interface MarginLayoutParams : LayoutParams
@property (nonatomic,strong) DoricRect *margin;
@property(nonatomic, strong) DoricRect *margin;
@end
@interface StackLayoutParams : LayoutParams
@property (nonatomic) DoricGravity alignment;
@property(nonatomic) DoricGravity alignment;
@end
@interface VHLayoutParams : MarginLayoutParams
@property (nonatomic) DoricGravity alignment;
@property (nonatomic) NSInteger weight;
@property(nonatomic) DoricGravity alignment;
@property(nonatomic) NSInteger weight;
@end
@interface UIView(DoricContainer)
@interface UIView (DoricContainer)
@property (nonatomic,strong) LayoutParams *layoutParams;
@property(nonatomic, strong) LayoutParams *layoutParams;
- (void) layout;
- (void)layout;
- (void) measure;
- (void)measure;
@end
@interface Stack : UIView
@property (nonatomic) DoricGravity gravity;
@property(nonatomic) DoricGravity gravity;
@end
@interface LinearLayout : UIView
@property (nonatomic) DoricGravity gravity;
@property (nonatomic) CGFloat space;
@property(nonatomic) DoricGravity gravity;
@property(nonatomic) CGFloat space;
@end

View File

@@ -10,7 +10,7 @@
@implementation DoricRect
- (instancetype)init {
if (self = [super init]) {
if (self = [super init]) {
_left = 0;
_right = 0;
_top = 0;
@@ -22,32 +22,35 @@ - (instancetype)init {
@implementation LayoutParams
- (instancetype)init {
if (self = [super init]) {
if (self = [super init]) {
_width = LAYOUT_WRAP_CONTENT;
_height = LAYOUT_WRAP_CONTENT;
}
return self;
}
@end
@implementation MarginLayoutParams
- (instancetype)init {
if (self = [super init]) {
if (self = [super init]) {
_margin = [[DoricRect alloc] init];
}
return self;
}@end
}
@end
@implementation StackLayoutParams
- (instancetype)init {
if (self = [super init]) {
if (self = [super init]) {
_alignment = 0;
}
return self;
}@end
}
@end
@implementation VHLayoutParams
- (instancetype)init {
if (self = [super init]) {
if (self = [super init]) {
_alignment = 0;
_weight = 0;
}
@@ -56,7 +59,7 @@ - (instancetype)init {
@end
@implementation UIView(DoricContainer)
@implementation UIView (DoricContainer)
- (LayoutParams *)layoutParams {
return objc_getAssociatedObject(self, _cmd);
@@ -67,12 +70,12 @@ - (void)setLayoutParams:(LayoutParams *)layoutParams {
}
- (void)layout {
}
- (void)measure {
if(self.layoutParams) {
if (self.layoutParams) {
}
}
@end

View File

@@ -13,32 +13,32 @@
NS_ASSUME_NONNULL_BEGIN
@class DoricGroupNode;
@interface DoricViewNode <V:UIView *>: DoricContextHolder
@interface DoricViewNode <V:UIView *> : DoricContextHolder
@property (nonatomic,strong) V view;
@property(nonatomic, strong) V view;
@property (nonatomic,weak) DoricGroupNode *parent;
@property (nonatomic) NSInteger index;
@property(nonatomic, weak) DoricGroupNode *parent;
@property(nonatomic) NSInteger index;
@property (nonatomic,strong) NSString *viewId;
@property(nonatomic, strong) NSString *viewId;
@property (nonatomic,strong) LayoutParams *layoutParams;
@property(nonatomic, strong) LayoutParams *layoutParams;
@property (nonatomic,strong,readonly) NSArray<NSString *> *idList;
@property(nonatomic, strong, readonly) NSArray<NSString *> *idList;
@property (nonatomic) CGFloat x;
@property (nonatomic) CGFloat y;
@property (nonatomic) CGFloat width;
@property (nonatomic) CGFloat height;
@property (nonatomic) CGFloat centerX;
@property (nonatomic) CGFloat centerY;
@property (nonatomic) CGFloat top;
@property (nonatomic) CGFloat left;
@property (nonatomic) CGFloat right;
@property (nonatomic) CGFloat bottom;
@property (nonatomic,readonly) CGFloat measuredWidth;
@property (nonatomic,readonly) CGFloat measuredHeight;
@property(nonatomic) CGFloat x;
@property(nonatomic) CGFloat y;
@property(nonatomic) CGFloat width;
@property(nonatomic) CGFloat height;
@property(nonatomic) CGFloat centerX;
@property(nonatomic) CGFloat centerY;
@property(nonatomic) CGFloat top;
@property(nonatomic) CGFloat left;
@property(nonatomic) CGFloat right;
@property(nonatomic) CGFloat bottom;
@property(nonatomic, readonly) CGFloat measuredWidth;
@property(nonatomic, readonly) CGFloat measuredHeight;
- (V)build:(NSDictionary *)props;
@@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)blendView:(V)view forPropName:(NSString *)name propValue:(id)prop;
- (void)callJSResponse:(NSString *)funcId,...;
- (void)callJSResponse:(NSString *)funcId, ...;
- (void)measureByParent:(DoricGroupNode *)parent;

View File

@@ -12,62 +12,62 @@
#import "DoricConstant.h"
void DoricAddEllipticArcPath(CGMutablePathRef path,
CGPoint origin,
CGFloat radius,
CGFloat startAngle,
CGFloat endAngle) {
CGPoint origin,
CGFloat radius,
CGFloat startAngle,
CGFloat endAngle) {
CGAffineTransform t = CGAffineTransformMakeTranslation(origin.x, origin.y);
CGPathAddArc(path, &t, 0, 0, radius, startAngle, endAngle, NO);
}
CGPathRef DoricCreateRoundedRectPath(CGRect bounds,
CGFloat leftTop,
CGFloat rightTop,
CGFloat rightBottom,
CGFloat leftBottom) {
CGFloat leftTop,
CGFloat rightTop,
CGFloat rightBottom,
CGFloat leftBottom) {
const CGFloat minX = CGRectGetMinX(bounds);
const CGFloat minY = CGRectGetMinY(bounds);
const CGFloat maxX = CGRectGetMaxX(bounds);
const CGFloat maxY = CGRectGetMaxY(bounds);
CGMutablePathRef path = CGPathCreateMutable();
DoricAddEllipticArcPath(path, (CGPoint){
minX + leftTop, minY + leftTop
DoricAddEllipticArcPath(path, (CGPoint) {
minX + leftTop, minY + leftTop
}, leftTop, M_PI, 3 * M_PI_2);
DoricAddEllipticArcPath(path, (CGPoint){
maxX - rightTop, minY + rightTop
DoricAddEllipticArcPath(path, (CGPoint) {
maxX - rightTop, minY + rightTop
}, rightTop, 3 * M_PI_2, 0);
DoricAddEllipticArcPath(path, (CGPoint){
maxX - rightBottom, maxY -rightBottom
DoricAddEllipticArcPath(path, (CGPoint) {
maxX - rightBottom, maxY - rightBottom
}, rightBottom, 0, M_PI_2);
DoricAddEllipticArcPath(path, (CGPoint){
minX + leftBottom, maxY - leftBottom
DoricAddEllipticArcPath(path, (CGPoint) {
minX + leftBottom, maxY - leftBottom
}, leftBottom, M_PI_2, M_PI);
CGPathCloseSubpath(path);
return path;
}
@interface DoricViewNode()
@property (nonatomic,strong) NSMutableDictionary *callbackIds;
@interface DoricViewNode ()
@property(nonatomic, strong) NSMutableDictionary *callbackIds;
@end
@implementation DoricViewNode
- (instancetype)initWithContext:(DoricContext *)doricContext {
if(self = [super initWithContext:doricContext]) {
if (self = [super initWithContext:doricContext]) {
_callbackIds = [[NSMutableDictionary alloc] init];
}
return self;
}
- (UIView *)build:(NSDictionary *)props {
return [[UIView alloc] init];
}
- (void)blend:(NSDictionary *)props {
if(self.view == nil) {
if (self.view == nil) {
self.view = [self build:props];
}
for (NSString *key in props) {
@@ -77,56 +77,56 @@ - (void)blend:(NSDictionary *)props {
}
- (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop {
if([name isEqualToString:@"width"]) {
NSNumber *width = (NSNumber *)prop;
if ([name isEqualToString:@"width"]) {
NSNumber *width = (NSNumber *) prop;
if ([width integerValue] < 0) {
self.layoutParams.width = [width integerValue];
} else {
self.layoutParams.width = LAYOUT_ABSOLUTE;
view.width = [width floatValue];
}
} else if([name isEqualToString:@"height"]) {
NSNumber *height = (NSNumber *)prop;
} else if ([name isEqualToString:@"height"]) {
NSNumber *height = (NSNumber *) prop;
if ([height integerValue] < 0) {
self.layoutParams.height = [height integerValue];
} else {
self.layoutParams.height = LAYOUT_ABSOLUTE;
view.height = [height floatValue];
}
} else if([name isEqualToString:@"x"]) {
view.x = [(NSNumber *)prop floatValue];
} else if([name isEqualToString:@"y"]) {
view.y = [(NSNumber *)prop floatValue];
} else if([name isEqualToString:@"bgColor"]) {
} else if ([name isEqualToString:@"x"]) {
view.x = [(NSNumber *) prop floatValue];
} else if ([name isEqualToString:@"y"]) {
view.y = [(NSNumber *) prop floatValue];
} else if ([name isEqualToString:@"bgColor"]) {
view.backgroundColor = DoricColor(prop);
} else if([name isEqualToString:@"layoutConfig"]) {
if(self.parent && [prop isKindOfClass:[NSDictionary class]]){
} else if ([name isEqualToString:@"layoutConfig"]) {
if (self.parent && [prop isKindOfClass:[NSDictionary class]]) {
[self.parent blendChild:self layoutConfig:prop];
}
} else if([name isEqualToString:@"onClick"]) {
} else if ([name isEqualToString:@"onClick"]) {
[self.callbackIds setObject:prop forKey:@"onClick"];
view.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClick:)];
UITapGestureRecognizer *tapGesturRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClick:)];
[view addGestureRecognizer:tapGesturRecognizer];
} else if([name isEqualToString:@"border"]) {
} else if ([name isEqualToString:@"border"]) {
NSDictionary *dic = prop;
CGFloat width = [(NSNumber *)[dic objectForKey:@"width"] floatValue];
UIColor *color = DoricColor((NSNumber *)[dic objectForKey:@"color"]);
CGFloat width = [(NSNumber *) [dic objectForKey:@"width"] floatValue];
UIColor *color = DoricColor((NSNumber *) [dic objectForKey:@"color"]);
view.layer.borderWidth = width;
view.layer.borderColor = color.CGColor;
} else if([name isEqualToString:@"corners"]) {
if([prop isKindOfClass:NSNumber.class]) {
view.layer.cornerRadius = [(NSNumber *)prop floatValue];
} else if([prop isKindOfClass:NSDictionary.class]) {
} else if ([name isEqualToString:@"corners"]) {
if ([prop isKindOfClass:NSNumber.class]) {
view.layer.cornerRadius = [(NSNumber *) prop floatValue];
} else if ([prop isKindOfClass:NSDictionary.class]) {
NSDictionary *dic = prop;
CGFloat leftTop = [(NSNumber *)[dic objectForKey:@"leftTop"] floatValue];
CGFloat rightTop = [(NSNumber *)[dic objectForKey:@"rightTop"] floatValue];
CGFloat rightBottom = [(NSNumber *)[dic objectForKey:@"rightBottom"] floatValue];
CGFloat leftBottom = [(NSNumber *)[dic objectForKey:@"leftBottom"] floatValue];
CGFloat leftTop = [(NSNumber *) [dic objectForKey:@"leftTop"] floatValue];
CGFloat rightTop = [(NSNumber *) [dic objectForKey:@"rightTop"] floatValue];
CGFloat rightBottom = [(NSNumber *) [dic objectForKey:@"rightBottom"] floatValue];
CGFloat leftBottom = [(NSNumber *) [dic objectForKey:@"leftBottom"] floatValue];
CALayer *mask = nil;
if(ABS(leftTop - rightTop) > CGFLOAT_MIN
||ABS(leftTop - rightBottom) > CGFLOAT_MIN
||ABS(leftTop - leftBottom) > CGFLOAT_MIN) {
if (ABS(leftTop - rightTop) > CGFLOAT_MIN
|| ABS(leftTop - rightBottom) > CGFLOAT_MIN
|| ABS(leftTop - leftBottom) > CGFLOAT_MIN) {
view.layer.cornerRadius = 0;
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
CGPathRef path = DoricCreateRoundedRectPath(self.view.bounds, leftTop, rightTop, rightBottom, leftBottom);
@@ -138,15 +138,15 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
}
view.layer.mask = mask;
}
} else if([name isEqualToString:@"shadow"]) {
} else if ([name isEqualToString:@"shadow"]) {
NSDictionary *dic = prop;
CGFloat opacity = [(NSNumber *)[dic objectForKey:@"opacity"] floatValue];
CGFloat opacity = [(NSNumber *) [dic objectForKey:@"opacity"] floatValue];
if (opacity > CGFLOAT_MIN) {
view.clipsToBounds = NO;
UIColor *color = DoricColor((NSNumber *)[dic objectForKey:@"color"]);
UIColor *color = DoricColor((NSNumber *) [dic objectForKey:@"color"]);
view.layer.shadowColor = color.CGColor;
view.layer.shadowRadius = [(NSNumber *)[dic objectForKey:@"radius"] floatValue];
view.layer.shadowOffset = CGSizeMake([(NSNumber *)[dic objectForKey:@"offsetX"] floatValue],[(NSNumber *)[dic objectForKey:@"offsetY"] floatValue]);
view.layer.shadowRadius = [(NSNumber *) [dic objectForKey:@"radius"] floatValue];
view.layer.shadowOffset = CGSizeMake([(NSNumber *) [dic objectForKey:@"offsetX"] floatValue], [(NSNumber *) [dic objectForKey:@"offsetY"] floatValue]);
view.layer.shadowOpacity = opacity;
} else {
view.clipsToBounds = YES;
@@ -158,20 +158,20 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
}
- (void)onClick:(UIView *)view {
[self callJSResponse:[self.callbackIds objectForKey:@"onClick"],nil];
[self callJSResponse:[self.callbackIds objectForKey:@"onClick"], nil];
}
- (CGFloat)measuredWidth {
if ([self.layoutParams isKindOfClass: MarginLayoutParams.class]) {
MarginLayoutParams *marginParams = (MarginLayoutParams *)self.layoutParams;
if ([self.layoutParams isKindOfClass:MarginLayoutParams.class]) {
MarginLayoutParams *marginParams = (MarginLayoutParams *) self.layoutParams;
return self.width + marginParams.margin.left + marginParams.margin.right;
}
return self.width;
}
- (CGFloat)measuredHeight {
if ([self.layoutParams isKindOfClass: MarginLayoutParams.class]) {
MarginLayoutParams *marginParams = (MarginLayoutParams *)self.layoutParams;
if ([self.layoutParams isKindOfClass:MarginLayoutParams.class]) {
MarginLayoutParams *marginParams = (MarginLayoutParams *) self.layoutParams;
return self.height + marginParams.margin.top + marginParams.margin.bottom;
}
return self.height;
@@ -186,7 +186,7 @@ - (void)measureByParent:(DoricGroupNode *)parent {
}
- (void)layoutByParent:(DoricGroupNode *)parent {
}
- (NSArray<NSString *> *)idList {
@@ -196,11 +196,11 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
[ret addObject:node.viewId];
node = node.parent;
} while (node && ![node isKindOfClass:[DoricRootNode class]]);
return [[ret reverseObjectEnumerator] allObjects];
}
- (void)callJSResponse:(NSString *)funcId,... {
- (void)callJSResponse:(NSString *)funcId, ... {
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:self.idList];
[array addObject:funcId];
@@ -216,88 +216,88 @@ - (void)callJSResponse:(NSString *)funcId,... {
+ (DoricViewNode *)create:(DoricContext *)context withType:(NSString *)type {
DoricRegistry *registry = context.driver.registry;
Class clz = [registry acquireViewNode:type];
Class clz = [registry acquireViewNode:type];
return [[clz alloc] initWithContext:context];
}
- (CGFloat)x {
return ((UIView *)self.view).x;
return ((UIView *) self.view).x;
}
- (CGFloat)y {
return ((UIView *)self.view).y;
return ((UIView *) self.view).y;
}
- (CGFloat)width {
return ((UIView *)self.view).width;
return ((UIView *) self.view).width;
}
- (CGFloat)height {
return ((UIView *)self.view).height;
return ((UIView *) self.view).height;
}
- (CGFloat)top {
return ((UIView *)self.view).top;
return ((UIView *) self.view).top;
}
- (CGFloat)bottom {
return ((UIView *)self.view).bottom;
return ((UIView *) self.view).bottom;
}
- (CGFloat)left {
return ((UIView *)self.view).left;
return ((UIView *) self.view).left;
}
- (CGFloat)right {
return ((UIView *)self.view).right;
return ((UIView *) self.view).right;
}
- (CGFloat)centerX {
return ((UIView *)self.view).centerX;
return ((UIView *) self.view).centerX;
}
- (CGFloat)centerY {
return ((UIView *)self.view).centerY;
return ((UIView *) self.view).centerY;
}
- (void)setX:(CGFloat)x {
((UIView *)self.view).x = x;
((UIView *) self.view).x = x;
}
- (void)setY:(CGFloat)y {
((UIView *)self.view).y = y;
((UIView *) self.view).y = y;
}
- (void)setWidth:(CGFloat)width {
((UIView *)self.view).width = width;
((UIView *) self.view).width = width;
}
- (void)setHeight:(CGFloat)height {
((UIView *)self.view).height = height;
((UIView *) self.view).height = height;
}
- (void)setLeft:(CGFloat)left {
((UIView *)self.view).left = left;
((UIView *) self.view).left = left;
}
- (void)setRight:(CGFloat)right {
((UIView *)self.view).right = right;
((UIView *) self.view).right = right;
}
- (void)setTop:(CGFloat)top {
((UIView *)self.view).top = top;
((UIView *) self.view).top = top;
}
- (void)setBottom:(CGFloat)bottom {
((UIView *)self.view).bottom = bottom;
((UIView *) self.view).bottom = bottom;
}
- (void)setCenterX:(CGFloat)centerX {
((UIView *)self.view).centerX = centerX;
((UIView *) self.view).centerX = centerX;
}
- (void)setCenterY:(CGFloat)centerY {
((UIView *)self.view).centerY = centerY;
((UIView *) self.view).centerY = centerY;
}
- (void)requestLayout {