Repository: incubator-weex Updated Branches: refs/heads/master 2d93c1c55 -> 9acc1bc46
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9acc1bc4/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm index a955445..0bda28a 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm +++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.mm @@ -36,7 +36,6 @@ #import "WXValidateProtocol.h" #import "WXPrerenderManager.h" #import "WXTracingManager.h" -#import "WXLayoutDefine.h" #import "WXSDKInstance_performance.h" #import "WXRootView.h" #import "WXComponent+Layout.h" @@ -63,11 +62,7 @@ static NSThread *WXComponentThread; WXComponent *_rootComponent; NSMutableArray *_fixedComponents; -//#ifndef USE_FLEX - css_node_t *_rootCSSNode; -//#else WeexCore::WXCoreLayoutNode* _rootFlexCSSNode; -//#endif CADisplayLink *_displayLink; } @@ -98,21 +93,12 @@ static NSThread *WXComponentThread; - (void)dealloc { -//#ifndef USE_FLEX - if(![WXComponent isUseFlex]) - { - free_css_node(_rootCSSNode); - } - -//#else - if(_rootFlexCSSNode){ delete _rootFlexCSSNode; // WeexCore::WXCoreLayoutNode::freeNodeTree(_rootFlexCSSNode); _rootFlexCSSNode=nullptr; } -//#endif [NSMutableArray wx_releaseArray:_fixedComponents]; } @@ -179,22 +165,6 @@ static NSThread *WXComponentThread; - (void)rootViewFrameDidChange:(CGRect)frame { WXAssertComponentThread(); -//#ifndef USE_FLEX - - if (![WXComponent isUseFlex]) { - if (_rootCSSNode) { - [self _applyRootFrame:frame toRootCSSNode:_rootCSSNode]; - if (!_rootComponent.styles[@"width"]) { - _rootComponent.cssNode->style.dimensions[CSS_WIDTH] = frame.size.width ?: CSS_UNDEFINED; - } - if (!_rootComponent.styles[@"height"]) { - _rootComponent.cssNode->style.dimensions[CSS_HEIGHT] = frame.size.height ?: CSS_UNDEFINED; - } - } - } -//#else - else - { if (_rootFlexCSSNode) { [self _applyRootFrame:frame]; if (!_rootComponent.styles[@"width"]) { @@ -204,29 +174,16 @@ static NSThread *WXComponentThread; _rootComponent.flexCssNode->setStyleHeight(frame.size.height ?:FlexUndefined); } } - } -//#endif [_rootComponent setNeedsLayout]; [self startComponentTasks]; } -//#ifndef USE_FLEX -- (void)_applyRootFrame:(CGRect)rootFrame toRootCSSNode:(css_node_t *)rootCSSNode -{ - _rootCSSNode->style.position[CSS_LEFT] = self.weexInstance.frame.origin.x; - _rootCSSNode->style.position[CSS_TOP] = self.weexInstance.frame.origin.y; - // if no instance width/height, use layout width/height, as Android's wrap_content - _rootCSSNode->style.dimensions[CSS_WIDTH] = self.weexInstance.frame.size.width ?: CSS_UNDEFINED; - _rootCSSNode->style.dimensions[CSS_HEIGHT] = self.weexInstance.frame.size.height ?: CSS_UNDEFINED; -} -//#else - (void)_applyRootFrame:(CGRect)rootFrame{ _rootFlexCSSNode->setStylePosition(WeexCore::kPositionEdgeLeft, self.weexInstance.frame.origin.x); _rootFlexCSSNode->setStylePosition(WeexCore::kPositionEdgeTop, self.weexInstance.frame.origin.y); _rootFlexCSSNode->setStyleWidth(self.weexInstance.frame.size.width ?: FlexUndefined,NO); _rootFlexCSSNode->setStyleHeight(self.weexInstance.frame.size.height ?: FlexUndefined); } -//#endif - (void)_addUITask:(void (^)(void))block { @@ -263,18 +220,8 @@ static NSThread *WXComponentThread; WXAssertParam(data); _rootComponent = [self _buildComponentForData:data supercomponent:nil]; -//#ifndef USE_FLEX - if(![WXComponent isUseFlex]) - { - [self _initRootCSSNode]; - } -//#else - else - { [self _initRootFlexCssNode]; _rootFlexCSSNode->addChildAt(_rootComponent.flexCssNode, (uint32_t)[_fixedComponents count]); - } -//#endif NSArray *subcomponentsData = [data valueForKey:@"children"]; if (subcomponentsData) { @@ -297,25 +244,6 @@ static NSThread *WXComponentThread; } -//#ifndef USE_FLEX -static bool rootNodeIsDirty(void *context) -{ - WXComponentManager *manager = (__bridge WXComponentManager *)(context); - return [manager->_rootComponent needsLayout]; -} - -static css_node_t * rootNodeGetChild(void *context, int i) -{ - WXComponentManager *manager = (__bridge WXComponentManager *)(context); - if (i == 0) { - return manager->_rootComponent.cssNode; - } else if(manager->_fixedComponents.count >= i) { - return ((WXComponent *)((manager->_fixedComponents)[i-1])).cssNode; - } - - return NULL; -} -//#endif - (void)addComponent:(NSDictionary *)componentData toSupercomponent:(NSString *)superRef atIndex:(NSInteger)index appendingInTree:(BOOL)appendingInTree { @@ -326,7 +254,7 @@ static css_node_t * rootNodeGetChild(void *context, int i) WXComponent *supercomponent = [_indexDict objectForKey:superRef]; WXAssertComponentExist(supercomponent); - if ([WXComponent isUseFlex] && !supercomponent) { + if (!supercomponent) { WXLogWarning(@"addComponent,superRef from js never exit ! check JS action, supRef:%@",superRef); return; } @@ -344,24 +272,6 @@ static css_node_t * rootNodeGetChild(void *context, int i) } #ifdef DEBUG -//#ifndef USE_FLEX - if(![WXComponent isUseFlex]) - { - WXLogDebug(@"flexLayout -> _recursivelyAddComponent : super:(%@,%@):[%f,%f] ,child:(%@,%@):[%f,%f],childClass:%@", - supercomponent.type, - supercomponent.ref, - supercomponent.cssNode->style.dimensions[CSS_WIDTH], - supercomponent.cssNode->style.dimensions[CSS_HEIGHT], - component.type, - component.ref, - component.cssNode->style.dimensions[CSS_WIDTH], - component.cssNode->style.dimensions[CSS_HEIGHT] - ,NSStringFromClass([component class]) - ); - } -//#else - else - { WXLogDebug(@"flexLayout -> _recursivelyAddComponent : super:(%@,%@):[%f,%f] ,child:(%@,%@):[%f,%f],childClass:%@", supercomponent.type, supercomponent.ref, @@ -373,8 +283,6 @@ static css_node_t * rootNodeGetChild(void *context, int i) component.flexCssNode->getStyleHeight() ,NSStringFromClass([component class]) ); - } -//#endif #endif //DEBUG @@ -447,7 +355,7 @@ static css_node_t * rootNodeGetChild(void *context, int i) WXComponent *component = [_indexDict objectForKey:ref]; WXAssertComponentExist(component); - if ([WXComponent isUseFlex] && !component) { + if (!component) { WXLogWarning(@"removeComponent ref from js never exit ! check JS action, ref :%@",ref); return; } @@ -985,20 +893,10 @@ static css_node_t * rootNodeGetChild(void *context, int i) WXLogDebug(@"flexLayout -> action__ calculateLayout root"); #endif -//#ifndef USE_FLEX - if(![WXComponent isUseFlex]) - { - layoutNode(_rootCSSNode, _rootCSSNode->style.dimensions[CSS_WIDTH], _rootCSSNode->style.dimensions[CSS_HEIGHT], CSS_DIRECTION_INHERIT); - } -//#else - else - { std::pair<float, float> renderPageSize; renderPageSize.first = self.weexInstance.frame.size.width; renderPageSize.second = self.weexInstance.frame.size.height; _rootFlexCSSNode->calculateLayout(renderPageSize); - } -//#endif NSMutableSet<WXComponent *> *dirtyComponents = [NSMutableSet set]; [_rootComponent _calculateFrameWithSuperAbsolutePosition:CGPointZero gatherDirtyComponents:dirtyComponents]; [self _calculateRootFrame]; @@ -1010,7 +908,6 @@ static css_node_t * rootNodeGetChild(void *context, int i) } } -//#ifdef USE_FLEX - (void) _printFlexComonentFrame:(WXComponent *)component { #ifdef DEBUG @@ -1029,7 +926,6 @@ static css_node_t * rootNodeGetChild(void *context, int i) } -//#endif - (void)_syncUITasks { @@ -1041,20 +937,6 @@ static css_node_t * rootNodeGetChild(void *context, int i) } }); } -//#ifndef USE_FLEX -- (void)_initRootCSSNode -{ - _rootCSSNode = new_css_node(); - - [self _applyRootFrame:self.weexInstance.frame toRootCSSNode:_rootCSSNode]; - - _rootCSSNode->style.flex_wrap = CSS_NOWRAP; - _rootCSSNode->is_dirty = rootNodeIsDirty; - _rootCSSNode->get_child = rootNodeGetChild; - _rootCSSNode->context=(__bridge void *)(self); - _rootCSSNode->children_count = 1; -} -//#else - (void)_initRootFlexCssNode { _rootFlexCSSNode = new WeexCore::WXCoreLayoutNode(); @@ -1062,37 +944,9 @@ static css_node_t * rootNodeGetChild(void *context, int i) _rootFlexCSSNode->setFlexWrap(WeexCore::kNoWrap); _rootFlexCSSNode->setContext((__bridge void *)(self)); } -//#endif - (void)_calculateRootFrame { -//#ifndef USE_FLEX - - if(![WXComponent isUseFlex]) - { - if (!_rootCSSNode->layout.should_update) { - return; - } - _rootCSSNode->layout.should_update = false; -#ifdef DEBUG - WXLogDebug(@"flexLayout -> root _calculateRootFrame"); -#endif - - CGRect frame = CGRectMake(WXRoundPixelValue(_rootCSSNode->layout.position[CSS_LEFT]), - WXRoundPixelValue(_rootCSSNode->layout.position[CSS_TOP]), - WXRoundPixelValue(_rootCSSNode->layout.dimensions[CSS_WIDTH]), - WXRoundPixelValue(_rootCSSNode->layout.dimensions[CSS_HEIGHT])); - WXPerformBlockOnMainThread(^{ - if(!self.weexInstance.isRootViewFrozen) { - self.weexInstance.rootView.frame = frame; - } - }); - - resetNodeLayout(_rootCSSNode); - } -//#else - else - { if(!_rootFlexCSSNode->hasNewLayout()){ return; } @@ -1114,8 +968,6 @@ static css_node_t * rootNodeGetChild(void *context, int i) // _rootFlexCSSNode->reset(); // resetNodeLayout(_rootFlexCSSNode); - } -//#endif } @@ -1126,33 +978,13 @@ static css_node_t * rootNodeGetChild(void *context, int i) - (void)addFixedComponent:(WXComponent *)fixComponent { [_fixedComponents addObject:fixComponent]; -//#ifndef USE_FLEX - if(![WXComponent isUseFlex]) - { - _rootCSSNode->children_count = (int)[_fixedComponents count] + 1; - } -//#else - else - { _rootFlexCSSNode->addChildAt(fixComponent.flexCssNode, (uint32_t)([_fixedComponents count]-1)); - } -//#endif } - (void)removeFixedComponent:(WXComponent *)fixComponent { [_fixedComponents removeObject:fixComponent]; -//#ifndef USE_FLEX - if(![WXComponent isUseFlex]) - { - _rootCSSNode->children_count = (int)[_fixedComponents count] + 1; - } -//#else - else - { _rootFlexCSSNode->removeChild(fixComponent->_flexCssNode); - } -//#endif } @end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9acc1bc4/ios/sdk/WeexSDK/Sources/Model/WXComponent.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent.h b/ios/sdk/WeexSDK/Sources/Model/WXComponent.h index c0e6c9a..937d486 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXComponent.h +++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent.h @@ -24,7 +24,6 @@ #import <Foundation/Foundation.h> -#import "WXLayoutDefine.h" #import "WXType.h" @class WXSDKInstance; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9acc1bc4/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm b/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm index e2ad487..0cf24fa 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm @@ -169,40 +169,28 @@ } else { component->_templateComponent = self->_templateComponent; } -//#ifndef USE_FLEX - if(![WXComponent isUseFlex]) - { - memcpy(component->_cssNode, self.cssNode, sizeof(css_node_t)); - component->_cssNode->context = (__bridge void *)component; - } -//#else - else - { - //memcpy((void*)component->_flexCssNode,self.flexCssNode,sizeof(WeexCore::WXCoreLayoutNode)); - component->_flexCssNode->copyStyle(self.flexCssNode); - component->_flexCssNode->copyMeasureFunc(self.flexCssNode); - component->_flexCssNode->setContext((__bridge void *)component); - } -//#endif + //memcpy((void*)component->_flexCssNode,self.flexCssNode,sizeof(WeexCore::WXCoreLayoutNode)); + component->_flexCssNode->copyStyle(self.flexCssNode); + component->_flexCssNode->copyMeasureFunc(self.flexCssNode); + component->_flexCssNode->setContext((__bridge void *)component); component->_calculatedFrame = self.calculatedFrame; NSMutableArray *subcomponentsCopy = [NSMutableArray array]; - if ([WXComponent isUseFlex]) { component->_subcomponents = subcomponentsCopy; NSUInteger count = [self.subcomponents count]; for (NSInteger i = 0 ; i < count;i++){ WXComponent *subcomponentCopy = [[self.subcomponents objectAtIndex:i] copy]; [component _insertSubcomponent:subcomponentCopy atIndex:i]; } - }else{ - for (WXComponent *subcomponent in self.subcomponents) { - WXComponent *subcomponentCopy = [subcomponent copy]; - subcomponentCopy->_supercomponent = component; - [subcomponentsCopy addObject:subcomponentCopy]; - } - component->_subcomponents = subcomponentsCopy; - } +// else{ +// for (WXComponent *subcomponent in self.subcomponents) { +// WXComponent *subcomponentCopy = [subcomponent copy]; +// subcomponentCopy->_supercomponent = component; +// [subcomponentsCopy addObject:subcomponentCopy]; +// } +// component->_subcomponents = subcomponentsCopy; +// } WXPerformBlockOnComponentThread(^{ [self.weexInstance.componentManager addComponent:component toIndexDictForRef:copyRef]; @@ -223,22 +211,12 @@ - (void)dealloc { -//#ifndef USE_FLEX - if(![WXComponent isUseFlex]) - { - free_css_node(_cssNode); - } -//#else - else - { - if(self.flexCssNode){ + if(self.flexCssNode){ #ifdef DEBUG - WXLogDebug(@"flexLayout -> dealloc %@",self.ref); + WXLogDebug(@"flexLayout -> dealloc %@",self.ref); #endif - delete self.flexCssNode; - } + delete self.flexCssNode; } -//#endif // remove all gesture and all if (_isTemplate && self.attributes[@"@templateId"]) { @@ -509,14 +487,6 @@ return _absolutePosition; } -//#ifndef USE_FLEX -- (css_node_t *)cssNode -{ - return _cssNode; -} -//#else -//#endif - - (void)_addEventParams:(NSDictionary *)params { pthread_mutex_lock(&_propertyMutex); @@ -576,14 +546,6 @@ if (_useCompositing || _isCompositingChild) { subcomponent->_isCompositingChild = YES; } -//#ifndef USE_FLEX - if(![WXComponent isUseFlex]) - { - - } -//#else - else - { if (subcomponent->_isNeedJoinLayoutSystem) { NSInteger actualIndex = [self getActualNodeIndex:subcomponent atIndex:index]; [self _insertChildCssNode:subcomponent atIndex:actualIndex]; @@ -597,8 +559,6 @@ ); #endif } - } -//#endif [self _recomputeCSSNodeChildren]; [self setNeedsLayout]; @@ -608,16 +568,8 @@ { pthread_mutex_lock(&_propertyMutex); [_subcomponents removeObject:subcomponent]; -//#ifndef USE_FLEX - if (![WXComponent isUseFlex]) { - } -//#else - else - { //subcomponent->_isNeedJoinLayoutSystem = NO; [self _rmChildCssNode:subcomponent]; - } -//#endif pthread_mutex_unlock(&_propertyMutex); } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9acc1bc4/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h b/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h index 12c3a1c..3b83f5c 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h +++ b/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h @@ -20,7 +20,6 @@ #import <UIKit/UIKit.h> #import <objc/runtime.h> #import "WXLog.h" -#import "WXLayoutDefine.h" #import "WXType.h" @class WXLength; @@ -56,12 +55,6 @@ typedef CGFloat WXPixelType; // WXPixelType that use flexCGFloat to convert + (WXPixelType)WXFlexPixelType:(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; -+ (css_justify_t)css_justify_t:(id)value; -+ (css_position_type_t)css_position_type_t:(id)value; + (UIViewContentMode)UIViewContentMode:(id)value; + (WXImageQuality)WXImageQuality:(id)value; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9acc1bc4/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m b/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m index 0fb2813..80513a5 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m +++ b/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m @@ -195,105 +195,6 @@ WX_NUMBER_CONVERT(NSUInteger, unsignedIntegerValue) return pixel * 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]]){ - if ([value isEqualToString:@"absolute"]) { - return CSS_POSITION_ABSOLUTE; - } else if ([value isEqualToString:@"relative"]) { - return CSS_POSITION_RELATIVE; - } else if ([value isEqualToString:@"fixed"]) { - return CSS_POSITION_ABSOLUTE; - } else if ([value isEqualToString:@"sticky"]) { - return CSS_POSITION_RELATIVE; - } - } - return CSS_POSITION_RELATIVE; -} - -+ (css_flex_direction_t)css_flex_direction_t:(id)value -{ - if([value isKindOfClass:[NSString class]]){ - if ([value isEqualToString:@"column"]) { - return CSS_FLEX_DIRECTION_COLUMN; - } else if ([value isEqualToString:@"column-reverse"]) { - return CSS_FLEX_DIRECTION_COLUMN_REVERSE; - } else if ([value isEqualToString:@"row"]) { - return CSS_FLEX_DIRECTION_ROW; - } else if ([value isEqualToString:@"row-reverse"]) { - return CSS_FLEX_DIRECTION_ROW_REVERSE; - } - } - return CSS_FLEX_DIRECTION_COLUMN; -} - -+ (css_align_t)css_align_t:(id)value -{ - if([value isKindOfClass:[NSString class]]){ - if ([value isEqualToString:@"stretch"]) { - return CSS_ALIGN_STRETCH; - } else if ([value isEqualToString:@"flex-start"]) { - return CSS_ALIGN_FLEX_START; - } else if ([value isEqualToString:@"flex-end"]) { - return CSS_ALIGN_FLEX_END; - } else if ([value isEqualToString:@"center"]) { - return CSS_ALIGN_CENTER; - } else if ([value isEqualToString:@"auto"]) { - return CSS_ALIGN_AUTO; - } - } - - return CSS_ALIGN_STRETCH; -} - -+ (css_wrap_type_t)css_wrap_type_t:(id)value -{ - if([value isKindOfClass:[NSString class]]) { - if ([value isEqualToString:@"nowrap"]) { - return CSS_NOWRAP; - } else if ([value isEqualToString:@"wrap"]) { - return CSS_WRAP; - } - } - - return CSS_NOWRAP; -} - -+ (css_justify_t)css_justify_t:(id)value -{ - if([value isKindOfClass:[NSString class]]){ - if ([value isEqualToString:@"flex-start"]) { - return CSS_JUSTIFY_FLEX_START; - } else if ([value isEqualToString:@"center"]) { - return CSS_JUSTIFY_CENTER; - } else if ([value isEqualToString:@"flex-end"]) { - return CSS_JUSTIFY_FLEX_END; - } else if ([value isEqualToString:@"space-between"]) { - return CSS_JUSTIFY_SPACE_BETWEEN; - } else if ([value isEqualToString:@"space-around"]) { - return CSS_JUSTIFY_SPACE_AROUND; - } - } - - return CSS_JUSTIFY_FLEX_START; -} - #pragma mark Style + (UIColor *)UIColor:(id)value http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9acc1bc4/ios/sdk/WeexSDK/Sources/WeexSDK.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/WeexSDK.h b/ios/sdk/WeexSDK/Sources/WeexSDK.h index 251353c..5c03635 100644 --- a/ios/sdk/WeexSDK/Sources/WeexSDK.h +++ b/ios/sdk/WeexSDK/Sources/WeexSDK.h @@ -49,7 +49,6 @@ #import "WXModalUIModule.h" #import "WXLog.h" #import "WXListComponent.h" -#import "WXLayoutDefine.h" #import "WXJSExceptionProtocol.h" #import "WXJSExceptionInfo.h" #import "WXIndicatorComponent.h" @@ -77,7 +76,6 @@ #import "WXAnalyzerCenter.h" #import "WXAComponent.h" #import "NSObject+WXSwizzle.h" -#import "Layout.h" #import "JSContext+Weex.h" #endif /* __OBJC__ */
