I've got it working using this initializer in AsyncDisplayKit v2.4, Swift:
ASCellNode(viewControllerBlock: { () -> UIViewController }, didLoad: { (ASDisplayNode) -> Void })
Here's a working example:
func tableNode(_ tableNode: ASTableNode, nodeBlockForRowAt indexPath: IndexPath) - > ASCellNodeBlock {
let content = self.contentList[indexPath.row]
// Return the old cell only for specific rows
if content.type == "MyOldContentThatUsesUITableViewCell" {
return {
// Load OldContentCell through a view block on the main thread
let cellHeight: CGFloat = 367.0
let cellNode = ASCellNode(viewControllerBlock: { () - > UIViewController in
let viewController = UIViewController()
// Load a cell using xib
guard let cell = Bundle.main.loadNibNamed("OldContentCell", owner: self, options: nil) ? [0] as ? OldContentCell else {
return viewController
}
// Since it's on the main thread, we can use UIScreen to get the full width
cell.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: cellHeight)
viewController.view.addSubview(cell)
return viewController
}, didLoad: nil)
// Width here doesn't really matter.. it will try and expand the cell's width
// to the ASTableNode's width
cellNode.style.preferredSize = CGSize(width: 100.0, height: cellHeight)
return cellNode
}
}
// Return a real ASCellNode totally managed by AsyncDisplayKit
let cellNodeBlock: () -> ASCellNode = {
// My subclass of ASCellNode
return ContentCellNode(content: content, contentIndex: indexPath.row)
}
return cellNodeBlock
}
I have also tried using the view block instead of view controller block that did not work.. the block never got executed:
ASCellNode(viewBlock: { () -> UIView })