cxfeng1 closed pull request #1535: [Core] Refactor. Adapt for scroller nested
in scroller.
URL: https://github.com/apache/incubator-weex/pull/1535
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
index ded029e1f7..dfe8824891 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
@@ -128,7 +128,7 @@ - (BOOL)_insertSubcomponent:(WXComponent *)subcomponent
atIndex:(NSInteger)index
}
// If a vertical list is added to a horizontal scroller, we need platform
dependent layout
- if (_flexCssNode && [self isMemberOfClass:[WXScrollerComponent class]] &&
(_scrollDirection == WXScrollDirectionHorizontal) &&
+ if (_flexCssNode && [self isKindOfClass:[WXScrollerComponent class]] &&
[subcomponent isKindOfClass:[WXScrollerComponent class]] &&
subcomponent->_positionType != WXPositionTypeFixed &&
(((WXScrollerComponent*)subcomponent).scrollDirection ==
WXScrollDirectionVertical)) {
@@ -139,7 +139,7 @@ - (BOOL)_insertSubcomponent:(WXComponent *)subcomponent
atIndex:(NSInteger)index
}
}
}
-
+
return inserted;
}
@@ -175,6 +175,19 @@ -(instancetype)initWithRef:(NSString *)ref type:(NSString
*)type styles:(NSDicti
_listenLoadMore = [events containsObject:@"loadmore"];
_scrollable = attributes[@"scrollable"] ? [WXConvert
BOOL:attributes[@"scrollable"]] : YES;
_offsetAccuracy = attributes[@"offsetAccuracy"] ? [WXConvert
WXPixelType:attributes[@"offsetAccuracy"]
scaleFactor:self.weexInstance.pixelScaleFactor] : 0;
+
+ /* let scroller fill the rest space if it is a child component and has
no fixed height & width.
+ WeexCore also does this in C++, but only for "scroller" and "list"
not including for
+ subclasses of WXScrollerComponent. */
+ if (_flexCssNode != nullptr) {
+ if (((_scrollDirection == WXScrollDirectionVertical &&
+ flexIsUndefined(_flexCssNode->getStyleHeight())) ||
+ (_scrollDirection == WXScrollDirectionHorizontal &&
+ flexIsUndefined(_flexCssNode->getStyleWidth()))) &&
+ _flexCssNode->getFlex() <= 0.0) {
+ _flexCssNode->set_flex(1.0);
+ }
+ }
id configCenter = [WXSDKEngine
handlerForProtocol:@protocol(WXConfigCenterProtocol)];
if ([configCenter
respondsToSelector:@selector(configForKey:defaultValue:isDefault:)]) {
@@ -1032,9 +1045,15 @@ - (void)_layoutPlatform
float width = _flexCssNode->getLayoutWidth();
float height = _flexCssNode->getLayoutHeight();
- _flexCssNode->setFlexDirection(WeexCore::kFlexDirectionRow, NO);
- _flexCssNode->setStyleHeight(_flexCssNode->getLayoutHeight());
- _flexCssNode->setStyleWidth(FlexUndefined, NO);
+ if (_scrollDirection == WXScrollDirectionVertical) {
+ _flexCssNode->setFlexDirection(WeexCore::kFlexDirectionColumn,
NO);
+ _flexCssNode->setStyleWidth(_flexCssNode->getLayoutWidth(),
NO);
+ _flexCssNode->setStyleHeight(FlexUndefined);
+ } else {
+ _flexCssNode->setFlexDirection(WeexCore::kFlexDirectionRow,
NO);
+ _flexCssNode->setStyleHeight(_flexCssNode->getLayoutHeight());
+ _flexCssNode->setStyleWidth(FlexUndefined, NO);
+ }
_flexCssNode->markAllDirty();
std::pair<float, float> renderPageSize;
renderPageSize.first = self.weexInstance.frame.size.width;
diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm
b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm
index 7ee51754e1..41dacfd33b 100644
--- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm
+++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm
@@ -27,6 +27,7 @@
#import "WXMonitor.h"
#import "WXSDKInstance_performance.h"
#import "WXCellComponent.h"
+#import "WXCoreBridge.h"
bool flexIsUndefined(float value) {
return isnan(value);
@@ -67,6 +68,13 @@ - (void)layoutDidFinish
WXAssertMainThread();
}
+- (void)updateLayoutStyles:(NSDictionary*)styles
+{
+ WXPerformBlockOnComponentThread(^{
+ [WXCoreBridge callUpdateStyle:self.weexInstance.instanceId
ref:self.ref data:styles];
+ });
+}
+
#pragma mark Private
- (void)_setRenderObject:(void *)object
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent.h
b/ios/sdk/WeexSDK/Sources/Model/WXComponent.h
index 1799e07942..95fe14d30a 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXComponent.h
+++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent.h
@@ -180,6 +180,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)layoutDidFinish;
+/**
+ * @abstract Update component's CSS style values for external components.
+ * Could be called in any thread and will be scheduled to component thread.
+ */
+- (void)updateLayoutStyles:(NSDictionary*)styles;
///--------------------------------------
/// @name View Management
diff --git a/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm
b/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm
index 0b7c019a52..93f7d009b8 100644
--- a/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm
+++ b/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm
@@ -175,6 +175,7 @@ - (void)_initViewPropertyWithStyles:(NSDictionary *)styles
_lastBoxShadow = _boxShadow;
}
}
+
- (void)_transitionUpdateViewProperty:(NSDictionary *)styles
{
WX_CHECK_COMPONENT_TYPE(self.componentType)
@@ -256,7 +257,7 @@ - (void)_updateViewStyles:(NSDictionary *)styles
[_layer setNeedsDisplay];
}
self.transform = transform;
- }else if (styles[@"transformOrigin"]) {
+ } else if (styles[@"transformOrigin"]) {
[_transform setTransformOrigin:[WXConvert
NSString:styles[@"transformOrigin"]]];
if (!CGRectEqualToRect(self.calculatedFrame, CGRectZero)) {
[_transform applyTransformForView:_view];
@@ -265,7 +266,7 @@ - (void)_updateViewStyles:(NSDictionary *)styles
}
}
--(void)resetBorder:(NSArray *)styles
+- (void)resetBorder:(NSArray *)styles
{
WX_BOARD_RADIUS_RESET_ALL(borderRadius);
WX_BOARD_RADIUS_RESET(borderTopLeftRadius);
@@ -286,7 +287,7 @@ -(void)resetBorder:(NSArray *)styles
WX_BOARD_COLOR_RESET(borderBottomColor);
}
--(void)_resetStyles:(NSArray *)styles
+- (void)_resetStyles:(NSArray *)styles
{
if (styles && [styles containsObject:@"backgroundColor"]) {
_backgroundColor = [UIColor clearColor];
@@ -319,7 +320,7 @@ - (void)_unloadViewWithReusing:(BOOL)isReusing
[self _removeAllEvents];
- if(self.ancestorScroller){
+ if (self.ancestorScroller) {
[self.ancestorScroller removeStickyComponent:self];
[self.ancestorScroller removeScrollToListener:self];
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services