From 1b08c227ef46021559e3fd75d5c9fc96b9f6c2ac Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Sat, 16 Nov 2019 16:49:42 +0800 Subject: [PATCH] feat:fix iOS render weight prop --- iOS/Pod/Classes/Shader/DoricLayouts.m | 20 -------------------- iOS/Pod/Classes/Shader/DoricSuperNode.m | 5 ++++- iOS/Pod/Classes/Shader/DoricTextNode.m | 13 ++++--------- js-framework/src/ui/declarative.ts | 8 ++++++++ 4 files changed, 16 insertions(+), 30 deletions(-) diff --git a/iOS/Pod/Classes/Shader/DoricLayouts.m b/iOS/Pod/Classes/Shader/DoricLayouts.m index fca3fe87..bf238368 100644 --- a/iOS/Pod/Classes/Shader/DoricLayouts.m +++ b/iOS/Pod/Classes/Shader/DoricLayouts.m @@ -530,23 +530,3 @@ - (UIView *)viewWithTagString:(NSString *)tagString { layout.layoutConfig = [[DoricLayoutConfig alloc] initWithWidth:DoricLayoutWrapContent height:DoricLayoutWrapContent]; return layout; } - -DoricVLayoutView *vLayoutWithBlock(NSArray *blocks) { - DoricVLayoutView *layout = [[DoricVLayoutView alloc] initWithFrame:CGRectZero]; - UIView *(^block)(); - for (block in blocks) { - [layout addSubview:block()]; - } - layout.layoutConfig = [[DoricLayoutConfig alloc] initWithWidth:DoricLayoutWrapContent height:DoricLayoutWrapContent]; - return layout; -} - -DoricHLayoutView *hLayoutWithBlock(NSArray *blocks) { - DoricHLayoutView *layout = [[DoricHLayoutView alloc] initWithFrame:CGRectZero]; - UIView *(^block)(); - for (block in blocks) { - [layout addSubview:block()]; - } - layout.layoutConfig = [[DoricLayoutConfig alloc] initWithWidth:DoricLayoutWrapContent height:DoricLayoutWrapContent]; - return layout; -} diff --git a/iOS/Pod/Classes/Shader/DoricSuperNode.m b/iOS/Pod/Classes/Shader/DoricSuperNode.m index b06ee2db..ac1827d4 100644 --- a/iOS/Pod/Classes/Shader/DoricSuperNode.m +++ b/iOS/Pod/Classes/Shader/DoricSuperNode.m @@ -93,7 +93,10 @@ - (void)blendSubNode:(DoricViewNode *)subNode layoutConfig:(NSDictionary *)layou if (alignment) { params.alignment = (DoricGravity) [alignment integerValue]; } - + NSNumber *weight = layoutConfig[@"weight"]; + if (weight) { + params.weight = (DoricGravity) [weight integerValue]; + } } - (void)blendSubNode:(NSDictionary *)subModel { diff --git a/iOS/Pod/Classes/Shader/DoricTextNode.m b/iOS/Pod/Classes/Shader/DoricTextNode.m index 5dd22fc5..9f386205 100644 --- a/iOS/Pod/Classes/Shader/DoricTextNode.m +++ b/iOS/Pod/Classes/Shader/DoricTextNode.m @@ -39,15 +39,10 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro } else if ([name isEqualToString:@"textAlignment"]) { DoricGravity gravity = (DoricGravity) [(NSNumber *) prop integerValue]; NSTextAlignment alignment = NSTextAlignmentCenter; - switch (gravity) { - case LEFT: - alignment = NSTextAlignmentLeft; - break; - case RIGHT: - alignment = NSTextAlignmentRight; - break; - default: - break; + if ((gravity & LEFT) == LEFT) { + alignment = NSTextAlignmentLeft; + } else if ((gravity & RIGHT) == RIGHT) { + alignment = NSTextAlignmentRight; } view.textAlignment = alignment; } else { diff --git a/js-framework/src/ui/declarative.ts b/js-framework/src/ui/declarative.ts index 69b8a454..13ce2903 100644 --- a/js-framework/src/ui/declarative.ts +++ b/js-framework/src/ui/declarative.ts @@ -20,6 +20,10 @@ import { IList, List } from './listview' export function text(config: IText) { const ret = new Text + ret.layoutConfig = { + widthSpec: LayoutSpec.WRAP_CONTENT, + heightSpec: LayoutSpec.WRAP_CONTENT, + } for (let key in config) { Reflect.set(ret, key, Reflect.get(config, key, config), ret) } @@ -28,6 +32,10 @@ export function text(config: IText) { export function image(config: IImage) { const ret = new Image + ret.layoutConfig = { + widthSpec: LayoutSpec.WRAP_CONTENT, + heightSpec: LayoutSpec.WRAP_CONTENT, + } for (let key in config) { Reflect.set(ret, key, Reflect.get(config, key, config), ret) }