HomeiOS Developmentios - UICollectionViewCompositionalLayout Dynamic Heights Inflicting Format Changes and Flickering

ios – UICollectionViewCompositionalLayout Dynamic Heights Inflicting Format Changes and Flickering


I am utilizing UICollectionViewCompositionalLayout to create a vertically scrolling checklist of horizontally scrolling (orthogonally scrolling) lists in my iOS app.

After I specify an estimated peak for each the merchandise and the group, the gathering view adjusts its peak when taller objects scroll into view.

If alternatively, I specify an estimated peak for the group and a fractional peak of 1.0 for the merchandise, the peak appears to be handled as an absolute worth, no matter constraints and compression resistance which are set.

Here is my createSection operate:

func createSection(sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection {
    let itemSize = NSCollectionLayoutSize(
        widthDimension: .absolute(90),
        heightDimension: .estimated(44)
    )
    let merchandise = NSCollectionLayoutItem(layoutSize: itemSize)
    let groupSize = NSCollectionLayoutSize(
        widthDimension: .fractionalWidth(90 / layoutEnvironment.container.effectiveContentSize.width),
        heightDimension: .estimated(44)
    )
    let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
    let part = NSCollectionLayoutSection(group: group)
    part.interGroupSpacing = 16.0
    part.orthogonalScrollingBehavior = .steady
    return part
}

I attempted subclassing UICollectionViewCompositionalLayout and overriding layoutAttributesForElementsInRect to regulate attributes based mostly on the tallest merchandise in every part. This resulted in flickering throughout scrolling, nevertheless, which I think is because of put together being referred to as constantly on bounds change.

I do not know the peak of the view in every cell prematurely. Nonetheless, I’ve ensured that they’re accurately constrained and that compression resistance is about to required on the vertical axis.

Anticipated Behaviour: The peak of every cell to be dynamically adjusted based mostly on its content material, with out inflicting structure modifications or flickering when cells of various heights become visible.

Precise Conduct: Specifying estimated peak for each merchandise and group causes structure modifications upon scrolling, whereas setting fractional peak for the merchandise leads to the group’s estimated peak being handled as an absolute worth. Overriding layoutAttributesForElementsInRect and adjusting there causes flickering.

How can I deal with dynamic cell heights in UICollectionViewCompositionalLayout with out inflicting these structure points? I might tremendously respect any recommendation or potential options.

Here is a Swift Playground demonstrating the issue: https://github.com/aodhol/CompositionalProblem/tree/primary

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments