AsyncDisplayKit is now Texture! LEARN MORE


ASNodeController (Beta)

To use this feature, you will need to import "ASNodeController+Beta.h"

The Texture team has many exciting ideas for expanding ASNodeController. Follow along here if you’d like to participate in shaping the future of node controllers.

For now, ASNodeController remains a simple, but powerful class.


The example project attached in the initial PR modifies the normal ASDKgram project to use an ASNodeController. This PhotoCellNodeController is used to manage the fetching of the comments data for a photo in a photo feed, once the photo enters the preload range. This node controller allows us to separate the preloading logic from where it previously existed in the PhotoCellNode “view” class.

To convert ASDKgram to use an ASNodeController, we first create a PhotoCellNodeController class.

This node controller overrides ASNodeController’s’ -loadNode method to create a PhotoCellNode once required. It is not neccessary to call super in this method.

This node controller also observes its node’s interface state in order to intelligently preload the photo’s comment feed model data when the PhotoCellNode enters the preload state (which indicates that the photo cell is likely to scroll onscreen soon).

All of this logic can be removed from where it previously existed in the “view” (our PhotoCellNode class), leading to a more concise and MVC-friendly view class.

Swift Objective-C
@implementation PhotoCellNodeController

- (void)loadNode
  self.node = [[PhotoCellNode alloc] initWithPhotoObject:self.photoModel];

- (void)didEnterPreloadState
  [super didEnterPreloadState];
  CommentFeedModel *commentFeedModel = _photoModel.commentFeed;
  [commentFeedModel refreshFeedWithCompletionBlock:^(NSArray *newComments) {
    // load comments for photo
    if (commentFeedModel.numberOfItemsInFeed > 0) {
      [self.node.photoCommentsNode updateWithCommentFeedModel:commentFeedModel];
      [self.node setNeedsLayout];


Edit on GitHub