diff --git a/iOS/Pod/Classes/Shader/DoricGroupNode.m b/iOS/Pod/Classes/Shader/DoricGroupNode.m index 763e16c4..92ba1265 100644 --- a/iOS/Pod/Classes/Shader/DoricGroupNode.m +++ b/iOS/Pod/Classes/Shader/DoricGroupNode.m @@ -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 { diff --git a/iOS/Pod/Classes/Shader/DoricHLayoutNode.m b/iOS/Pod/Classes/Shader/DoricHLayoutNode.m index 389b9b80..608f697d 100644 --- a/iOS/Pod/Classes/Shader/DoricHLayoutNode.m +++ b/iOS/Pod/Classes/Shader/DoricHLayoutNode.m @@ -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; diff --git a/iOS/Pod/Classes/Shader/DoricRootNode.m b/iOS/Pod/Classes/Shader/DoricRootNode.m index 430bb6a5..57e24ed2 100644 --- a/iOS/Pod/Classes/Shader/DoricRootNode.m +++ b/iOS/Pod/Classes/Shader/DoricRootNode.m @@ -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]; diff --git a/iOS/Pod/Classes/Shader/DoricStackNode.m b/iOS/Pod/Classes/Shader/DoricStackNode.m index f9bccd17..96e5ce34 100644 --- a/iOS/Pod/Classes/Shader/DoricStackNode.m +++ b/iOS/Pod/Classes/Shader/DoricStackNode.m @@ -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 diff --git a/iOS/Pod/Classes/Shader/DoricVLayoutNode.m b/iOS/Pod/Classes/Shader/DoricVLayoutNode.m index 2fe14284..937eb020 100644 --- a/iOS/Pod/Classes/Shader/DoricVLayoutNode.m +++ b/iOS/Pod/Classes/Shader/DoricVLayoutNode.m @@ -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; diff --git a/iOS/Pod/Classes/Shader/DoricViewNode.m b/iOS/Pod/Classes/Shader/DoricViewNode.m index 3b7341ab..83ec6ef5 100644 --- a/iOS/Pod/Classes/Shader/DoricViewNode.m +++ b/iOS/Pod/Classes/Shader/DoricViewNode.m @@ -151,7 +151,7 @@ - (CGFloat)centerX { } - (CGFloat)centerY { - return ((UIView *)self.view).centerX; + return ((UIView *)self.view).centerY; } - (void)setX:(CGFloat)x { diff --git a/js-framework/demo.ts b/js-framework/demo.ts index 5ef14eeb..a8cc10b8 100644 --- a/js-framework/demo.ts +++ b/js-framework/demo.ts @@ -50,7 +50,6 @@ class CounterVM extends ViewModel { }) } } - @Entry class MyPage extends VMPanel{