[ASCellNode] Layout delegate should not be public as it must not be reset externally.

Do not call layout delegate method before the cell node is loaded.  This can happen if
application code calls -setNeedsLayout on the cell manually, and can confuse UIKit state
because we submit an empty batch update call on the next runloop.
This commit is contained in:
Scott Goodson
2016-02-20 15:24:44 -08:00
parent ca8357a364
commit d899f12f70
5 changed files with 27 additions and 22 deletions

View File

@@ -8,6 +8,28 @@
#import "ASCellNode.h"
@interface ASCellNode (Internal)
@protocol ASCellNodeLayoutDelegate <NSObject>
/**
* Notifies the delegate that the specified cell node has done a relayout.
* The notification is done on main thread.
*
* This will not be called due to measurement passes before the node has loaded
* its view, even if triggered by -setNeedsLayout, as it is assumed these are
* not relevant to UIKit. Indeed, these calls can cause consistency issues.
*
* @param node A node informing the delegate about the relayout.
* @param sizeChanged `YES` if the node's `calculatedSize` changed during the relayout, `NO` otherwise.
*/
- (void)nodeDidRelayout:(ASCellNode *)node sizeChanged:(BOOL)sizeChanged;
@end
@interface ASCellNode ()
/*
* A delegate to be notified (on main thread) after a relayout.
*/
@property (nonatomic, weak) id<ASCellNodeLayoutDelegate> layoutDelegate;
@end

View File

@@ -14,19 +14,6 @@ NS_ASSUME_NONNULL_BEGIN
typedef NSUInteger ASCellNodeAnimation;
@protocol ASCellNodeLayoutDelegate <NSObject>
/**
* Notifies the delegate that the specified cell node has done a relayout.
* The notification is done on main thread.
*
* @param node A node informing the delegate about the relayout.
* @param sizeChanged `YES` if the node's `calculatedSize` changed during the relayout, `NO` otherwise.
*/
- (void)nodeDidRelayout:(ASCellNode *)node sizeChanged:(BOOL)sizeChanged;
@end
/**
* Generic cell node. Subclass this instead of `ASDisplayNode` to use with `ASTableView` and `ASCollectionView`.
*/
@@ -71,11 +58,6 @@ typedef NSUInteger ASCellNodeAnimation;
*/
@property (nonatomic, assign) BOOL highlighted;
/*
* A delegate to be notified (on main thread) after a relayout.
*/
@property (nonatomic, weak) id<ASCellNodeLayoutDelegate> layoutDelegate;
/*
* ASCellNode must forward touch events in order for UITableView and UICollectionView tap handling to work. Overriding
* these methods (e.g. for highlighting) requires the super method be called.

View File

@@ -6,7 +6,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "ASCellNode.h"
#import "ASCellNode+Internal.h"
#import "ASInternalHelpers.h"
#import <AsyncDisplayKit/_ASDisplayView.h>
@@ -27,6 +27,7 @@
@end
@implementation ASCellNode
@synthesize layoutDelegate = _layoutDelegate;
- (instancetype)init
{
@@ -97,7 +98,7 @@
CGSize oldSize = self.calculatedSize;
[super setNeedsLayout];
if (_layoutDelegate != nil) {
if (_layoutDelegate != nil && self.isNodeLoaded) {
BOOL sizeChanged = !CGSizeEqualToSize(oldSize, self.calculatedSize);
ASPerformBlockOnMainThread(^{
[_layoutDelegate nodeDidRelayout:self sizeChanged:sizeChanged];

View File

@@ -1882,7 +1882,6 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
- (ASSizeRange)constrainedSizeForCalculatedLayout
{
ASDisplayNodeAssertThreadAffinity(self);
return _constrainedSize;
}

View File

@@ -10,6 +10,7 @@
#import "ASAssert.h"
#import "ASBatchFetching.h"
#import "ASCellNode+Internal.h"
#import "ASChangeSetDataController.h"
#import "ASDelegateProxy.h"
#import "ASDisplayNode+Beta.h"