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

Commit 73bf9e3

Browse files
wqyfavorcxfeng1
authored andcommitted
[Core] Refactor. Adapt for scroller nested in scroller. (#1535)
1 parent eaab049 commit 73bf9e3

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ - (BOOL)_insertSubcomponent:(WXComponent *)subcomponent atIndex:(NSInteger)index
128128
}
129129

130130
// If a vertical list is added to a horizontal scroller, we need platform dependent layout
131-
if (_flexCssNode && [self isMemberOfClass:[WXScrollerComponent class]] && (_scrollDirection == WXScrollDirectionHorizontal) &&
131+
if (_flexCssNode && [self isKindOfClass:[WXScrollerComponent class]] &&
132132
[subcomponent isKindOfClass:[WXScrollerComponent class]] &&
133133
subcomponent->_positionType != WXPositionTypeFixed &&
134134
(((WXScrollerComponent*)subcomponent).scrollDirection == WXScrollDirectionVertical)) {
@@ -139,7 +139,7 @@ - (BOOL)_insertSubcomponent:(WXComponent *)subcomponent atIndex:(NSInteger)index
139139
}
140140
}
141141
}
142-
142+
143143
return inserted;
144144
}
145145

@@ -175,6 +175,19 @@ -(instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDicti
175175
_listenLoadMore = [events containsObject:@"loadmore"];
176176
_scrollable = attributes[@"scrollable"] ? [WXConvert BOOL:attributes[@"scrollable"]] : YES;
177177
_offsetAccuracy = attributes[@"offsetAccuracy"] ? [WXConvert WXPixelType:attributes[@"offsetAccuracy"] scaleFactor:self.weexInstance.pixelScaleFactor] : 0;
178+
179+
/* let scroller fill the rest space if it is a child component and has no fixed height & width.
180+
WeexCore also does this in C++, but only for "scroller" and "list" not including for
181+
subclasses of WXScrollerComponent. */
182+
if (_flexCssNode != nullptr) {
183+
if (((_scrollDirection == WXScrollDirectionVertical &&
184+
flexIsUndefined(_flexCssNode->getStyleHeight())) ||
185+
(_scrollDirection == WXScrollDirectionHorizontal &&
186+
flexIsUndefined(_flexCssNode->getStyleWidth()))) &&
187+
_flexCssNode->getFlex() <= 0.0) {
188+
_flexCssNode->set_flex(1.0);
189+
}
190+
}
178191

179192
id configCenter = [WXSDKEngine handlerForProtocol:@protocol(WXConfigCenterProtocol)];
180193
if ([configCenter respondsToSelector:@selector(configForKey:defaultValue:isDefault:)]) {
@@ -1032,9 +1045,15 @@ - (void)_layoutPlatform
10321045
float width = _flexCssNode->getLayoutWidth();
10331046
float height = _flexCssNode->getLayoutHeight();
10341047

1035-
_flexCssNode->setFlexDirection(WeexCore::kFlexDirectionRow, NO);
1036-
_flexCssNode->setStyleHeight(_flexCssNode->getLayoutHeight());
1037-
_flexCssNode->setStyleWidth(FlexUndefined, NO);
1048+
if (_scrollDirection == WXScrollDirectionVertical) {
1049+
_flexCssNode->setFlexDirection(WeexCore::kFlexDirectionColumn, NO);
1050+
_flexCssNode->setStyleWidth(_flexCssNode->getLayoutWidth(), NO);
1051+
_flexCssNode->setStyleHeight(FlexUndefined);
1052+
} else {
1053+
_flexCssNode->setFlexDirection(WeexCore::kFlexDirectionRow, NO);
1054+
_flexCssNode->setStyleHeight(_flexCssNode->getLayoutHeight());
1055+
_flexCssNode->setStyleWidth(FlexUndefined, NO);
1056+
}
10381057
_flexCssNode->markAllDirty();
10391058
std::pair<float, float> renderPageSize;
10401059
renderPageSize.first = self.weexInstance.frame.size.width;

ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#import "WXMonitor.h"
2828
#import "WXSDKInstance_performance.h"
2929
#import "WXCellComponent.h"
30+
#import "WXCoreBridge.h"
3031

3132
bool flexIsUndefined(float value) {
3233
return isnan(value);
@@ -67,6 +68,13 @@ - (void)layoutDidFinish
6768
WXAssertMainThread();
6869
}
6970

71+
- (void)updateLayoutStyles:(NSDictionary*)styles
72+
{
73+
WXPerformBlockOnComponentThread(^{
74+
[WXCoreBridge callUpdateStyle:self.weexInstance.instanceId ref:self.ref data:styles];
75+
});
76+
}
77+
7078
#pragma mark Private
7179

7280
- (void)_setRenderObject:(void *)object

ios/sdk/WeexSDK/Sources/Model/WXComponent.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ NS_ASSUME_NONNULL_BEGIN
180180
*/
181181
- (void)layoutDidFinish;
182182

183+
/**
184+
* @abstract Update component's CSS style values for external components.
185+
* Could be called in any thread and will be scheduled to component thread.
186+
*/
187+
- (void)updateLayoutStyles:(NSDictionary*)styles;
183188

184189
///--------------------------------------
185190
/// @name View Management

ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ - (void)_initViewPropertyWithStyles:(NSDictionary *)styles
175175
_lastBoxShadow = _boxShadow;
176176
}
177177
}
178+
178179
- (void)_transitionUpdateViewProperty:(NSDictionary *)styles
179180
{
180181
WX_CHECK_COMPONENT_TYPE(self.componentType)
@@ -256,7 +257,7 @@ - (void)_updateViewStyles:(NSDictionary *)styles
256257
[_layer setNeedsDisplay];
257258
}
258259
self.transform = transform;
259-
}else if (styles[@"transformOrigin"]) {
260+
} else if (styles[@"transformOrigin"]) {
260261
[_transform setTransformOrigin:[WXConvert NSString:styles[@"transformOrigin"]]];
261262
if (!CGRectEqualToRect(self.calculatedFrame, CGRectZero)) {
262263
[_transform applyTransformForView:_view];
@@ -265,7 +266,7 @@ - (void)_updateViewStyles:(NSDictionary *)styles
265266
}
266267
}
267268

268-
-(void)resetBorder:(NSArray *)styles
269+
- (void)resetBorder:(NSArray *)styles
269270
{
270271
WX_BOARD_RADIUS_RESET_ALL(borderRadius);
271272
WX_BOARD_RADIUS_RESET(borderTopLeftRadius);
@@ -286,7 +287,7 @@ -(void)resetBorder:(NSArray *)styles
286287
WX_BOARD_COLOR_RESET(borderBottomColor);
287288
}
288289

289-
-(void)_resetStyles:(NSArray *)styles
290+
- (void)_resetStyles:(NSArray *)styles
290291
{
291292
if (styles && [styles containsObject:@"backgroundColor"]) {
292293
_backgroundColor = [UIColor clearColor];
@@ -319,7 +320,7 @@ - (void)_unloadViewWithReusing:(BOOL)isReusing
319320

320321
[self _removeAllEvents];
321322

322-
if(self.ancestorScroller){
323+
if (self.ancestorScroller) {
323324
[self.ancestorScroller removeStickyComponent:self];
324325
[self.ancestorScroller removeScrollToListener:self];
325326
}

0 commit comments

Comments
 (0)