Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[WEEX-282][iOS] update layout system to support rtl direction
Browse files Browse the repository at this point in the history
Modified WXComponent+Layout.m:
	1.set direction value to  cssNode
	2.setNeedLayout changed to trigger sibling component recalculate cssNode->layout

Modified WXConvert.h/m:
	add convert for "direction"

Modified WXConvertTests.m:
	add Tests for convert direction
  • Loading branch information
Klueze committed Apr 9, 2018
1 parent bb29077 commit 487b692
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
31 changes: 30 additions & 1 deletion ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,23 @@ @implementation WXComponent (Layout)

- (void)setNeedsLayout
{
_isLayoutDirty = YES;
WXComponent *supercomponent = [self supercomponent];
if(supercomponent){
for (WXComponent *siblingComponent in [supercomponent subcomponents]) {
[siblingComponent _needRecalculateLayout];
}
[supercomponent setNeedsLayout];
} else {
[self _needRecalculateLayout];
}
}

- (void)_needRecalculateLayout
{
_isLayoutDirty = YES;
[self _clearLayoutCSS];
}

- (BOOL)needsLayout
{
return _isLayoutDirty;
Expand Down Expand Up @@ -208,6 +218,23 @@ - (void)_layoutDidFinish
[self layoutDidFinish];
}

/**
* clear the layout variables on css node
**/
- (void)_clearLayoutCSS {
memset(&(_cssNode->layout), 0, sizeof(_cssNode->layout));
_cssNode->layout.dimensions[CSS_WIDTH] = CSS_UNDEFINED;
_cssNode->layout.dimensions[CSS_HEIGHT] = CSS_UNDEFINED;

// Such that the comparison is always going to be false
_cssNode->layout.last_requested_dimensions[CSS_WIDTH] = -1;
_cssNode->layout.last_requested_dimensions[CSS_HEIGHT] = -1;
_cssNode->layout.last_parent_max_width = -1;
_cssNode->layout.last_parent_max_height = -1;
_cssNode->layout.last_direction = (css_direction_t)-1;
_cssNode->layout.should_update = true;
}

#define WX_STYLE_FILL_CSS_NODE(key, cssProp, type)\
do {\
id value = styles[@#key];\
Expand Down Expand Up @@ -248,6 +275,7 @@ - (CGFloat)WXPixelType:(id)value

- (void)_fillCSSNode:(NSDictionary *)styles
{
WX_STYLE_FILL_CSS_NODE(direction, direction, css_direction_t)
// flex
WX_STYLE_FILL_CSS_NODE(flex, flex, CGFloat)
WX_STYLE_FILL_CSS_NODE(flexDirection, flex_direction, css_flex_direction_t)
Expand Down Expand Up @@ -311,6 +339,7 @@ - (void)_fillCSSNode:(NSDictionary *)styles

- (void)_resetCSSNode:(NSArray *)styles;
{
WX_STYLE_RESET_CSS_NODE(direction, direction, CSS_DIRECTION_LTR)
// flex
WX_STYLE_RESET_CSS_NODE(flex, flex, 0.0)
WX_STYLE_RESET_CSS_NODE(flexDirection, flex_direction, CSS_FLEX_DIRECTION_COLUMN)
Expand Down
1 change: 1 addition & 0 deletions ios/sdk/WeexSDK/Sources/Utility/WXConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef CGFloat WXPixelType;
// @parameter scaleFactor: please use weexInstance's pixelScaleFactor property
+ (WXPixelType)WXPixelType:(id)value scaleFactor:(CGFloat)scaleFactor;

+ (css_direction_t)css_direction_t:(id)value;
+ (css_flex_direction_t)css_flex_direction_t:(id)value;
+ (css_align_t)css_align_t:(id)value;
+ (css_wrap_type_t)css_wrap_type_t:(id)value;
Expand Down
14 changes: 14 additions & 0 deletions ios/sdk/WeexSDK/Sources/Utility/WXConvert.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ + (WXPixelType)WXPixelType:(id)value scaleFactor:(CGFloat)scaleFactor

#pragma mark CSS Layout

+ (css_direction_t)css_direction_t:(id)value
{
if([value isKindOfClass:[NSString class]]){
if ([value isEqualToString:@"inherit"]) {
return CSS_DIRECTION_INHERIT;
} else if ([value isEqualToString:@"ltr"]) {
return CSS_DIRECTION_LTR;
} else if ([value isEqualToString:@"rtl"]) {
return CSS_DIRECTION_RTL;
}
}
return CSS_DIRECTION_LTR;
}

+(css_position_type_t)css_position_type_t:(id)value
{
if([value isKindOfClass:[NSString class]]){
Expand Down
8 changes: 8 additions & 0 deletions ios/sdk/WeexSDKTests/WXConvertTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ - (void)tearDown {
[super tearDown];
}

- (void)testDirection {
NSArray *testDirections = @[@"inherit", @"ltr", @"rtl"];
css_direction_t directions[3] = {CSS_DIRECTION_INHERIT, CSS_DIRECTION_LTR, CSS_DIRECTION_RTL};
for (int i = 0; i<testDirections.count; i++) {
XCTAssertTrue([WXConvert wx_css_direction_t:testDirections[i]] == directions[i]);
}
}

- (void)testBOOL {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
Expand Down

0 comments on commit 487b692

Please sign in to comment.