rename add doric prefix
This commit is contained in:
parent
c2e3ef4f7e
commit
4b1a982e85
@ -13,7 +13,7 @@
|
||||
#import "DoricNativePlugin.h"
|
||||
#import "DoricRootNode.h"
|
||||
#import "DoricLocalServer.h"
|
||||
#import "DoricLinearLayout.h"
|
||||
#import "DoricLayouts.h"
|
||||
#import "DoricExtensions.h"
|
||||
|
||||
@interface ViewController ()
|
||||
@ -29,8 +29,8 @@ - (void)viewDidLoad {
|
||||
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"Snake" ofType:@"js"];
|
||||
NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
|
||||
self.doricContext = [[DoricContext alloc] initWithScript:jsContent source:@"test.js"];
|
||||
[self.doricContext.rootNode setupRootView:[[Stack new] also:^(Stack *it) {
|
||||
it.layoutConfig = [[StackLayoutConfig alloc] initWithWidth:LayoutParamAtMost height:LayoutParamAtMost];
|
||||
[self.doricContext.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) {
|
||||
it.layoutConfig = [[DoricStackConfig alloc] initWithWidth:DoricLayoutAtMost height:DoricLayoutAtMost];
|
||||
[self.view addSubview:it];
|
||||
}]];
|
||||
[self.doricContext initContextWithWidth:self.view.width height:self.view.height];
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricGroupNode <V:UIView *, P:LayoutConfig *> : DoricViewNode<V>
|
||||
@interface DoricGroupNode <V:UIView *, P:DoricLayoutConfig *> : DoricViewNode<V>
|
||||
|
||||
@property(nonatomic, strong) NSMutableDictionary *children;
|
||||
@property(nonatomic, strong) NSMutableArray *indexedChildren;
|
||||
|
@ -73,7 +73,7 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
|
||||
[tobeRemoved addObject:old];
|
||||
}
|
||||
|
||||
LayoutConfig *params = node.layoutConfig;
|
||||
DoricLayoutConfig *params = node.layoutConfig;
|
||||
if (params == nil) {
|
||||
params = [self generateDefaultLayoutParams];
|
||||
node.layoutConfig = params;
|
||||
@ -109,31 +109,31 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
|
||||
}
|
||||
}
|
||||
|
||||
- (LayoutConfig *)generateDefaultLayoutParams {
|
||||
LayoutConfig *params = [[LayoutConfig alloc] init];
|
||||
- (DoricLayoutConfig *)generateDefaultLayoutParams {
|
||||
DoricLayoutConfig *params = [[DoricLayoutConfig alloc] init];
|
||||
return params;
|
||||
}
|
||||
|
||||
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutConfig {
|
||||
LayoutConfig *params = child.layoutConfig;
|
||||
DoricLayoutConfig *params = child.layoutConfig;
|
||||
|
||||
[layoutConfig[@"widthSpec"] also:^(NSNumber *it) {
|
||||
if (it) {
|
||||
params.widthSpec = (LayoutParam) [it integerValue];
|
||||
params.widthSpec = (DoricLayoutSpec) [it integerValue];
|
||||
}
|
||||
}];
|
||||
|
||||
[layoutConfig[@"heightSpec"] also:^(NSNumber *it) {
|
||||
if (it) {
|
||||
params.heightSpec = (LayoutParam) [it integerValue];
|
||||
params.heightSpec = (DoricLayoutSpec) [it integerValue];
|
||||
}
|
||||
}];
|
||||
|
||||
if ([params isKindOfClass:MarginLayoutConfig.class]) {
|
||||
MarginLayoutConfig *marginParams = (MarginLayoutConfig *) params;
|
||||
if ([params isKindOfClass:DoricMarginConfig.class]) {
|
||||
DoricMarginConfig *marginParams = (DoricMarginConfig *) params;
|
||||
NSDictionary *margin = layoutConfig[@"margin"];
|
||||
if (margin) {
|
||||
marginParams.margin = MarginMake(
|
||||
marginParams.margin = DoricMarginMake(
|
||||
[(NSNumber *) margin[@"left"] floatValue],
|
||||
[(NSNumber *) margin[@"top"] floatValue],
|
||||
[(NSNumber *) margin[@"right"] floatValue],
|
||||
|
@ -22,5 +22,5 @@
|
||||
|
||||
#import "DoricGroupNode.h"
|
||||
|
||||
@interface DoricHLayoutNode : DoricGroupNode<HLayout *, LinearLayoutConfig *>
|
||||
@interface DoricHLayoutNode : DoricGroupNode<HLayout *, DoricLinearConfig *>
|
||||
@end
|
||||
|
@ -40,14 +40,14 @@ - (void)blendView:(HLayout *)view forPropName:(NSString *)name propValue:(id)pro
|
||||
|
||||
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutConfig {
|
||||
[super blendChild:child layoutConfig:layoutConfig];
|
||||
if (![child.layoutConfig isKindOfClass:LinearLayoutConfig.class]) {
|
||||
if (![child.layoutConfig isKindOfClass:DoricLinearConfig.class]) {
|
||||
DoricLog(@"blend HLayout child error,layout params not match");
|
||||
return;
|
||||
}
|
||||
LinearLayoutConfig *params = (LinearLayoutConfig *) child.layoutConfig;
|
||||
DoricLinearConfig *params = (DoricLinearConfig *) child.layoutConfig;
|
||||
NSDictionary *margin = layoutConfig[@"margin"];
|
||||
if (margin) {
|
||||
params.margin = MarginMake(
|
||||
params.margin = DoricMarginMake(
|
||||
[(NSNumber *) margin[@"left"] floatValue],
|
||||
[(NSNumber *) margin[@"top"] floatValue],
|
||||
[(NSNumber *) margin[@"right"] floatValue],
|
||||
@ -59,7 +59,7 @@ - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutCon
|
||||
}
|
||||
}
|
||||
|
||||
- (LinearLayoutConfig *)generateDefaultLayoutParams {
|
||||
return [[LinearLayoutConfig alloc] init];
|
||||
- (DoricLinearConfig *)generateDefaultLayoutParams {
|
||||
return [[DoricLinearConfig alloc] init];
|
||||
}
|
||||
@end
|
||||
|
@ -20,20 +20,20 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
struct Margin {
|
||||
struct DoricMargin {
|
||||
CGFloat left;
|
||||
CGFloat right;
|
||||
CGFloat top;
|
||||
CGFloat bottom;
|
||||
};
|
||||
typedef struct Margin Margin;
|
||||
typedef struct DoricMargin DoricMargin;
|
||||
|
||||
Margin MarginMake(CGFloat left, CGFloat top, CGFloat right, CGFloat bottom);
|
||||
DoricMargin DoricMarginMake(CGFloat left, CGFloat top, CGFloat right, CGFloat bottom);
|
||||
|
||||
typedef NS_ENUM(NSInteger, LayoutParam) {
|
||||
LayoutParamExact,
|
||||
LayoutParamWrapContent,
|
||||
LayoutParamAtMost,
|
||||
typedef NS_ENUM(NSInteger, DoricLayoutSpec) {
|
||||
DoricLayoutExact,
|
||||
DoricLayoutWrapContent,
|
||||
DoricLayoutAtMost,
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger, DoricGravity) {
|
||||
@ -51,32 +51,32 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
|
||||
CENTER = CENTER_X | CENTER_Y,
|
||||
};
|
||||
|
||||
@interface LayoutConfig : NSObject
|
||||
@property(nonatomic, assign) LayoutParam widthSpec;
|
||||
@property(nonatomic, assign) LayoutParam heightSpec;
|
||||
@interface DoricLayoutConfig : NSObject
|
||||
@property(nonatomic, assign) DoricLayoutSpec widthSpec;
|
||||
@property(nonatomic, assign) DoricLayoutSpec heightSpec;
|
||||
@property(nonatomic, assign) DoricGravity alignment;
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
- (instancetype)initWithWidth:(LayoutParam)width height:(LayoutParam)height;
|
||||
- (instancetype)initWithWidth:(DoricLayoutSpec)width height:(DoricLayoutSpec)height;
|
||||
|
||||
@end
|
||||
|
||||
@interface StackLayoutConfig : LayoutConfig
|
||||
@interface DoricStackConfig : DoricLayoutConfig
|
||||
@end
|
||||
|
||||
@interface MarginLayoutConfig : LayoutConfig
|
||||
@property(nonatomic) Margin margin;
|
||||
@interface DoricMarginConfig : DoricLayoutConfig
|
||||
@property(nonatomic) DoricMargin margin;
|
||||
|
||||
- (instancetype)initWithWidth:(LayoutParam)width height:(LayoutParam)height margin:(Margin)margin;
|
||||
- (instancetype)initWithWidth:(DoricLayoutSpec)width height:(DoricLayoutSpec)height margin:(DoricMargin)margin;
|
||||
@end
|
||||
|
||||
@interface LinearLayoutConfig : MarginLayoutConfig
|
||||
@interface DoricLinearConfig : DoricMarginConfig
|
||||
@property(nonatomic, assign) NSUInteger weight;
|
||||
@end
|
||||
|
||||
|
||||
@interface LayoutContainer <T :LayoutConfig *> : UIView
|
||||
@interface DoricLayoutContainer <T :DoricLayoutConfig *> : UIView
|
||||
|
||||
- (T)configForChild:(__kindof UIView *)child;
|
||||
|
||||
@ -85,11 +85,11 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
|
||||
- (void)requestLayout;
|
||||
@end
|
||||
|
||||
@interface Stack : LayoutContainer<StackLayoutConfig *>
|
||||
@interface DoricStackView : DoricLayoutContainer<DoricStackConfig *>
|
||||
@property(nonatomic, assign) DoricGravity gravity;
|
||||
@end
|
||||
|
||||
@interface LinearLayout : LayoutContainer<LinearLayoutConfig *>
|
||||
@interface LinearLayout : DoricLayoutContainer<DoricLinearConfig *>
|
||||
@property(nonatomic, assign) DoricGravity gravity;
|
||||
@property(nonatomic, assign) CGFloat space;
|
||||
@end
|
||||
@ -102,7 +102,7 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
|
||||
@end
|
||||
|
||||
@interface UIView (LayoutConfig)
|
||||
@property(nonatomic, strong) LayoutConfig *layoutConfig;
|
||||
@property(nonatomic, strong) DoricLayoutConfig *layoutConfig;
|
||||
@property(nonatomic, copy) NSString *tagString;
|
||||
|
||||
- (UIView *)viewWithTagString:(NSString *)tagString;
|
@ -17,12 +17,12 @@
|
||||
// Created by pengfei.zhou on 2019/10/23.
|
||||
//
|
||||
|
||||
#import "DoricLinearLayout.h"
|
||||
#import "DoricLayouts.h"
|
||||
#import <objc/runtime.h>
|
||||
#import "UIView+Doric.h"
|
||||
|
||||
Margin MarginMake(CGFloat left, CGFloat top, CGFloat right, CGFloat bottom) {
|
||||
Margin margin;
|
||||
DoricMargin DoricMarginMake(CGFloat left, CGFloat top, CGFloat right, CGFloat bottom) {
|
||||
DoricMargin margin;
|
||||
margin.left = left;
|
||||
margin.top = top;
|
||||
margin.right = right;
|
||||
@ -30,16 +30,16 @@ Margin MarginMake(CGFloat left, CGFloat top, CGFloat right, CGFloat bottom) {
|
||||
return margin;
|
||||
}
|
||||
|
||||
@implementation LayoutConfig
|
||||
@implementation DoricLayoutConfig
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_widthSpec = LayoutParamExact;
|
||||
_heightSpec = LayoutParamExact;
|
||||
_widthSpec = DoricLayoutExact;
|
||||
_heightSpec = DoricLayoutExact;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithWidth:(LayoutParam)width height:(LayoutParam)height {
|
||||
- (instancetype)initWithWidth:(DoricLayoutSpec)width height:(DoricLayoutSpec)height {
|
||||
if (self = [super init]) {
|
||||
_widthSpec = width;
|
||||
_heightSpec = height;
|
||||
@ -48,15 +48,15 @@ - (instancetype)initWithWidth:(LayoutParam)width height:(LayoutParam)height {
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation MarginLayoutConfig
|
||||
@implementation DoricMarginConfig
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_margin = MarginMake(0, 0, 0, 0);
|
||||
_margin = DoricMarginMake(0, 0, 0, 0);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithWidth:(LayoutParam)width height:(LayoutParam)height margin:(Margin)margin {
|
||||
- (instancetype)initWithWidth:(DoricLayoutSpec)width height:(DoricLayoutSpec)height margin:(DoricMargin)margin {
|
||||
if (self = [super initWithWidth:width height:height]) {
|
||||
_margin = margin;
|
||||
}
|
||||
@ -64,18 +64,18 @@ - (instancetype)initWithWidth:(LayoutParam)width height:(LayoutParam)height marg
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation StackLayoutConfig
|
||||
@implementation DoricStackConfig
|
||||
@end
|
||||
|
||||
@implementation LinearLayoutConfig
|
||||
@implementation DoricLinearConfig
|
||||
@end
|
||||
|
||||
|
||||
@interface LayoutContainer ()
|
||||
@interface DoricLayoutContainer ()
|
||||
@property(nonatomic, assign) BOOL waitingLayout;
|
||||
@end
|
||||
|
||||
@implementation LayoutContainer
|
||||
@implementation DoricLayoutContainer
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_waitingLayout = NO;
|
||||
@ -98,10 +98,10 @@ - (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
}
|
||||
|
||||
|
||||
- (LayoutConfig *)configForChild:(UIView *)child {
|
||||
LayoutConfig *config = child.layoutConfig;
|
||||
- (DoricLayoutConfig *)configForChild:(UIView *)child {
|
||||
DoricLayoutConfig *config = child.layoutConfig;
|
||||
if (!config) {
|
||||
config = [[LayoutConfig alloc] init];
|
||||
config = [[DoricLayoutConfig alloc] init];
|
||||
}
|
||||
return config;
|
||||
}
|
||||
@ -129,8 +129,8 @@ - (void)layoutSubviews {
|
||||
|
||||
- (void)layout {
|
||||
[self.subviews enumerateObjectsUsingBlock:^(__kindof UIView *child, NSUInteger idx, BOOL *stop) {
|
||||
if ([child isKindOfClass:[LayoutContainer class]]) {
|
||||
[(LayoutContainer *) child layout];
|
||||
if ([child isKindOfClass:[DoricLayoutContainer class]]) {
|
||||
[(DoricLayoutContainer *) child layout];
|
||||
}
|
||||
}];
|
||||
}
|
||||
@ -138,47 +138,47 @@ - (void)layout {
|
||||
@end
|
||||
|
||||
|
||||
@interface Stack ()
|
||||
@interface DoricStackView ()
|
||||
|
||||
@property(nonatomic, assign) CGFloat contentWidth;
|
||||
@property(nonatomic, assign) CGFloat contentHeight;
|
||||
@end
|
||||
|
||||
@implementation Stack
|
||||
- (StackLayoutConfig *)configForChild:(UIView *)child {
|
||||
StackLayoutConfig *config = (StackLayoutConfig *) child.layoutConfig;
|
||||
@implementation DoricStackView
|
||||
- (DoricStackConfig *)configForChild:(UIView *)child {
|
||||
DoricStackConfig *config = (DoricStackConfig *) child.layoutConfig;
|
||||
if (!config) {
|
||||
config = [[StackLayoutConfig alloc] init];
|
||||
config = [[DoricStackConfig alloc] init];
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
- (void)sizeToFit {
|
||||
LayoutConfig *config = self.layoutConfig;
|
||||
DoricLayoutConfig *config = self.layoutConfig;
|
||||
self.contentWidth = 0;
|
||||
self.contentHeight = 0;
|
||||
for (UIView *child in self.subviews) {
|
||||
if (child.isHidden) {
|
||||
continue;
|
||||
}
|
||||
StackLayoutConfig *childConfig = [self configForChild:child];
|
||||
if ([child isKindOfClass:[LayoutContainer class]]
|
||||
|| childConfig.widthSpec == LayoutParamWrapContent
|
||||
|| childConfig.heightSpec == LayoutParamWrapContent) {
|
||||
DoricStackConfig *childConfig = [self configForChild:child];
|
||||
if ([child isKindOfClass:[DoricLayoutContainer class]]
|
||||
|| childConfig.widthSpec == DoricLayoutWrapContent
|
||||
|| childConfig.heightSpec == DoricLayoutWrapContent) {
|
||||
[child sizeToFit];
|
||||
}
|
||||
self.contentWidth = MAX(self.contentWidth, child.width);
|
||||
self.contentHeight = MAX(self.contentHeight, child.height);
|
||||
}
|
||||
if (config.widthSpec == LayoutParamWrapContent) {
|
||||
if (config.widthSpec == DoricLayoutWrapContent) {
|
||||
self.width = self.contentWidth;
|
||||
} else if (config.widthSpec == LayoutParamAtMost) {
|
||||
} else if (config.widthSpec == DoricLayoutAtMost) {
|
||||
self.width = self.superview.width;
|
||||
}
|
||||
if (config.heightSpec == LayoutParamWrapContent) {
|
||||
if (config.heightSpec == DoricLayoutWrapContent) {
|
||||
self.height = self.contentHeight;
|
||||
} else if (config.heightSpec == LayoutParamAtMost) {
|
||||
} else if (config.heightSpec == DoricLayoutAtMost) {
|
||||
self.height = self.superview.height;
|
||||
}
|
||||
}
|
||||
@ -188,7 +188,7 @@ - (void)layout {
|
||||
if (child.isHidden) {
|
||||
continue;
|
||||
}
|
||||
StackLayoutConfig *childConfig = [self configForChild:child];
|
||||
DoricStackConfig *childConfig = [self configForChild:child];
|
||||
DoricGravity gravity = childConfig.alignment | self.gravity;
|
||||
if ((gravity & LEFT) == LEFT) {
|
||||
child.left = 0;
|
||||
@ -204,15 +204,15 @@ - (void)layout {
|
||||
} else if ((gravity & CENTER_Y) == CENTER_Y) {
|
||||
child.centerY = self.height / 2;
|
||||
}
|
||||
if (childConfig.widthSpec == LayoutParamAtMost) {
|
||||
if (childConfig.widthSpec == DoricLayoutAtMost) {
|
||||
child.width = self.width;
|
||||
}
|
||||
if (childConfig.heightSpec == LayoutParamAtMost) {
|
||||
if (childConfig.heightSpec == DoricLayoutAtMost) {
|
||||
child.height = self.height;
|
||||
}
|
||||
|
||||
if ([child isKindOfClass:[LayoutContainer class]]) {
|
||||
[(LayoutContainer *) child layout];
|
||||
if ([child isKindOfClass:[DoricLayoutContainer class]]) {
|
||||
[(DoricLayoutContainer *) child layout];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -225,10 +225,10 @@ @interface LinearLayout ()
|
||||
@end
|
||||
|
||||
@implementation LinearLayout
|
||||
- (LinearLayoutConfig *)configForChild:(UIView *)child {
|
||||
LinearLayoutConfig *config = (LinearLayoutConfig *) child.layoutConfig;
|
||||
- (DoricLinearConfig *)configForChild:(UIView *)child {
|
||||
DoricLinearConfig *config = (DoricLinearConfig *) child.layoutConfig;
|
||||
if (!config) {
|
||||
config = [[LinearLayoutConfig alloc] init];
|
||||
config = [[DoricLinearConfig alloc] init];
|
||||
}
|
||||
return config;
|
||||
}
|
||||
@ -237,7 +237,7 @@ - (LinearLayoutConfig *)configForChild:(UIView *)child {
|
||||
@implementation VLayout
|
||||
|
||||
- (void)sizeToFit {
|
||||
LayoutConfig *config = self.layoutConfig;
|
||||
DoricLayoutConfig *config = self.layoutConfig;
|
||||
self.contentWidth = 0;
|
||||
self.contentHeight = 0;
|
||||
self.contentWeight = 0;
|
||||
@ -245,10 +245,10 @@ - (void)sizeToFit {
|
||||
if (child.isHidden) {
|
||||
continue;
|
||||
}
|
||||
LinearLayoutConfig *childConfig = [self configForChild:child];
|
||||
if ([child isKindOfClass:[LayoutContainer class]]
|
||||
|| childConfig.widthSpec == LayoutParamWrapContent
|
||||
|| childConfig.heightSpec == LayoutParamWrapContent) {
|
||||
DoricLinearConfig *childConfig = [self configForChild:child];
|
||||
if ([child isKindOfClass:[DoricLayoutContainer class]]
|
||||
|| childConfig.widthSpec == DoricLayoutWrapContent
|
||||
|| childConfig.heightSpec == DoricLayoutWrapContent) {
|
||||
[child sizeToFit];
|
||||
}
|
||||
self.contentWidth = MAX(self.contentWidth, child.width + childConfig.margin.left + childConfig.margin.right);
|
||||
@ -256,14 +256,14 @@ - (void)sizeToFit {
|
||||
self.contentWeight += childConfig.weight;
|
||||
}
|
||||
self.contentHeight -= self.space;
|
||||
if (config.widthSpec == LayoutParamWrapContent) {
|
||||
if (config.widthSpec == DoricLayoutWrapContent) {
|
||||
self.width = self.contentWidth;
|
||||
} else if (config.widthSpec == LayoutParamAtMost) {
|
||||
} else if (config.widthSpec == DoricLayoutAtMost) {
|
||||
self.width = self.superview.width;
|
||||
}
|
||||
if (config.heightSpec == LayoutParamWrapContent) {
|
||||
if (config.heightSpec == DoricLayoutWrapContent) {
|
||||
self.height = self.contentHeight;
|
||||
} else if (config.heightSpec == LayoutParamAtMost) {
|
||||
} else if (config.heightSpec == DoricLayoutAtMost) {
|
||||
self.height = self.superview.height;
|
||||
}
|
||||
if (self.contentWeight) {
|
||||
@ -272,7 +272,7 @@ - (void)sizeToFit {
|
||||
if (child.isHidden) {
|
||||
continue;
|
||||
}
|
||||
LinearLayoutConfig *childConfig = [self configForChild:child];
|
||||
DoricLinearConfig *childConfig = [self configForChild:child];
|
||||
if (childConfig.weight) {
|
||||
child.height += remain / self.contentWeight * childConfig.weight;
|
||||
}
|
||||
@ -294,7 +294,7 @@ - (void)layout {
|
||||
if (child.isHidden) {
|
||||
continue;
|
||||
}
|
||||
LinearLayoutConfig *childConfig = [self configForChild:child];
|
||||
DoricLinearConfig *childConfig = [self configForChild:child];
|
||||
DoricGravity gravity = childConfig.alignment | self.gravity;
|
||||
if ((gravity & LEFT) == LEFT) {
|
||||
child.left = 0;
|
||||
@ -309,10 +309,10 @@ - (void)layout {
|
||||
child.right = self.width - childConfig.margin.right;
|
||||
}
|
||||
}
|
||||
if (childConfig.widthSpec == LayoutParamAtMost) {
|
||||
if (childConfig.widthSpec == DoricLayoutAtMost) {
|
||||
child.width = self.width;
|
||||
}
|
||||
if (childConfig.heightSpec == LayoutParamAtMost) {
|
||||
if (childConfig.heightSpec == DoricLayoutAtMost) {
|
||||
child.height = self.height - yStart - childConfig.margin.top - childConfig.margin.bottom - self.space;
|
||||
}
|
||||
if (childConfig.margin.top) {
|
||||
@ -323,8 +323,8 @@ - (void)layout {
|
||||
if (childConfig.margin.bottom) {
|
||||
yStart += childConfig.margin.bottom;
|
||||
}
|
||||
if ([child isKindOfClass:[LayoutContainer class]]) {
|
||||
[(LayoutContainer *) child layout];
|
||||
if ([child isKindOfClass:[DoricLayoutContainer class]]) {
|
||||
[(DoricLayoutContainer *) child layout];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -332,13 +332,13 @@ - (void)layout {
|
||||
|
||||
@implementation HLayout
|
||||
- (void)sizeToFit {
|
||||
LinearLayoutConfig *config;
|
||||
DoricLinearConfig *config;
|
||||
if ([self.superview isKindOfClass:[LinearLayout class]]) {
|
||||
config = [(LinearLayout *) self.superview configForChild:self];
|
||||
} else {
|
||||
config = (LinearLayoutConfig *) self.layoutConfig;
|
||||
config = (DoricLinearConfig *) self.layoutConfig;
|
||||
if (!config) {
|
||||
config = [[LinearLayoutConfig alloc] init];
|
||||
config = [[DoricLinearConfig alloc] init];
|
||||
}
|
||||
}
|
||||
self.contentWidth = 0;
|
||||
@ -348,10 +348,10 @@ - (void)sizeToFit {
|
||||
if (child.isHidden) {
|
||||
continue;
|
||||
}
|
||||
LinearLayoutConfig *childConfig = [self configForChild:child];
|
||||
if ([child isKindOfClass:[LayoutContainer class]]
|
||||
|| childConfig.widthSpec == LayoutParamWrapContent
|
||||
|| childConfig.heightSpec == LayoutParamWrapContent) {
|
||||
DoricLinearConfig *childConfig = [self configForChild:child];
|
||||
if ([child isKindOfClass:[DoricLayoutContainer class]]
|
||||
|| childConfig.widthSpec == DoricLayoutWrapContent
|
||||
|| childConfig.heightSpec == DoricLayoutWrapContent) {
|
||||
[child sizeToFit];
|
||||
}
|
||||
self.contentHeight = MAX(self.contentHeight, child.height + childConfig.margin.top + childConfig.margin.bottom);
|
||||
@ -359,14 +359,14 @@ - (void)sizeToFit {
|
||||
self.contentWeight += childConfig.weight;
|
||||
}
|
||||
self.contentWidth -= self.space;
|
||||
if (config.widthSpec == LayoutParamWrapContent) {
|
||||
if (config.widthSpec == DoricLayoutWrapContent) {
|
||||
self.width = self.contentWidth;
|
||||
} else if (config.widthSpec == LayoutParamAtMost) {
|
||||
} else if (config.widthSpec == DoricLayoutAtMost) {
|
||||
self.width = self.superview.width;
|
||||
}
|
||||
if (config.heightSpec == LayoutParamWrapContent) {
|
||||
if (config.heightSpec == DoricLayoutWrapContent) {
|
||||
self.height = self.contentHeight;
|
||||
} else if (config.heightSpec == LayoutParamAtMost) {
|
||||
} else if (config.heightSpec == DoricLayoutAtMost) {
|
||||
self.height = self.superview.height;
|
||||
}
|
||||
if (self.contentWeight) {
|
||||
@ -375,7 +375,7 @@ - (void)sizeToFit {
|
||||
if (child.isHidden) {
|
||||
continue;
|
||||
}
|
||||
LinearLayoutConfig *childConfig = [self configForChild:child];
|
||||
DoricLinearConfig *childConfig = [self configForChild:child];
|
||||
if (childConfig.weight) {
|
||||
child.width += remain / self.contentWeight * childConfig.weight;
|
||||
}
|
||||
@ -397,7 +397,7 @@ - (void)layout {
|
||||
if (child.isHidden) {
|
||||
continue;
|
||||
}
|
||||
LinearLayoutConfig *childConfig = [self configForChild:child];
|
||||
DoricLinearConfig *childConfig = [self configForChild:child];
|
||||
DoricGravity gravity = childConfig.alignment | self.gravity;
|
||||
if ((gravity & TOP) == TOP) {
|
||||
child.top = 0;
|
||||
@ -413,10 +413,10 @@ - (void)layout {
|
||||
}
|
||||
}
|
||||
|
||||
if (childConfig.heightSpec == LayoutParamAtMost) {
|
||||
if (childConfig.heightSpec == DoricLayoutAtMost) {
|
||||
child.height = self.height;
|
||||
}
|
||||
if (childConfig.widthSpec == LayoutParamAtMost) {
|
||||
if (childConfig.widthSpec == DoricLayoutAtMost) {
|
||||
child.width = self.width - xStart - childConfig.margin.right - childConfig.margin.left - self.space;
|
||||
}
|
||||
|
||||
@ -428,8 +428,8 @@ - (void)layout {
|
||||
if (childConfig.margin.right) {
|
||||
xStart += childConfig.margin.right;
|
||||
}
|
||||
if ([child isKindOfClass:[LayoutContainer class]]) {
|
||||
[(LayoutContainer *) child layout];
|
||||
if ([child isKindOfClass:[DoricLayoutContainer class]]) {
|
||||
[(DoricLayoutContainer *) child layout];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -441,11 +441,11 @@ - (void)layout {
|
||||
@implementation UIView (LayoutConfig)
|
||||
@dynamic layoutConfig;
|
||||
|
||||
- (void)setLayoutConfig:(LayoutConfig *)layoutConfig {
|
||||
- (void)setLayoutConfig:(DoricLayoutConfig *)layoutConfig {
|
||||
objc_setAssociatedObject(self, kLayoutConfig, layoutConfig, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
- (LayoutConfig *)layoutConfig {
|
||||
- (DoricLayoutConfig *)layoutConfig {
|
||||
return objc_getAssociatedObject(self, kLayoutConfig);
|
||||
}
|
||||
|
||||
@ -471,7 +471,7 @@ - (UIView *)viewWithTagString:(NSString *)tagString {
|
||||
for (__kindof UIView *uiView in views) {
|
||||
[layout addSubview:uiView];
|
||||
}
|
||||
layout.layoutConfig = [[LayoutConfig alloc] initWithWidth:LayoutParamWrapContent height:LayoutParamWrapContent];
|
||||
layout.layoutConfig = [[DoricLayoutConfig alloc] initWithWidth:DoricLayoutWrapContent height:DoricLayoutWrapContent];
|
||||
return layout;
|
||||
}
|
||||
|
||||
@ -480,7 +480,7 @@ - (UIView *)viewWithTagString:(NSString *)tagString {
|
||||
for (__kindof UIView *uiView in views) {
|
||||
[layout addSubview:uiView];
|
||||
}
|
||||
layout.layoutConfig = [[LayoutConfig alloc] initWithWidth:LayoutParamWrapContent height:LayoutParamWrapContent];
|
||||
layout.layoutConfig = [[DoricLayoutConfig alloc] initWithWidth:DoricLayoutWrapContent height:DoricLayoutWrapContent];
|
||||
return layout;
|
||||
}
|
||||
|
||||
@ -490,7 +490,7 @@ - (UIView *)viewWithTagString:(NSString *)tagString {
|
||||
for (block in blocks) {
|
||||
[layout addSubview:block()];
|
||||
}
|
||||
layout.layoutConfig = [[LayoutConfig alloc] initWithWidth:LayoutParamWrapContent height:LayoutParamWrapContent];
|
||||
layout.layoutConfig = [[DoricLayoutConfig alloc] initWithWidth:DoricLayoutWrapContent height:DoricLayoutWrapContent];
|
||||
return layout;
|
||||
}
|
||||
|
||||
@ -500,6 +500,6 @@ - (UIView *)viewWithTagString:(NSString *)tagString {
|
||||
for (block in blocks) {
|
||||
[layout addSubview:block()];
|
||||
}
|
||||
layout.layoutConfig = [[LayoutConfig alloc] initWithWidth:LayoutParamWrapContent height:LayoutParamWrapContent];
|
||||
layout.layoutConfig = [[DoricLayoutConfig alloc] initWithWidth:DoricLayoutWrapContent height:DoricLayoutWrapContent];
|
||||
return layout;
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricRootNode : DoricStackNode
|
||||
|
||||
- (void)setupRootView:(Stack *)view;
|
||||
- (void)setupRootView:(DoricStackView *)view;
|
||||
|
||||
- (void)render:(NSDictionary *)props;
|
||||
@end
|
||||
|
@ -23,7 +23,7 @@
|
||||
#import "DoricRootNode.h"
|
||||
|
||||
@implementation DoricRootNode
|
||||
- (void)setupRootView:(Stack *)view {
|
||||
- (void)setupRootView:(DoricStackView *)view {
|
||||
self.view = view;
|
||||
self.layoutConfig = view.layoutConfig;
|
||||
}
|
||||
|
@ -22,5 +22,5 @@
|
||||
|
||||
#import "DoricGroupNode.h"
|
||||
|
||||
@interface DoricStackNode : DoricGroupNode<Stack *, StackLayoutConfig *>
|
||||
@interface DoricStackNode : DoricGroupNode<DoricStackView *, DoricStackConfig *>
|
||||
@end
|
||||
|
@ -25,11 +25,11 @@
|
||||
|
||||
@implementation DoricStackNode
|
||||
|
||||
- (Stack *)build:(NSDictionary *)props {
|
||||
return [Stack new];
|
||||
- (DoricStackView *)build:(NSDictionary *)props {
|
||||
return [DoricStackView new];
|
||||
}
|
||||
|
||||
- (void)blendView:(Stack *)view forPropName:(NSString *)name propValue:(id)prop {
|
||||
- (void)blendView:(DoricStackView *)view forPropName:(NSString *)name propValue:(id)prop {
|
||||
if ([name isEqualToString:@"gravity"]) {
|
||||
view.gravity = (DoricGravity) [(NSNumber *) prop integerValue];
|
||||
} else {
|
||||
@ -37,17 +37,17 @@ - (void)blendView:(Stack *)view forPropName:(NSString *)name propValue:(id)prop
|
||||
}
|
||||
}
|
||||
|
||||
- (StackLayoutConfig *)generateDefaultLayoutParams {
|
||||
return [[StackLayoutConfig alloc] init];
|
||||
- (DoricStackConfig *)generateDefaultLayoutParams {
|
||||
return [[DoricStackConfig alloc] init];
|
||||
}
|
||||
|
||||
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutConfig {
|
||||
[super blendChild:child layoutConfig:layoutConfig];
|
||||
if (![child.layoutConfig isKindOfClass:StackLayoutConfig.class]) {
|
||||
if (![child.layoutConfig isKindOfClass:DoricStackConfig.class]) {
|
||||
DoricLog(@"blend HLayout child error,layout params not match");
|
||||
return;
|
||||
}
|
||||
StackLayoutConfig *params = (StackLayoutConfig *) child.layoutConfig;
|
||||
DoricStackConfig *params = (DoricStackConfig *) child.layoutConfig;
|
||||
NSNumber *alignment = layoutConfig[@"alignment"];
|
||||
if (alignment) {
|
||||
params.alignment = (DoricGravity) [alignment integerValue];
|
||||
|
@ -22,5 +22,5 @@
|
||||
|
||||
#import "DoricGroupNode.h"
|
||||
|
||||
@interface DoricVLayoutNode : DoricGroupNode<VLayout *, LinearLayoutConfig *>
|
||||
@interface DoricVLayoutNode : DoricGroupNode<VLayout *, DoricLinearConfig *>
|
||||
@end
|
||||
|
@ -41,14 +41,14 @@ - (void)blendView:(VLayout *)view forPropName:(NSString *)name propValue:(id)pro
|
||||
|
||||
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig {
|
||||
[super blendChild:child layoutConfig:layoutconfig];
|
||||
if (![child.layoutConfig isKindOfClass:LinearLayoutConfig.class]) {
|
||||
if (![child.layoutConfig isKindOfClass:DoricLinearConfig.class]) {
|
||||
DoricLog(@"blend VLayout child error,layout params not match");
|
||||
return;
|
||||
}
|
||||
LinearLayoutConfig *params = (LinearLayoutConfig *) child.layoutConfig;
|
||||
DoricLinearConfig *params = (DoricLinearConfig *) child.layoutConfig;
|
||||
NSDictionary *margin = layoutconfig[@"margin"];
|
||||
if (margin) {
|
||||
params.margin = MarginMake(
|
||||
params.margin = DoricMarginMake(
|
||||
[(NSNumber *) margin[@"left"] floatValue],
|
||||
[(NSNumber *) margin[@"top"] floatValue],
|
||||
[(NSNumber *) margin[@"right"] floatValue],
|
||||
@ -60,7 +60,7 @@ - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutcon
|
||||
}
|
||||
}
|
||||
|
||||
- (LinearLayoutConfig *)generateDefaultLayoutParams {
|
||||
return [[LinearLayoutConfig alloc] init];
|
||||
- (DoricLinearConfig *)generateDefaultLayoutParams {
|
||||
return [[DoricLinearConfig alloc] init];
|
||||
}
|
||||
@end
|
||||
|
@ -21,7 +21,7 @@
|
||||
//
|
||||
|
||||
#import "DoricContextHolder.h"
|
||||
#import "DoricLinearLayout.h"
|
||||
#import "DoricLayouts.h"
|
||||
#import "UIView+Doric.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@property(nonatomic, strong) NSString *viewId;
|
||||
|
||||
@property(nonatomic, strong) LayoutConfig *layoutConfig;
|
||||
@property(nonatomic, strong) DoricLayoutConfig *layoutConfig;
|
||||
|
||||
@property(nonatomic, strong, readonly) NSArray<NSString *> *idList;
|
||||
|
||||
|
Reference in New Issue
Block a user