From f009d29cee000b67e71a86a2f98e2c58256d1760 Mon Sep 17 00:00:00 2001 From: wqyfavor Date: Sun, 30 Sep 2018 14:42:15 +0800 Subject: [PATCH] Fix div in list which cause weexcore render objects not ordered. (#1602) * [Core] Refactor. Remove useless "_isNeedJoinLayoutSystem". * [Core] Refactor. div inside list, we add div to subcomponents of list, but do not display it. --- .../Component/RecycleList/WXCellSlotComponent.mm | 1 - .../RecycleList/WXComponent+DataBinding.mm | 2 +- .../WeexSDK/Sources/Component/WXCellComponent.mm | 1 - .../Sources/Component/WXComponent_internal.h | 3 +-- .../WeexSDK/Sources/Component/WXHeaderComponent.mm | 1 - .../WeexSDK/Sources/Component/WXListComponent.mm | 2 +- ios/sdk/WeexSDK/Sources/Model/WXComponent.mm | 5 ----- .../Sources/View/WXComponent+ViewManagement.mm | 13 +++++++++++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXCellSlotComponent.mm b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXCellSlotComponent.mm index 3b7b90635c..70143bbcc6 100644 --- a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXCellSlotComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXCellSlotComponent.mm @@ -43,7 +43,6 @@ - (instancetype)initWithRef:(NSString *)ref } _templateCaseType = attributes[@"case"] ? [WXConvert NSString:attributes[@"case"]] :const_cast(WXDefaultRecycleTemplateType); _lazyCreateView = YES; - _isNeedJoinLayoutSystem = NO; } return self; diff --git a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXComponent+DataBinding.mm b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXComponent+DataBinding.mm index 767ffe3eae..26892dbd60 100644 --- a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXComponent+DataBinding.mm +++ b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXComponent+DataBinding.mm @@ -170,7 +170,7 @@ - (void)updateBindingData:(NSDictionary *)data if (!needDisplay) { self.displayType = WXDisplayTypeNone; return; - } else if (needDisplay && !_isNeedJoinLayoutSystem) { + } else if (needDisplay) { self.displayType = WXDisplayTypeBlock; } } diff --git a/ios/sdk/WeexSDK/Sources/Component/WXCellComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXCellComponent.mm index 393d26149e..64ead8bc11 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXCellComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/WXCellComponent.mm @@ -51,7 +51,6 @@ - (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDict _deleteAnimation = [WXConvert UITableViewRowAnimation:attributes[@"deleteAnimation"]]; _keepScrollPosition = attributes[@"keepScrollPosition"] ? [WXConvert BOOL:attributes[@"keepScrollPosition"]] : NO; _lazyCreateView = YES; - _isNeedJoinLayoutSystem = NO; if (attributes[@"zIndex"]) { _zIndex = [WXConvert NSString:attributes[@"zIndex"]]; } diff --git a/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h b/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h index 161eb2bf06..fb1b673422 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h +++ b/ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h @@ -129,10 +129,9 @@ typedef id (^WXDataBindingBlock)(NSDictionary *data, BOOL *needUpdate); WXBorderStyle _borderBottomStyle; WXBorderStyle _borderLeftStyle; - + BOOL _isViewTreeIgnored; // Component is added to super, but it is not added to views. BOOL _isFixed; BOOL _async; - BOOL _isNeedJoinLayoutSystem; BOOL _lazyCreateView; WXTransform *_transform; diff --git a/ios/sdk/WeexSDK/Sources/Component/WXHeaderComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXHeaderComponent.mm index c555a23c60..2d5c6a7bde 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXHeaderComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/WXHeaderComponent.mm @@ -33,7 +33,6 @@ - (instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDict if (self) { _async = YES; - _isNeedJoinLayoutSystem = NO; _keepScrollPosition = attributes[@"keepScrollPosition"] ? [WXConvert BOOL:attributes[@"keepScrollPosition"]] : NO; } diff --git a/ios/sdk/WeexSDK/Sources/Component/WXListComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXListComponent.mm index 26949909c0..55116af68a 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXListComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/WXListComponent.mm @@ -262,7 +262,7 @@ - (BOOL)_insertSubcomponent:(WXComponent *)subcomponent atIndex:(NSInteger)index && ![subcomponent isKindOfClass:[WXLoadingComponent class]] && subcomponent->_positionType != WXPositionTypeFixed) { WXLogError(@"list only support cell/header/refresh/loading/fixed-component as child."); - return NO; + subcomponent->_isViewTreeIgnored = YES; // do not show this element. } BOOL inserted = [super _insertSubcomponent:subcomponent atIndex:index]; diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm b/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm index 02d937e6be..e00a8edf7d 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm @@ -99,7 +99,6 @@ - (instancetype)initWithRef:(NSString *)ref _absolutePosition = CGPointMake(NAN, NAN); _displayType = WXDisplayTypeBlock; - _isNeedJoinLayoutSystem = YES; _isViewFrameSyncWithCalculated = YES; _ariaHidden = nil; _accessible = nil; @@ -323,13 +322,11 @@ - (void)setDisplayType:(WXDisplayType)displayType if (_displayType != displayType) { _displayType = displayType; if (displayType == WXDisplayTypeNone) { - _isNeedJoinLayoutSystem = NO; [self _removeFromSupercomponent]; WXPerformBlockOnMainThread(^{ [self removeFromSuperview]; }); } else { - _isNeedJoinLayoutSystem = YES; WXPerformBlockOnMainThread(^{ [self _buildViewHierarchyLazily]; // TODO: insert into the correct index @@ -594,7 +591,6 @@ - (BOOL)_insertSubcomponent:(WXComponent *)subcomponent atIndex:(NSInteger)index if (subcomponent->_positionType == WXPositionTypeFixed) { [self.weexInstance.componentManager addFixedComponent:subcomponent]; - subcomponent->_isNeedJoinLayoutSystem = NO; } if (_useCompositing || _isCompositingChild) { @@ -628,7 +624,6 @@ - (void)_removeFromSupercomponent:(BOOL)remove if (_positionType == WXPositionTypeFixed) { [self.weexInstance.componentManager removeFixedComponent:self]; - self->_isNeedJoinLayoutSystem = YES; } if (_positionType == WXPositionTypeSticky) { [self.ancestorScroller removeStickyComponent:self]; diff --git a/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm b/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm index 93f7d009b8..ad178903bc 100644 --- a/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm +++ b/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm @@ -99,6 +99,17 @@ - (void)insertSubview:(WXComponent *)subcomponent atIndex:(NSInteger)index if (subcomponent.displayType == WXDisplayTypeNone) { return; } + + if (_isViewTreeIgnored) { + // self not added to views, children also ignored. + subcomponent->_isViewTreeIgnored = YES; + return; + } + + if (subcomponent->_isViewTreeIgnored) { + // children not added to views, such as div in list, we do not create view. + return; + } WX_CHECK_COMPONENT_TYPE(self.componentType) if (subcomponent->_positionType == WXPositionTypeFixed) { @@ -230,10 +241,8 @@ - (void)_updateViewStyles:(NSDictionary *)styles WXPerformBlockOnComponentThread(^{ if (positionType == WXPositionTypeFixed) { [self.weexInstance.componentManager addFixedComponent:self]; - _isNeedJoinLayoutSystem = NO; } else if (_positionType == WXPositionTypeFixed) { [self.weexInstance.componentManager removeFixedComponent:self]; - _isNeedJoinLayoutSystem = YES; } _positionType = positionType;