iosswiftuicollectionviewasyncdisplaykitiglistkit

How to implement the ListCollectionViewLayout while using Texture?


I have been having trouble getting the ListCollectionViewLayout, the stock layout provided by IGListKit, to work together with Texture (formerly AsyncDisplayKit).

This is my Collection View Controller:

let collectionNode: ASCollectionNode!
var refreshControl : UIRefreshControl?
var layout: ListCollectionViewLayout

var pageTitle: String?

var feedItems: [FeedItem] = [FeedItem]()

lazy var adapter: ListAdapter = {
    return ListAdapter(updater: ListAdapterUpdater(), viewController: self, workingRangeSize: 1)
}()

init() {
    layout = ListCollectionViewLayout.init(stickyHeaders: false, scrollDirection: .vertical, topContentInset: 0, stretchToEdge: false)
    self.collectionNode = ASCollectionNode(collectionViewLayout: layout)
    super.init(node: self.collectionNode)
    self.adapter.setASDKCollectionNode(self.collectionNode)
    self.adapter.dataSource = self
    self.collectionNode.alwaysBounceVertical = true
    refreshControl = UIRefreshControl()
    refreshControl?.addTarget(self, action: #selector(refreshContent), for: .valueChanged)
    self.collectionNode.view.addSubview(refreshControl!)

}

This is the Section Controller:

class HashtagSectionController: ListSectionController, ASSectionController {

weak var delegate: HashtagDataDelegate?
var pushViewDelegate: PushViewControllerDelegate?
var pushUserDelegate: PushUsernameDelegate?
var isLoading: Bool

func nodeForItem(at index: Int) -> ASCellNode {
    guard let feedItem = object else { return ASCellNode() }

    let node = DiscoverCellNode(post: feedItem.post, user: feedItem.user)
    DispatchQueue.main.async {
        node.contentNode.delegate = self
    }
    return node
}

override init() {
    self.isLoading = false
    super.init()
    self.inset = UIEdgeInsets(top: 10, left: 0, bottom: 20, right: 0)
}

var object: FeedItem?

func nodeBlockForItem(at index: Int) -> ASCellNodeBlock {
    guard let feedItem = object else { return {
        return ASCellNode()
        }
    }
    return {
        let node = DiscoverCellNode(post: feedItem.post, user: feedItem.user)
        DispatchQueue.main.async {
            node.contentNode.delegate = self
        }
        return node
    }
}

override func numberOfItems() -> Int {
    return 1
}

override func didUpdate(to object: Any) {
    self.object = object as? FeedItem
}

override func didSelectItem(at index: Int) {
    guard let feedItem = object else { return }
    pushViewDelegate?.pushViewController(post: feedItem.post, user: feedItem.user)
}

override func sizeForItem(at index: Int) -> CGSize {
    return ASIGListSectionControllerMethods.sizeForItem(at: index)
    //return CGSize(width: 120, height: 120)
}

override func cellForItem(at index: Int) -> UICollectionViewCell {
    return ASIGListSectionControllerMethods.cellForItem(at: index, sectionController: self)
}

}

So I am unsure as to why this isn't working. Am I missing a Delegate the ListCollectionLayout needs in order to work. I get an error stating "layoutSize is invalid and unsafe to provide to CoreAnimation".


Solution

  • I ended up not using the listkit and decided to use just the diffing algorithm with the Texture collection view.