iOS layout done
This commit is contained in:
parent
b0e34a316b
commit
5c1fc624ce
@ -17,7 +17,9 @@ - (instancetype)initWithContext:(DoricContext *)doricContext {
|
||||
return self;
|
||||
}
|
||||
- (UIView *)build:(NSDictionary *)props {
|
||||
return [[UIView alloc] init];
|
||||
UIView *ret = [[UIView alloc] init];
|
||||
ret.clipsToBounds = YES;
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop {
|
||||
|
@ -30,7 +30,7 @@ - (void)blendView:(id)view forPropName:(NSString *)name propValue:(id)prop {
|
||||
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig {
|
||||
[super blendChild:child layoutConfig:layoutconfig];
|
||||
if (![child.layoutParams isKindOfClass:VHLayoutParams.class]) {
|
||||
DoricLog(@"blend VLayout child error,layout params not match");
|
||||
DoricLog(@"blend HLayout child error,layout params not match");
|
||||
return;
|
||||
}
|
||||
VHLayoutParams *params = (VHLayoutParams *)child.layoutParams;
|
||||
@ -84,8 +84,8 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
|
||||
if (self.layoutParams.height == LAYOUT_MATCH_PARENT) {
|
||||
self.height = parent.height;
|
||||
}
|
||||
// layotu child
|
||||
CGFloat xStart = 0, yStart = 0;
|
||||
// layout child
|
||||
CGFloat xStart = 0;
|
||||
if ((self.gravity & LEFT) == LEFT) {
|
||||
xStart = 0;
|
||||
} else if ((self.gravity & RIGHT) == RIGHT) {
|
||||
@ -94,14 +94,6 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
|
||||
xStart = (self.width -self.desiredWidth)/2;
|
||||
}
|
||||
|
||||
if ((self.gravity & TOP) == TOP) {
|
||||
yStart = 0;
|
||||
} 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;
|
||||
}
|
||||
|
||||
for (DoricViewNode *child in self.indexedChildren) {
|
||||
if (child.layoutParams.width == LAYOUT_MATCH_PARENT) {
|
||||
child.width = self.width;
|
||||
@ -112,13 +104,13 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
|
||||
|
||||
if ([child.layoutParams isKindOfClass:VHLayoutParams.class]) {
|
||||
VHLayoutParams *layoutParams = (VHLayoutParams *)child.layoutParams;
|
||||
DoricGravity gravity = layoutParams.alignment;
|
||||
DoricGravity gravity = layoutParams.alignment | self.gravity;
|
||||
if ((gravity & TOP) == TOP) {
|
||||
child.top = yStart;
|
||||
child.top = 0;
|
||||
} else if ((gravity & BOTTOM) == BOTTOM) {
|
||||
child.bottom = yStart + self.desiredHeight;
|
||||
child.bottom = self.height;
|
||||
} else if ((gravity & CENTER_Y) == CENTER_Y) {
|
||||
child.centerY = yStart + self.desiredHeight/2;
|
||||
child.centerY = self.height/2;
|
||||
}
|
||||
}
|
||||
child.left = xStart;
|
||||
|
@ -12,12 +12,6 @@ - (void)setupRootView:(UIView *)view {
|
||||
self.view = view;
|
||||
}
|
||||
|
||||
- (void)measureByParent:(DoricGroupNode *)parent {
|
||||
// Do noting for root
|
||||
[super measureByParent:self];
|
||||
}
|
||||
|
||||
|
||||
- (void)render:(NSDictionary *)props {
|
||||
[self blend:props];
|
||||
[self measureByParent:self];
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
#import "DoricStackNode.h"
|
||||
#import "DoricUtil.h"
|
||||
|
||||
@implementation DoricStackNode
|
||||
|
||||
@ -42,9 +43,28 @@ - (LayoutParams *)generateDefaultLayoutParams {
|
||||
return [[StackLayoutParams alloc] init];
|
||||
}
|
||||
|
||||
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig {
|
||||
[super blendChild:child layoutConfig:layoutconfig];
|
||||
if (![child.layoutParams isKindOfClass:StackLayoutParams.class]) {
|
||||
DoricLog(@"blend Stack child error,layout params not match");
|
||||
return;
|
||||
}
|
||||
StackLayoutParams *params = (StackLayoutParams *)child.layoutParams;
|
||||
// NSDictionary *margin = [layoutconfig objectForKey:@"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];
|
||||
// }
|
||||
NSNumber *alignment = [layoutconfig objectForKey:@"alignment"];
|
||||
if (alignment) {
|
||||
params.alignment = [alignment integerValue];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)layoutByParent:(DoricGroupNode *)parent {
|
||||
for (DoricViewNode *child in self.indexedChildren) {
|
||||
[child measureByParent:self];
|
||||
if (child.layoutParams.width == LAYOUT_MATCH_PARENT) {
|
||||
child.width = self.width;
|
||||
}
|
||||
@ -53,7 +73,7 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
|
||||
}
|
||||
DoricGravity gravity = self.gravity;
|
||||
if ([child.layoutParams isKindOfClass:StackLayoutParams.class]) {
|
||||
StackLayoutParams *layoutParams = (StackLayoutParams *)self.layoutParams;
|
||||
StackLayoutParams *layoutParams = (StackLayoutParams *)child.layoutParams;
|
||||
gravity |= layoutParams.alignment;
|
||||
}
|
||||
|
||||
@ -75,6 +95,7 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
|
||||
if ((gravity & CENTER_Y) == CENTER_Y) {
|
||||
child.centerY = self.centerY;
|
||||
}
|
||||
[child layoutByParent:self];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
@ -83,16 +83,8 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
|
||||
if (self.layoutParams.height == LAYOUT_MATCH_PARENT) {
|
||||
self.height = parent.height;
|
||||
}
|
||||
// layotu child
|
||||
CGFloat xStart = 0, yStart = 0;
|
||||
if ((self.gravity & LEFT) == LEFT) {
|
||||
xStart = 0;
|
||||
} else if ((self.gravity & RIGHT) == RIGHT) {
|
||||
xStart = self.width - self.desiredWidth;
|
||||
} else if ((self.gravity & CENTER_X) == CENTER_X) {
|
||||
xStart = (self.width -self.desiredWidth)/2;
|
||||
}
|
||||
|
||||
// layout child
|
||||
CGFloat yStart = 0;
|
||||
if ((self.gravity & TOP) == TOP) {
|
||||
yStart = 0;
|
||||
} else if ((self.gravity & BOTTOM) == BOTTOM) {
|
||||
@ -111,13 +103,13 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
|
||||
}
|
||||
if ([child.layoutParams isKindOfClass:VHLayoutParams.class]) {
|
||||
VHLayoutParams *layoutParams = (VHLayoutParams *)child.layoutParams;
|
||||
DoricGravity gravity = layoutParams.alignment;
|
||||
DoricGravity gravity = layoutParams.alignment | self.gravity;
|
||||
if ((gravity & LEFT) == LEFT) {
|
||||
child.left = xStart;
|
||||
child.left = 0;
|
||||
} else if ((gravity & RIGHT) == RIGHT) {
|
||||
child.right = xStart + self.desiredWidth;
|
||||
child.right = self.width;
|
||||
} else if ((gravity & CENTER_X) == CENTER_X) {
|
||||
child.centerX = xStart + self.desiredWidth/2;
|
||||
child.centerX = self.width/2;
|
||||
}
|
||||
}
|
||||
child.top = yStart;
|
||||
|
@ -151,7 +151,7 @@ - (CGFloat)centerX {
|
||||
}
|
||||
|
||||
- (CGFloat)centerY {
|
||||
return ((UIView *)self.view).centerX;
|
||||
return ((UIView *)self.view).centerY;
|
||||
}
|
||||
|
||||
- (void)setX:(CGFloat)x {
|
||||
|
@ -50,7 +50,6 @@ class CounterVM extends ViewModel<CountModel, CounterView> {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@Entry
|
||||
class MyPage extends VMPanel<CountModel, CounterView>{
|
||||
|
||||
|
Reference in New Issue
Block a user