You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ac...@apache.org on 2018/03/06 04:06:31 UTC

[2/2] incubator-weex git commit: [WEEX-218][iOS] support leftGap and rightGap for waterfall component

[WEEX-218][iOS] support leftGap and rightGap for waterfall component

support leftGap and rightGap for waterfall component, thus you can specify
 the leftGap and rightGap for cell inside waterfall component.

feature:218


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/52c19397
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/52c19397
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/52c19397

Branch: refs/heads/master
Commit: 52c1939774eea8c671abcb117495116e9834ef10
Parents: e9d5e3f
Author: acton393 <zh...@gmail.com>
Authored: Mon Feb 12 17:39:51 2018 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Tue Mar 6 12:04:55 2018 +0800

----------------------------------------------------------------------
 .../Component/Recycler/WXMultiColumnLayout.h    |  2 ++
 .../Component/Recycler/WXMultiColumnLayout.m    | 21 ++++++++++++++++++--
 .../Component/Recycler/WXRecyclerComponent.m    | 12 +++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/52c19397/ios/sdk/WeexSDK/Sources/Component/Recycler/WXMultiColumnLayout.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/Recycler/WXMultiColumnLayout.h b/ios/sdk/WeexSDK/Sources/Component/Recycler/WXMultiColumnLayout.h
index 4ad4a9b..3311cde 100644
--- a/ios/sdk/WeexSDK/Sources/Component/Recycler/WXMultiColumnLayout.h
+++ b/ios/sdk/WeexSDK/Sources/Component/Recycler/WXMultiColumnLayout.h
@@ -45,6 +45,8 @@ extern NSString * const kCollectionSupplementaryViewKindHeader;
 @property (nonatomic, strong) WXLength *columnCount;
 
 @property (nonatomic, strong) WXLength *columnWidth;
+@property (nonatomic, assign) float leftGap;
+@property (nonatomic, assign) float rightGap;
 
 @property (nonatomic, assign) float columnGap;
 

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/52c19397/ios/sdk/WeexSDK/Sources/Component/Recycler/WXMultiColumnLayout.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/Recycler/WXMultiColumnLayout.m b/ios/sdk/WeexSDK/Sources/Component/Recycler/WXMultiColumnLayout.m
index b7ae652..3f8151a 100644
--- a/ios/sdk/WeexSDK/Sources/Component/Recycler/WXMultiColumnLayout.m
+++ b/ios/sdk/WeexSDK/Sources/Component/Recycler/WXMultiColumnLayout.m
@@ -120,6 +120,22 @@ NSString * const kMultiColumnLayoutCell = @"WXMultiColumnLayoutCell";
     }
 }
 
+- (void)setLeftGap:(float)leftGap
+{
+    if (_rightGap != leftGap) {
+        _rightGap = leftGap;
+        [self _cleanComputed];
+    }
+}
+
+- (void)setRightGap:(float)rightGap
+{
+    if (_rightGap != rightGap) {
+        _rightGap = rightGap;
+        [self _cleanComputed];
+    }
+}
+
 - (CGFloat)computedColumnWidth
 {
     if (!_computedColumnWidth && !_computedColumnCount) {
@@ -189,7 +205,7 @@ NSString * const kMultiColumnLayoutCell = @"WXMultiColumnLayoutCell";
                 CGFloat itemHeight = [self.delegate collectionView:self.collectionView layout:self heightForItemAtIndexPath:indexPath];
                 UICollectionViewLayoutAttributes *itemAttributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
                 NSUInteger column = [self _minHeightColumnForAllColumns];
-                CGFloat x = insets.left + (columnWidth + columnGap) * column;
+                CGFloat x = insets.left + (columnWidth + columnGap) * column+_leftGap;
                 if (column >= [self.columnsMaxHeights count]) {
                     return;
                 }
@@ -347,7 +363,8 @@ NSString * const kMultiColumnLayoutCell = @"WXMultiColumnLayoutCell";
     
     int columnCount;
     float columnWidth ;
-    float availableWidth = self.contentWidth - (insets.left + insets.right);
+    float availableWidth = self.contentWidth - (insets.left + insets.right+_leftGap + _rightGap);
+    
     computeColumnWidthAndCount(availableWidth, self.columnCount, self.columnWidth, self.columnGap, &columnCount, &columnWidth);
     if (availableWidth <= 0) {
         return;

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/52c19397/ios/sdk/WeexSDK/Sources/Component/Recycler/WXRecyclerComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/Recycler/WXRecyclerComponent.m b/ios/sdk/WeexSDK/Sources/Component/Recycler/WXRecyclerComponent.m
index c67ac6a..99c6b22 100644
--- a/ios/sdk/WeexSDK/Sources/Component/Recycler/WXRecyclerComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/Recycler/WXRecyclerComponent.m
@@ -132,6 +132,12 @@ typedef enum : NSUInteger {
             WXMultiColumnLayout *layout = (WXMultiColumnLayout *)_collectionViewlayout;
             layout.columnWidth = [WXConvert WXLength:attributes[@"columnWidth"] isFloat:YES scaleFactor:scaleFactor] ? : [WXLength lengthWithFloat:0.0 type:WXLengthTypeAuto];
             layout.columnCount = [WXConvert WXLength:attributes[@"columnCount"] isFloat:NO scaleFactor:1.0] ? : [WXLength lengthWithInt:1 type:WXLengthTypeFixed];
+            if (attributes[@"leftGap"]) {
+                layout.leftGap = [WXConvert WXPixelType:attributes[@"leftGap"] scaleFactor:scaleFactor];
+            }
+            if (attributes[@"rightGap"]) {
+                layout.rightGap = [WXConvert WXPixelType:attributes[@"rightGap"] scaleFactor:scaleFactor];
+            }
             layout.columnGap = [self _floatValueForColumnGap:([WXConvert WXLength:attributes[@"columnGap"] isFloat:YES scaleFactor:scaleFactor] ? : [WXLength lengthWithFloat:0.0 type:WXLengthTypeNormal])];
             
             layout.delegate = self;
@@ -236,6 +242,12 @@ typedef enum : NSUInteger {
             layout.columnGap = [self _floatValueForColumnGap:([WXConvert WXLength:attributes[@"columnGap"] isFloat:YES scaleFactor:scaleFactor])];
             needUpdateLayout = YES;
         }
+        if (attributes[@"leftGap"]) {
+            layout.leftGap = [WXConvert WXPixelType:attributes[@"leftGap"] scaleFactor:scaleFactor];
+        }
+        if (attributes[@"rightGap"]) {
+            layout.rightGap = [WXConvert WXPixelType:attributes[@"rightGap"] scaleFactor:scaleFactor];
+        }
         
         if (needUpdateLayout) {
             for (WXComponent *component in self.subcomponents) {