Implement getter methods for new table / collection delegate / dataSource. Make ASTableView node-backed.

This commit is contained in:
Scott Goodson 2015-12-24 18:02:52 -08:00
parent 27c151095b
commit c1640c7f59
3 changed files with 53 additions and 12 deletions

View File

@ -84,6 +84,15 @@
} }
} }
- (id <ASCollectionDelegate>)delegate
{
if ([self pendingState]) {
return _pendingState.delegate;
} else {
return self.view.asyncDelegate;
}
}
- (void)setDataSource:(id <ASCollectionDataSource>)dataSource - (void)setDataSource:(id <ASCollectionDataSource>)dataSource
{ {
if ([self pendingState]) { if ([self pendingState]) {
@ -94,6 +103,15 @@
} }
} }
- (id <ASCollectionDataSource>)dataSource
{
if ([self pendingState]) {
return _pendingState.dataSource;
} else {
return self.view.asyncDataSource;
}
}
- (ASCollectionView *)view - (ASCollectionView *)view
{ {
return (ASCollectionView *)[super view]; return (ASCollectionView *)[super view];

View File

@ -20,11 +20,15 @@
@property (nonatomic) _ASTablePendingState *pendingState; @property (nonatomic) _ASTablePendingState *pendingState;
@end @end
@interface ASTableView ()
- (instancetype)_initWithFrame:(CGRect)frame style:(UITableViewStyle)style;
@end
@implementation ASTableNode @implementation ASTableNode
- (instancetype)initWithStyle:(UITableViewStyle)style - (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 self;
} }
return nil; return nil;
@ -63,6 +67,15 @@
} }
} }
- (id <ASTableDelegate>)delegate
{
if ([self pendingState]) {
return _pendingState.delegate;
} else {
return self.view.asyncDelegate;
}
}
- (void)setDataSource:(id <ASTableDataSource>)dataSource - (void)setDataSource:(id <ASTableDataSource>)dataSource
{ {
if ([self pendingState]) { if ([self pendingState]) {
@ -73,6 +86,15 @@
} }
} }
- (id <ASTableDataSource>)dataSource
{
if ([self pendingState]) {
return _pendingState.dataSource;
} else {
return self.view.asyncDataSource;
}
}
- (ASTableView *)view - (ASTableView *)view
{ {
return (ASTableView *)[super view]; return (ASTableView *)[super view];

View File

@ -8,6 +8,7 @@
#import "ASTableView.h" #import "ASTableView.h"
#import "ASTableViewInternal.h" #import "ASTableViewInternal.h"
#import "ASTableNode.h"
#import "ASAssert.h" #import "ASAssert.h"
#import "ASBatchFetching.h" #import "ASBatchFetching.h"
@ -159,33 +160,33 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
return [self initWithFrame:frame style:style asyncDataFetching:NO]; 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 - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style asyncDataFetching:(BOOL)asyncDataFetchingEnabled
{ {
return [self initWithFrame:frame style:style dataControllerClass:[self.class dataControllerClass] asyncDataFetching: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 - (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])) if (!(self = [super initWithFrame:frame style:style]))
return nil; 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; return self;
} }
- (instancetype)initWithCoder:(NSCoder *)aDecoder - (instancetype)initWithCoder:(NSCoder *)aDecoder
{ {
if (!(self = [super initWithCoder:aDecoder])) NSLog(@"Warning: AsyncDisplayKit is not designed to be used with Interface Builder. Table properties set in IB will be lost.");
return nil; return [self initWithFrame:CGRectZero style:UITableViewStylePlain];
[self configureWithDataControllerClass:[self.class dataControllerClass] asyncDataFetching:NO];
return self;
} }
- (void)dealloc - (void)dealloc