From 201278629a233959bab028ded8b522bd343c0cd6 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Sat, 21 Mar 2020 16:03:03 +0800 Subject: [PATCH] iOS:Gravity and Margin shold affect at the same time --- doric-iOS/Pod/Classes/Shader/DoricLayouts.m | 54 ++++++++++++++------ doric-iOS/Pod/Classes/Shader/DoricViewNode.m | 4 +- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricLayouts.m b/doric-iOS/Pod/Classes/Shader/DoricLayouts.m index 7f42afcd..0b1a3499 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricLayouts.m +++ b/doric-iOS/Pod/Classes/Shader/DoricLayouts.m @@ -260,10 +260,8 @@ - (void)layoutSelf:(CGSize)targetSize { } else if ((gravity & CENTER_X) == CENTER_X) { child.centerX = targetSize.width / 2; } else { - if (childConfig.margin.left) { - child.left = childConfig.margin.left + padding.left; - } else if (childConfig.margin.right) { - child.right = targetSize.width - childConfig.margin.right - padding.right; + if (childConfig.margin.left || childConfig.margin.right) { + child.left = padding.left; } } if ((gravity & TOP) == TOP) { @@ -273,12 +271,26 @@ - (void)layoutSelf:(CGSize)targetSize { } else if ((gravity & CENTER_Y) == CENTER_Y) { child.centerY = targetSize.height / 2; } else { - if (childConfig.margin.top) { - child.top = childConfig.margin.top + padding.top; - } else if (childConfig.margin.bottom) { - child.bottom = targetSize.height - childConfig.margin.bottom - padding.bottom; + if (childConfig.margin.top || childConfig.margin.bottom) { + child.top = padding.top; } } + + if (!gravity) { + gravity = LEFT | TOP; + } + if (childConfig.margin.left && !((gravity & RIGHT) == RIGHT)) { + child.left += childConfig.margin.left; + } + if (childConfig.margin.right && !((gravity & LEFT) == LEFT)) { + child.right -= childConfig.margin.right; + } + if (childConfig.margin.top && !((gravity & BOTTOM) == BOTTOM)) { + child.top += childConfig.margin.top; + } + if (childConfig.margin.bottom && !((gravity & TOP) == TOP)) { + child.bottom -= childConfig.margin.bottom; + } } } @end @@ -359,13 +371,18 @@ - (void)layoutSelf:(CGSize)targetSize { child.right = self.width - padding.right; } else if ((gravity & CENTER_X) == CENTER_X) { child.centerX = targetSize.width / 2; - } else if (childConfig.margin.left) { - child.left = childConfig.margin.left + padding.left; - } else if (childConfig.margin.right) { - child.right = targetSize.width - childConfig.margin.right - padding.right; } else { child.left = padding.left; } + if (!gravity) { + gravity = LEFT; + } + if (childConfig.margin.left && !((gravity & RIGHT) == RIGHT)) { + child.left += childConfig.margin.left; + } + if (childConfig.margin.right && !((gravity & LEFT) == LEFT)) { + child.right -= childConfig.margin.right; + } if (childConfig.margin.top) { yStart += childConfig.margin.top; } @@ -454,13 +471,18 @@ - (void)layoutSelf:(CGSize)targetSize { child.bottom = targetSize.height - padding.bottom; } else if ((gravity & CENTER_Y) == CENTER_Y) { child.centerY = targetSize.height / 2; - } else if (childConfig.margin.top) { - child.top = childConfig.margin.top + padding.top; - } else if (childConfig.margin.bottom) { - child.bottom = targetSize.height - childConfig.margin.bottom - padding.bottom; } else { child.top = padding.top; } + if (!gravity) { + gravity = TOP; + } + if (childConfig.margin.top && !((gravity & BOTTOM) == BOTTOM)) { + child.top += childConfig.margin.top; + } + if (childConfig.margin.bottom && !((gravity & TOP) == TOP)) { + child.bottom -= childConfig.margin.bottom; + } if (childConfig.margin.left) { xStart += childConfig.margin.left; diff --git a/doric-iOS/Pod/Classes/Shader/DoricViewNode.m b/doric-iOS/Pod/Classes/Shader/DoricViewNode.m index b6e4225a..4a77640e 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricViewNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricViewNode.m @@ -182,9 +182,9 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop self.gradientLayer.frame = view.bounds; } } else if ([name isEqualToString:@"x"]) { - view.x = [(NSNumber *) prop floatValue]; + view.x = [prop floatValue]; } else if ([name isEqualToString:@"y"]) { - view.y = [(NSNumber *) prop floatValue]; + view.y = [prop floatValue]; } else if ([name isEqualToString:@"backgroundColor"]) { if ([prop isKindOfClass:[NSNumber class]]) { view.backgroundColor = DoricColor(prop);