From 641929c4e5cccc3a5cd92c33fab1a052bf6e6caf Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Fri, 21 Aug 2015 17:22:55 +0300 Subject: [PATCH 1/4] By default, cell nodes in table view should fill its width. So the min constrained width is updated to enforce this behaviour. --- AsyncDisplayKit/ASTableView.mm | 3 ++- examples/Kittens/Sample/KittenNode.mm | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index 6a9a3bd3..8948591d 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -791,7 +791,8 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) { } // Default size range - return ASSizeRangeMake(CGSizeZero, CGSizeMake(_maxWidthForNodesConstrainedSize, FLT_MAX)); + return ASSizeRangeMake(CGSizeMake(_maxWidthForNodesConstrainedSize, 0), + CGSizeMake(_maxWidthForNodesConstrainedSize, FLT_MAX)); } - (void)dataControllerLockDataSource diff --git a/examples/Kittens/Sample/KittenNode.mm b/examples/Kittens/Sample/KittenNode.mm index a852bcb8..84e4b49e 100644 --- a/examples/Kittens/Sample/KittenNode.mm +++ b/examples/Kittens/Sample/KittenNode.mm @@ -136,6 +136,7 @@ static const CGFloat kInnerPadding = 10.0f; { _imageNode.preferredFrameSize = _isImageEnlarged ? CGSizeMake(2.0 * kImageSize, 2.0 * kImageSize) : CGSizeMake(kImageSize, kImageSize); _textNode.flexShrink = YES; + _textNode.flexGrow = YES; return [ASInsetLayoutSpec From 98b41a4b1cb706195623596750275e27cd3183b4 Mon Sep 17 00:00:00 2001 From: Garrett Moon Date: Wed, 26 Aug 2015 16:15:18 -0700 Subject: [PATCH 2/4] scrollable directions was invalid for non-flow layouts as bounds and contentSize were zero on init --- .../Details/ASCollectionViewLayoutController.mm | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/AsyncDisplayKit/Details/ASCollectionViewLayoutController.mm b/AsyncDisplayKit/Details/ASCollectionViewLayoutController.mm index 86551027..cbed7f2b 100644 --- a/AsyncDisplayKit/Details/ASCollectionViewLayoutController.mm +++ b/AsyncDisplayKit/Details/ASCollectionViewLayoutController.mm @@ -13,6 +13,7 @@ #import "ASAssert.h" #import "ASCollectionView.h" #import "CGRect+ASConvenience.h" +#import "UICollectionViewLayout+ASConvenience.h" struct ASDirectionalScreenfulBuffer { CGFloat positiveDirection; // Positive relative to iOS Core Animation layer coordinate space. @@ -56,7 +57,7 @@ typedef struct ASRangeGeometry ASRangeGeometry; @interface ASCollectionViewLayoutController () { - UIScrollView * __weak _scrollView; + ASCollectionView * __weak _collectionView; UICollectionViewLayout * __strong _collectionViewLayout; std::vector _updateRangeBoundsIndexedByRangeType; ASScrollDirection _scrollableDirections; @@ -72,7 +73,7 @@ typedef struct ASRangeGeometry ASRangeGeometry; } _scrollableDirections = [collectionView scrollableDirections]; - _scrollView = collectionView; + _collectionView = collectionView; _collectionViewLayout = [collectionView collectionViewLayout]; _updateRangeBoundsIndexedByRangeType = std::vector(ASLayoutRangeTypeCount); return self; @@ -94,8 +95,13 @@ typedef struct ASRangeGeometry ASRangeGeometry; - (ASRangeGeometry)rangeGeometryWithScrollDirection:(ASScrollDirection)scrollDirection rangeTuningParameters:(ASRangeTuningParameters)rangeTuningParameters { - CGRect rangeBounds = _scrollView.bounds; - CGRect updateBounds = _scrollView.bounds; + CGRect rangeBounds = _collectionView.bounds; + CGRect updateBounds = _collectionView.bounds; + + //scrollable directions can change for non-flow layouts + if ([_collectionViewLayout asdk_isFlowLayout] == NO) { + _scrollableDirections = [_collectionView scrollableDirections]; + } BOOL canScrollHorizontally = ASScrollDirectionContainsHorizontalDirection(_scrollableDirections); if (canScrollHorizontally) { @@ -148,7 +154,7 @@ typedef struct ASRangeGeometry ASRangeGeometry; return YES; } - CGRect currentBounds = _scrollView.bounds; + CGRect currentBounds = _collectionView.bounds; if (CGRectIsEmpty(currentBounds)) { currentBounds = CGRectMake(0, 0, viewportSize.width, viewportSize.height); } From 075c39e3981e68b655011e24cdd08c4994eaff1d Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Thu, 27 Aug 2015 20:57:53 +0300 Subject: [PATCH 3/4] When relayout a node, preserve its frame origin. --- AsyncDisplayKit/ASDisplayNode.mm | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/AsyncDisplayKit/ASDisplayNode.mm b/AsyncDisplayKit/ASDisplayNode.mm index ab1a6440..59d0b783 100644 --- a/AsyncDisplayKit/ASDisplayNode.mm +++ b/AsyncDisplayKit/ASDisplayNode.mm @@ -600,9 +600,27 @@ void ASDisplayNodeRespectThreadAffinityOfNode(ASDisplayNode *node, void (^block) } else { // This is the root node. Trigger a full measurement pass on *current* thread. Old constrained size is re-used. [self measureWithSizeRange:oldConstrainedSize]; - CGRect bounds = self.bounds; - bounds.size = CGSizeMake(_layout.size.width, _layout.size.height); - self.bounds = bounds; + + CGSize oldSize = self.bounds.size; + CGSize newSize = _layout.size; + + if (! CGSizeEqualToSize(oldSize, newSize)) { + CGRect bounds = self.bounds; + bounds.size = newSize; + self.bounds = bounds; + + // Frame's origin must be preserved. Since it is computed from bounds size, anchorPoint + // and position (see frame setter in ASDisplayNode+UIViewBridge), position needs to be adjusted. + BOOL useLayer = (_layer && ASDisplayNodeThreadIsMain()); + CGPoint anchorPoint = (useLayer ? _layer.anchorPoint : self.anchorPoint); + CGPoint oldPosition = (useLayer ? _layer.position : self.position); + + CGFloat xDelta = (newSize.width - oldSize.width) * anchorPoint.x; + CGFloat yDelta = (newSize.height - oldSize.height) * anchorPoint.y; + CGPoint newPosition = CGPointMake(oldPosition.x + xDelta, oldPosition.y + yDelta); + + useLayer ? _layer.position = newPosition : self.position = newPosition; + } } } From 62303ebeecbe1797f878dfcfaa3b74b79f77969f Mon Sep 17 00:00:00 2001 From: Garrett Moon Date: Fri, 28 Aug 2015 13:37:39 -0700 Subject: [PATCH 4/4] array must be init'd otherwise arrayByAddingObject returns nil. --- AsyncDisplayKit/Layout/ASStaticLayoutSpec.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/AsyncDisplayKit/Layout/ASStaticLayoutSpec.mm b/AsyncDisplayKit/Layout/ASStaticLayoutSpec.mm index 61a6d172..eca2637a 100644 --- a/AsyncDisplayKit/Layout/ASStaticLayoutSpec.mm +++ b/AsyncDisplayKit/Layout/ASStaticLayoutSpec.mm @@ -44,6 +44,11 @@ return [[self alloc] initWithChildren:children]; } +- (instancetype)init +{ + return [self initWithChildren:@[]]; +} + - (instancetype)initWithChildren:(NSArray *)children { if (!(self = [super init])) {