feat:rename vlayout and hlayout

This commit is contained in:
pengfei.zhou 2019-10-23 20:11:24 +08:00
parent 4b1a982e85
commit c9f1f099ae
7 changed files with 32 additions and 40 deletions

View File

@ -22,5 +22,5 @@
#import "DoricGroupNode.h" #import "DoricGroupNode.h"
@interface DoricHLayoutNode : DoricGroupNode<HLayout *, DoricLinearConfig *> @interface DoricHLayoutNode : DoricGroupNode<DoricHLayoutView *, DoricLinearConfig *>
@end @end

View File

@ -24,11 +24,11 @@
#import "DoricUtil.h" #import "DoricUtil.h"
@implementation DoricHLayoutNode @implementation DoricHLayoutNode
- (HLayout *)build:(NSDictionary *)props { - (DoricHLayoutView *)build:(NSDictionary *)props {
return [HLayout new]; return [DoricHLayoutView new];
} }
- (void)blendView:(HLayout *)view forPropName:(NSString *)name propValue:(id)prop { - (void)blendView:(DoricHLayoutView *)view forPropName:(NSString *)name propValue:(id)prop {
if ([name isEqualToString:@"gravity"]) { if ([name isEqualToString:@"gravity"]) {
view.gravity = (DoricGravity) [(NSNumber *) prop integerValue]; view.gravity = (DoricGravity) [(NSNumber *) prop integerValue];
} else if ([name isEqualToString:@"space"]) { } else if ([name isEqualToString:@"space"]) {
@ -41,7 +41,7 @@ - (void)blendView:(HLayout *)view forPropName:(NSString *)name propValue:(id)pro
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutConfig { - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutConfig {
[super blendChild:child layoutConfig:layoutConfig]; [super blendChild:child layoutConfig:layoutConfig];
if (![child.layoutConfig isKindOfClass:DoricLinearConfig.class]) { if (![child.layoutConfig isKindOfClass:DoricLinearConfig.class]) {
DoricLog(@"blend HLayout child error,layout params not match"); DoricLog(@"blend DoricHLayoutView child error,layout params not match");
return; return;
} }
DoricLinearConfig *params = (DoricLinearConfig *) child.layoutConfig; DoricLinearConfig *params = (DoricLinearConfig *) child.layoutConfig;

View File

@ -89,29 +89,21 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
@property(nonatomic, assign) DoricGravity gravity; @property(nonatomic, assign) DoricGravity gravity;
@end @end
@interface LinearLayout : DoricLayoutContainer<DoricLinearConfig *> @interface DoricLinearView : DoricLayoutContainer<DoricLinearConfig *>
@property(nonatomic, assign) DoricGravity gravity; @property(nonatomic, assign) DoricGravity gravity;
@property(nonatomic, assign) CGFloat space; @property(nonatomic, assign) CGFloat space;
@end @end
@interface VLayout : LinearLayout @interface DoricVLayoutView : DoricLinearView
@end @end
@interface HLayout : LinearLayout @interface DoricHLayoutView : DoricLinearView
@end @end
@interface UIView (LayoutConfig) @interface UIView (DoricLayoutConfig)
@property(nonatomic, strong) DoricLayoutConfig *layoutConfig; @property(nonatomic, strong) DoricLayoutConfig *layoutConfig;
@property(nonatomic, copy) NSString *tagString; @property(nonatomic, copy) NSString *tagString;
- (UIView *)viewWithTagString:(NSString *)tagString; - (UIView *)viewWithTagString:(NSString *)tagString;
@end @end
VLayout *vLayout(NSArray <__kindof UIView *> *views);
HLayout *hLayout(NSArray <__kindof UIView *> *views);
VLayout *vLayoutWithBlock(NSArray <UIView *(^)()> *blocks);
HLayout *hLayoutWithBlock(NSArray <UIView *(^)()> *blocks);

View File

@ -107,8 +107,8 @@ - (DoricLayoutConfig *)configForChild:(UIView *)child {
} }
- (void)requestLayout { - (void)requestLayout {
if ([self.superview isKindOfClass:[LinearLayout class]]) { if ([self.superview isKindOfClass:[DoricLinearView class]]) {
[(LinearLayout *) self.superview requestLayout]; [(DoricLinearView *) self.superview requestLayout];
return; return;
} }
if (self.waitingLayout) { if (self.waitingLayout) {
@ -218,13 +218,13 @@ - (void)layout {
} }
@end @end
@interface LinearLayout () @interface DoricLinearView ()
@property(nonatomic, assign) CGFloat contentWidth; @property(nonatomic, assign) CGFloat contentWidth;
@property(nonatomic, assign) CGFloat contentHeight; @property(nonatomic, assign) CGFloat contentHeight;
@property(nonatomic, assign) NSUInteger contentWeight; @property(nonatomic, assign) NSUInteger contentWeight;
@end @end
@implementation LinearLayout @implementation DoricLinearView
- (DoricLinearConfig *)configForChild:(UIView *)child { - (DoricLinearConfig *)configForChild:(UIView *)child {
DoricLinearConfig *config = (DoricLinearConfig *) child.layoutConfig; DoricLinearConfig *config = (DoricLinearConfig *) child.layoutConfig;
if (!config) { if (!config) {
@ -234,7 +234,7 @@ - (DoricLinearConfig *)configForChild:(UIView *)child {
} }
@end @end
@implementation VLayout @implementation DoricVLayoutView
- (void)sizeToFit { - (void)sizeToFit {
DoricLayoutConfig *config = self.layoutConfig; DoricLayoutConfig *config = self.layoutConfig;
@ -330,11 +330,11 @@ - (void)layout {
} }
@end @end
@implementation HLayout @implementation DoricHLayoutView
- (void)sizeToFit { - (void)sizeToFit {
DoricLinearConfig *config; DoricLinearConfig *config;
if ([self.superview isKindOfClass:[LinearLayout class]]) { if ([self.superview isKindOfClass:[DoricLinearView class]]) {
config = [(LinearLayout *) self.superview configForChild:self]; config = [(DoricLinearView *) self.superview configForChild:self];
} else { } else {
config = (DoricLinearConfig *) self.layoutConfig; config = (DoricLinearConfig *) self.layoutConfig;
if (!config) { if (!config) {
@ -438,7 +438,7 @@ - (void)layout {
static const void *kLayoutConfig = &kLayoutConfig; static const void *kLayoutConfig = &kLayoutConfig;
static const void *kTagString = &kTagString; static const void *kTagString = &kTagString;
@implementation UIView (LayoutConfig) @implementation UIView (DoricLayoutConfig)
@dynamic layoutConfig; @dynamic layoutConfig;
- (void)setLayoutConfig:(DoricLayoutConfig *)layoutConfig { - (void)setLayoutConfig:(DoricLayoutConfig *)layoutConfig {
@ -466,8 +466,8 @@ - (UIView *)viewWithTagString:(NSString *)tagString {
@end @end
VLayout *vLayout(NSArray <__kindof UIView *> *views) { DoricVLayoutView *vLayout(NSArray <__kindof UIView *> *views) {
VLayout *layout = [[VLayout alloc] initWithFrame:CGRectZero]; DoricVLayoutView *layout = [[DoricVLayoutView alloc] initWithFrame:CGRectZero];
for (__kindof UIView *uiView in views) { for (__kindof UIView *uiView in views) {
[layout addSubview:uiView]; [layout addSubview:uiView];
} }
@ -475,8 +475,8 @@ - (UIView *)viewWithTagString:(NSString *)tagString {
return layout; return layout;
} }
HLayout *hLayout(NSArray <__kindof UIView *> *views) { DoricHLayoutView *hLayout(NSArray <__kindof UIView *> *views) {
HLayout *layout = [[HLayout alloc] initWithFrame:CGRectZero]; DoricHLayoutView *layout = [[DoricHLayoutView alloc] initWithFrame:CGRectZero];
for (__kindof UIView *uiView in views) { for (__kindof UIView *uiView in views) {
[layout addSubview:uiView]; [layout addSubview:uiView];
} }
@ -484,8 +484,8 @@ - (UIView *)viewWithTagString:(NSString *)tagString {
return layout; return layout;
} }
VLayout *vLayoutWithBlock(NSArray <UIView *(^)()> *blocks) { DoricVLayoutView *vLayoutWithBlock(NSArray <UIView *(^)()> *blocks) {
VLayout *layout = [[VLayout alloc] initWithFrame:CGRectZero]; DoricVLayoutView *layout = [[DoricVLayoutView alloc] initWithFrame:CGRectZero];
UIView *(^block)(); UIView *(^block)();
for (block in blocks) { for (block in blocks) {
[layout addSubview:block()]; [layout addSubview:block()];
@ -494,8 +494,8 @@ - (UIView *)viewWithTagString:(NSString *)tagString {
return layout; return layout;
} }
HLayout *hLayoutWithBlock(NSArray <UIView *(^)()> *blocks) { DoricHLayoutView *hLayoutWithBlock(NSArray <UIView *(^)()> *blocks) {
HLayout *layout = [[HLayout alloc] initWithFrame:CGRectZero]; DoricHLayoutView *layout = [[DoricHLayoutView alloc] initWithFrame:CGRectZero];
UIView *(^block)(); UIView *(^block)();
for (block in blocks) { for (block in blocks) {
[layout addSubview:block()]; [layout addSubview:block()];

View File

@ -44,7 +44,7 @@ - (DoricStackConfig *)generateDefaultLayoutParams {
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutConfig { - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutConfig {
[super blendChild:child layoutConfig:layoutConfig]; [super blendChild:child layoutConfig:layoutConfig];
if (![child.layoutConfig isKindOfClass:DoricStackConfig.class]) { if (![child.layoutConfig isKindOfClass:DoricStackConfig.class]) {
DoricLog(@"blend HLayout child error,layout params not match"); DoricLog(@"blend DoricHLayoutView child error,layout params not match");
return; return;
} }
DoricStackConfig *params = (DoricStackConfig *) child.layoutConfig; DoricStackConfig *params = (DoricStackConfig *) child.layoutConfig;

View File

@ -22,5 +22,5 @@
#import "DoricGroupNode.h" #import "DoricGroupNode.h"
@interface DoricVLayoutNode : DoricGroupNode<VLayout *, DoricLinearConfig *> @interface DoricVLayoutNode : DoricGroupNode<DoricVLayoutView *, DoricLinearConfig *>
@end @end

View File

@ -25,11 +25,11 @@
@implementation DoricVLayoutNode @implementation DoricVLayoutNode
- (VLayout *)build:(NSDictionary *)props { - (DoricVLayoutView *)build:(NSDictionary *)props {
return [VLayout new]; return [DoricVLayoutView new];
} }
- (void)blendView:(VLayout *)view forPropName:(NSString *)name propValue:(id)prop { - (void)blendView:(DoricVLayoutView *)view forPropName:(NSString *)name propValue:(id)prop {
if ([name isEqualToString:@"gravity"]) { if ([name isEqualToString:@"gravity"]) {
view.gravity = (DoricGravity) [(NSNumber *) prop integerValue]; view.gravity = (DoricGravity) [(NSNumber *) prop integerValue];
} else if ([name isEqualToString:@"space"]) { } else if ([name isEqualToString:@"space"]) {
@ -42,7 +42,7 @@ - (void)blendView:(VLayout *)view forPropName:(NSString *)name propValue:(id)pro
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig { - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig {
[super blendChild:child layoutConfig:layoutconfig]; [super blendChild:child layoutConfig:layoutconfig];
if (![child.layoutConfig isKindOfClass:DoricLinearConfig.class]) { if (![child.layoutConfig isKindOfClass:DoricLinearConfig.class]) {
DoricLog(@"blend VLayout child error,layout params not match"); DoricLog(@"blend DoricVLayoutView child error,layout params not match");
return; return;
} }
DoricLinearConfig *params = (DoricLinearConfig *) child.layoutConfig; DoricLinearConfig *params = (DoricLinearConfig *) child.layoutConfig;