Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couldn't find 'visible' supplementary element of kind UICollectionElementKindSectionHeader assertion #385

Closed
mrvincenzo opened this issue Jun 23, 2017 · 2 comments

Comments

@mrvincenzo
Copy link

Getting the Couldn't find 'visible' supplementary element of kind UICollectionElementKindSectionHeader at index path <> in map <> assertion when animating section insertion with performBatchUpdates in ASCollectionNode. Please see facebookarchive/AsyncDisplayKit#3158 for additional details.

Starting from scratch. First section insertion works well. Second section insertion gets the above assertion. Code snippet that reproduces the issue:

import AsyncDisplayKit

final class BatchUpdatesAssertion: ASViewController<ASCollectionNode> {

    fileprivate var timer: Timer!
    fileprivate var numberOfSections = 0

    init() {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .vertical

        let node = ASCollectionNode(collectionViewLayout: layout)
        node.registerSupplementaryNode(ofKind: UICollectionElementKindSectionHeader)
  
        super.init(node: node)
  
        node.dataSource = self
        node.delegate = self
  
        timer = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) {  _ in
            self.numberOfSections = self.numberOfSections + 1
            self.animateInsetion()
        }
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

// MARK: - ASCollectionDataSource

extension BatchUpdatesAssertion: ASCollectionDataSource {
    func animateInsetion() {
        node.performBatchUpdates({ 
            node.insertSections(IndexSet(integer: 0))
            node.insertItems(at: [IndexPath(item: 0, section: 0)])
        }, completion: { _ in
        })
    }

    func numberOfSections(in collectionNode: ASCollectionNode) -> Int {
        return numberOfSections
    }

    func collectionNode(_ collectionNode: ASCollectionNode, numberOfItemsInSection section: Int) -> Int {
        return 1
    }

    func collectionNode(_ collectionNode: ASCollectionNode, nodeForItemAt indexPath: IndexPath) -> ASCellNode {
        let node = ASTextCellNode()
        node.text = "item"
        return node
    }

    func collectionNode(_ collectionNode: ASCollectionNode, nodeForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> ASCellNode {
        let node = ASTextCellNode()
        node.text = "section"
        return node
    }
}

// MARK: - ASCollectionDelegate

extension BatchUpdatesAssertion: ASCollectionDelegate {
    func collectionNode(_ collectionNode: ASCollectionNode, constrainedSizeForItemAt indexPath: IndexPath) -> ASSizeRange {
        return ASSizeRangeUnconstrained
    }

    func collectionNode(_ collectionNode: ASCollectionNode, sizeRangeForHeaderInSection section: Int) -> ASSizeRange {
        return ASSizeRangeUnconstrained
    }
}
@Pacek
Copy link

Pacek commented Jun 29, 2017

There's also example project with this crash in #397.

@Adlai-Holler
Copy link
Member

Fix in #404 thanks for the detailed report @mrvincenzo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants