From c1640c7f59d8d1cec6a18f6ec04bd87563a4078c Mon Sep 17 00:00:00 2001 From: Scott Goodson Date: Thu, 24 Dec 2015 18:02:52 -0800 Subject: [PATCH] Implement getter methods for new table / collection delegate / dataSource. Make ASTableView node-backed. --- AsyncDisplayKit/ASCollectionNode.m | 18 ++++++++++++++++++ AsyncDisplayKit/ASTableNode.m | 24 +++++++++++++++++++++++- AsyncDisplayKit/ASTableView.mm | 23 ++++++++++++----------- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/AsyncDisplayKit/ASCollectionNode.m b/AsyncDisplayKit/ASCollectionNode.m index 7cf49fbcb6..315c3626b9 100644 --- a/AsyncDisplayKit/ASCollectionNode.m +++ b/AsyncDisplayKit/ASCollectionNode.m @@ -84,6 +84,15 @@ } } +- (id )delegate +{ + if ([self pendingState]) { + return _pendingState.delegate; + } else { + return self.view.asyncDelegate; + } +} + - (void)setDataSource:(id )dataSource { if ([self pendingState]) { @@ -94,6 +103,15 @@ } } +- (id )dataSource +{ + if ([self pendingState]) { + return _pendingState.dataSource; + } else { + return self.view.asyncDataSource; + } +} + - (ASCollectionView *)view { return (ASCollectionView *)[super view]; diff --git a/AsyncDisplayKit/ASTableNode.m b/AsyncDisplayKit/ASTableNode.m index 136c6843aa..2d9bbc33bb 100644 --- a/AsyncDisplayKit/ASTableNode.m +++ b/AsyncDisplayKit/ASTableNode.m @@ -20,11 +20,15 @@ @property (nonatomic) _ASTablePendingState *pendingState; @end +@interface ASTableView () +- (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style; +@end + @implementation ASTableNode - (instancetype)initWithStyle:(UITableViewStyle)style { - if (self = [super initWithViewBlock:^UIView *{ return [[ASTableView alloc] initWithFrame:CGRectZero style:style]; }]) { + if (self = [super initWithViewBlock:^UIView *{ return [[ASTableView alloc] _initWithFrame:CGRectZero style:style]; }]) { return self; } return nil; @@ -63,6 +67,15 @@ } } +- (id )delegate +{ + if ([self pendingState]) { + return _pendingState.delegate; + } else { + return self.view.asyncDelegate; + } +} + - (void)setDataSource:(id )dataSource { if ([self pendingState]) { @@ -73,6 +86,15 @@ } } +- (id )dataSource +{ + if ([self pendingState]) { + return _pendingState.dataSource; + } else { + return self.view.asyncDataSource; + } +} + - (ASTableView *)view { return (ASTableView *)[super view]; diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index 8d799b5b4a..162a0fa1b2 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -8,6 +8,7 @@ #import "ASTableView.h" #import "ASTableViewInternal.h" +#import "ASTableNode.h" #import "ASAssert.h" #import "ASBatchFetching.h" @@ -159,33 +160,33 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; return [self initWithFrame:frame style:style asyncDataFetching:NO]; } +// FIXME: This method is deprecated and will probably be removed in or shortly after 2.0. - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style asyncDataFetching:(BOOL)asyncDataFetchingEnabled { return [self initWithFrame:frame style:style dataControllerClass:[self.class dataControllerClass] asyncDataFetching:asyncDataFetchingEnabled]; } - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style dataControllerClass:(Class)dataControllerClass asyncDataFetching:(BOOL)asyncDataFetchingEnabled +{ + ASTableNode *tableNode = [[ASTableNode alloc] initWithStyle:style]; + tableNode.frame = frame; + return tableNode.view; +} + +- (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style { if (!(self = [super initWithFrame:frame style:style])) return nil; - - // FIXME: asyncDataFetching is currently unreliable for some use cases. - // https://github.com/facebook/AsyncDisplayKit/issues/385 - asyncDataFetchingEnabled = NO; - [self configureWithDataControllerClass:dataControllerClass asyncDataFetching:asyncDataFetchingEnabled]; + [self configureWithDataControllerClass:[self.class dataControllerClass] asyncDataFetching:NO]; return self; } - (instancetype)initWithCoder:(NSCoder *)aDecoder { - if (!(self = [super initWithCoder:aDecoder])) - return nil; - - [self configureWithDataControllerClass:[self.class dataControllerClass] asyncDataFetching:NO]; - - return self; + NSLog(@"Warning: AsyncDisplayKit is not designed to be used with Interface Builder. Table properties set in IB will be lost."); + return [self initWithFrame:CGRectZero style:UITableViewStylePlain]; } - (void)dealloc