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) { if (!ownedByNode) {
// See commentary at the definition of .strongCollectionNode for why we create an ASCollectionNode. // 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; self.strongCollectionNode = collectionNode;
} }
@ -349,6 +352,11 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
return [[_dataController nodeAtIndexPath:indexPath] calculatedSize]; return [[_dataController nodeAtIndexPath:indexPath] calculatedSize];
} }
- (NSArray<NSArray <ASCellNode *> *> *)completedNodes
{
return [_dataController completedNodes];
}
- (ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath - (ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath
{ {
return [_dataController nodeAtIndexPath:indexPath]; return [_dataController nodeAtIndexPath:indexPath];

View File

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

View File

@ -198,14 +198,17 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
} }
if (!dataControllerClass) { if (!dataControllerClass) {
dataControllerClass = [self.class dataControllerClass]; dataControllerClass = [[self class] dataControllerClass];
} }
[self configureWithDataControllerClass:dataControllerClass]; [self configureWithDataControllerClass:dataControllerClass];
if (!ownedByNode) { if (!ownedByNode) {
// See commentary at the definition of .strongTableNode for why we create an ASTableNode. // 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; self.strongTableNode = tableNode;
} }
@ -333,6 +336,11 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
[self setTuningParameters:tuningParameters forRangeType:ASLayoutRangeTypeDisplay]; [self setTuningParameters:tuningParameters forRangeType:ASLayoutRangeTypeDisplay];
} }
- (NSArray<NSArray <ASCellNode *> *> *)completedNodes
{
return [_dataController completedNodes];
}
- (ASCellNode *)nodeForRowAtIndexPath:(NSIndexPath *)indexPath - (ASCellNode *)nodeForRowAtIndexPath:(NSIndexPath *)indexPath
{ {
return [_dataController nodeAtIndexPath:indexPath]; return [_dataController nodeAtIndexPath:indexPath];

View File

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

View File

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