AsyncDisplayKit/Texture's ASTableNode clips ASTextNode content upon device orientation change

I am testing using an iPhone 13. I am able to demonstrate the problem with this simple example code:

import UIKit
import SnapKit
import AsyncDisplayKit
import LoremSwiftum

class ViewControllerAsyncDisplayKit: UIViewController, ASTableDataSource, ASTableDelegate {

    let tableNode = ASTableNode()
    let records = (0..<1000).map {NSAttributedString(string: "Row \($0) \(Lorem.sentences(Int.random(in: 1..<3)))", attributes: [.font:UIFont.systemFont(ofSize: 16, weight: .regular),.foregroundColor:UIColor.label])}
    
    override func viewDidLoad() {
        super.viewDidLoad()
                
        tableNode.dataSource = self
        tableNode.delegate = self
        tableNode.view.separatorColor = .red
        
        view.addSubview(tableNode.view)
        tableNode.view.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    func tableNode(_ tableNode: ASTableNode, numberOfRowsInSection section: Int) -> Int {
        return records.count
    }
    
    func tableNode(_ tableNode: ASTableNode, nodeBlockForRowAt indexPath: IndexPath) -> ASCellNodeBlock {
        let text = records[indexPath.row]
        return {
            return RecordNode(text: text)
        }
    }
}

class RecordNode: ASCellNode {
    
    private var titleNode = ASTextNode()
    
    init(text: NSAttributedString) {
    
        super.init()
        automaticallyManagesSubnodes = true
        automaticallyRelayoutOnSafeAreaChanges = true
        automaticallyRelayoutOnLayoutMarginsChanges = true
                
        titleNode.attributedText = text
    }
    
    override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
        return ASInsetLayoutSpec(insets: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10), child: titleNode)
    }
    
}

Upon rotation, some of the text in the cells gets clipped as the cell height appears incorrect:

enter image description here

It seems that the more variability in the length of sentences (height of original cell before orientation change), the more obvious the problem is.

I am able solve this using what I believe is a workaround:

override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {
    tableNode.performBatchUpdates(nil)
}

Is there a better way to prevent this without this workaround? Am I doing something wrong? Why can't the ASTableNode not calculate the correct height by itself as layoutSpecThatFits is called automatically after orientation change?

Upvotes: 0

Views: 17

Answers (0)

Related Questions