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

[23/50] [abbrv] incubator-weex git commit: * [ios] fix issue that scrollable components can not scroll to top if frame.size < contentSize

* [ios] fix issue that scrollable components can not scroll to top if frame.size < contentSize


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

Branch: refs/heads/dev
Commit: c2f0b6552530370effb6637db955616e0aad95e4
Parents: cae9aa8
Author: \u9690\u98ce <cx...@apache.org>
Authored: Wed Mar 29 19:31:36 2017 +0800
Committer: \u9690\u98ce <cx...@apache.org>
Committed: Wed Mar 29 19:31:36 2017 +0800

----------------------------------------------------------------------
 .../Component/Recycler/WXRecyclerComponent.m        | 16 ++++++++--------
 ios/sdk/WeexSDK/Sources/Component/WXListComponent.m |  7 +------
 .../WeexSDK/Sources/Component/WXScrollerComponent.m | 10 ++--------
 3 files changed, 11 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c2f0b655/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 b5b5ac8..842fa1f 100644
--- a/ios/sdk/WeexSDK/Sources/Component/Recycler/WXRecyclerComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/Recycler/WXRecyclerComponent.m
@@ -45,6 +45,11 @@ typedef enum : NSUInteger {
     [self.wx_component layoutDidFinish];
 }
 
+- (void)setContentOffset:(CGPoint)contentOffset
+{
+    [super setContentOffset:contentOffset];
+}
+
 @end
 
 @interface WXCollectionViewCell : UICollectionViewCell
@@ -211,24 +216,19 @@ typedef enum : NSUInteger {
 
 - (void)scrollToComponent:(WXComponent *)component withOffset:(CGFloat)offset animated:(BOOL)animated
 {
-    if (_collectionView.contentSize.height <= _collectionView.frame.size.height) {
-        // can not scroll
-        return;
-    }
-    
     CGPoint contentOffset = _collectionView.contentOffset;
     CGFloat contentOffsetY = 0;
     
     CGRect rect;
     while (component) {
         if ([component isKindOfClass:[WXCellComponent class]]) {
-            NSIndexPath *toIndexPath = [self.dataController indexPathForCell:component];
+            NSIndexPath *toIndexPath = [self.dataController indexPathForCell:(WXCellComponent *)component];
             UICollectionViewLayoutAttributes *attributes = [_collectionView layoutAttributesForItemAtIndexPath:toIndexPath];
             rect = attributes.frame;
             break;
         }
         if ([component isKindOfClass:[WXHeaderComponent class]]) {
-            NSUInteger toIndex = [self.dataController indexForHeader:component];
+            NSUInteger toIndex = [self.dataController indexForHeader:(WXHeaderComponent *)component];
             UICollectionViewLayoutAttributes *attributes = [_collectionView layoutAttributesForSupplementaryElementOfKind:kCollectionSupplementaryViewKindHeader atIndexPath:[NSIndexPath indexPathWithIndex:toIndex]];
             rect = attributes.frame;
             break;
@@ -240,7 +240,7 @@ typedef enum : NSUInteger {
     contentOffsetY += rect.origin.y;
     contentOffsetY += offset * self.weexInstance.pixelScaleFactor;
     
-    if (contentOffsetY > _collectionView.contentSize.height - _collectionView.frame.size.height) {
+    if (_collectionView.contentSize.height >= _collectionView.frame.size.height && contentOffsetY > _collectionView.contentSize.height - _collectionView.frame.size.height) {
         contentOffset.y = _collectionView.contentSize.height - _collectionView.frame.size.height;
     } else {
         contentOffset.y = contentOffsetY;

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c2f0b655/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m
index bc31995..c598a3d 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXListComponent.m
@@ -173,11 +173,6 @@
 
 - (void)scrollToComponent:(WXComponent *)component withOffset:(CGFloat)offset animated:(BOOL)animated
 {
-    if (_tableView.contentSize.height <= _tableView.frame.size.height) {
-        // can not scroll
-        return;
-    }
-    
     CGPoint contentOffset = _tableView.contentOffset;
     CGFloat contentOffsetY = 0;
     
@@ -201,7 +196,7 @@
     contentOffsetY += cellRect.origin.y;
     contentOffsetY += offset * self.weexInstance.pixelScaleFactor;
     
-    if (contentOffsetY > _tableView.contentSize.height - _tableView.frame.size.height) {
+    if (_tableView.contentSize.height >= _tableView.frame.size.height && contentOffsetY > _tableView.contentSize.height - _tableView.frame.size.height) {
         contentOffset.y = _tableView.contentSize.height - _tableView.frame.size.height;
     } else {
         contentOffset.y = contentOffsetY;

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c2f0b655/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m
index 50dc059..eb7c15d 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m
@@ -318,12 +318,6 @@ WX_EXPORT_METHOD(@selector(resetLoadmore))
 - (void)scrollToComponent:(WXComponent *)component withOffset:(CGFloat)offset animated:(BOOL)animated
 {
     UIScrollView *scrollView = (UIScrollView *)self.view;
-    
-    if ((_scrollDirection == WXScrollDirectionHorizontal && scrollView.contentSize.width <= scrollView.frame.size.width)
-        || (_scrollDirection == WXScrollDirectionVertical && scrollView.contentSize.height <= scrollView.frame.size.height)) {
-        // can not scroll
-        return;
-    }
 
     CGPoint contentOffset = scrollView.contentOffset;
     CGFloat scaleFactor = self.weexInstance.pixelScaleFactor;
@@ -332,7 +326,7 @@ WX_EXPORT_METHOD(@selector(resetLoadmore))
         CGFloat contentOffetX = [component.supercomponent.view convertPoint:component.view.frame.origin toView:self.view].x;
         contentOffetX += offset * scaleFactor;
         
-        if (contentOffetX > scrollView.contentSize.width - scrollView.frame.size.width) {
+        if (scrollView.contentSize.width >= scrollView.frame.size.width && contentOffetX > scrollView.contentSize.width - scrollView.frame.size.width) {
             contentOffset.x = scrollView.contentSize.width - scrollView.frame.size.width;
         } else {
             contentOffset.x = contentOffetX;
@@ -341,7 +335,7 @@ WX_EXPORT_METHOD(@selector(resetLoadmore))
         CGFloat contentOffetY = [component.supercomponent.view convertPoint:component.view.frame.origin toView:self.view].y;
         contentOffetY += offset * scaleFactor;
         
-        if (contentOffetY > scrollView.contentSize.height - scrollView.frame.size.height) {
+        if (scrollView.contentSize.height >= scrollView.frame.size.height && contentOffetY > scrollView.contentSize.height - scrollView.frame.size.height) {
             contentOffset.y = scrollView.contentSize.height - scrollView.frame.size.height;
         } else {
             contentOffset.y = contentOffetY;