Disable creation of backing ASTable/CollectionNode for the *View varients (retain cycle).

This commit is contained in:
Scott Goodson 2016-01-09 20:44:24 -08:00
parent c3ef2efe0c
commit d45db5ac32
5 changed files with 30 additions and 5 deletions

View File

@ -150,7 +150,10 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
if (!ownedByNode) {
// See commentary at the definition of .strongCollectionNode for why we create an ASCollectionNode.
ASCollectionNode *collectionNode = [[ASCollectionNode alloc] _initWithCollectionView:self];
// FIXME: The _view pointer of the node retains us, but the node will die immediately if we don't
// retain it. At the moment there isn't a great solution to this, so we can't yet move our core
// logic to ASCollectionNode (required to have a shared superclass with ASTable*).
ASCollectionNode *collectionNode = nil; //[[ASCollectionNode alloc] _initWithCollectionView:self];
self.strongCollectionNode = collectionNode;
}
@ -349,6 +352,11 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
return [[_dataController nodeAtIndexPath:indexPath] calculatedSize];
}
- (NSArray<NSArray <ASCellNode *> *> *)completedNodes
{
return [_dataController completedNodes];
}
- (ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return [_dataController nodeAtIndexPath:indexPath];

View File

@ -31,8 +31,10 @@
- (instancetype)_initWithTableView:(ASTableView *)tableView
{
if (self = [super initWithViewBlock:^UIView *{ return tableView; }]) {
__unused ASTableView *tableView = [self view];
// Avoid a retain cycle. In this case, the ASTableView is creating us, and strongly retains us.
ASTableView * __weak weakTableView = tableView;
if (self = [super initWithViewBlock:^UIView *{ return weakTableView; }]) {
__unused __weak ASTableView *view = [self view];
return self;
}
return nil;

View File

@ -198,14 +198,17 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
}
if (!dataControllerClass) {
dataControllerClass = [self.class dataControllerClass];
dataControllerClass = [[self class] dataControllerClass];
}
[self configureWithDataControllerClass:dataControllerClass];
if (!ownedByNode) {
// See commentary at the definition of .strongTableNode for why we create an ASTableNode.
ASTableNode *tableNode = [[ASTableNode alloc] _initWithTableView:self];
// FIXME: The _view pointer of the node retains us, but the node will die immediately if we don't
// retain it. At the moment there isn't a great solution to this, so we can't yet move our core
// logic to ASTableNode (required to have a shared superclass with ASCollection*).
ASTableNode *tableNode = nil; //[[ASTableNode alloc] _initWithTableView:self];
self.strongTableNode = tableNode;
}
@ -333,6 +336,11 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
[self setTuningParameters:tuningParameters forRangeType:ASLayoutRangeTypeDisplay];
}
- (NSArray<NSArray <ASCellNode *> *> *)completedNodes
{
return [_dataController completedNodes];
}
- (ASCellNode *)nodeForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [_dataController nodeAtIndexPath:indexPath];

View File

@ -117,6 +117,8 @@ NS_ASSUME_NONNULL_BEGIN
- (ASDisplayNode *)rangeController:(ASRangeController *)rangeController nodeAtIndexPath:(NSIndexPath *)indexPath;
- (NSArray<NSArray <ASCellNode *> *> *)completedNodes;
@end
/**

View File

@ -13,10 +13,15 @@
#import "ViewController.h"
#import <AsyncDisplayKit/ASDisplayNode.h>
#import <AsyncDisplayKit/ASDisplayNode+Beta.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[ASDisplayNode setShouldUseNewRenderingRange:YES];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[UINavigationController alloc] init];