apptekstudios / ASCollectionView

A SwiftUI collection view with support for custom layouts, preloading, and more.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ASCollectionView Incorrect Cell Sizing Before Scroll?

moxie0 opened this issue · comments

Using a minimal code sample:

import SwiftUI
import ASCollectionView_SwiftUI

struct SampleViewModel : Identifiable {
    let id : Int
}

struct ContentView: View {
    
    @State var viewModels : [SampleViewModel] = []
    
    var body: some View {
        ASCollectionView(data: viewModels) {
            (viewModel : SampleViewModel, context: ASCellContext) in
            Text("\(viewModel.id)")
        }.onAppear {
            self.load()
        }
    }
    
    func load() {
        DispatchQueue.main.async {
            self.viewModels = (0 ..< 10).map { (i : Int) in
                    SampleViewModel(id: i)
            }
        }
    }
}

The first four cells are rendered correctly sized, but the subsequent three cells are rendered "too tall." Inspecting the layout reveals that the Text views are sized correctly, but the parent ASCollectionViewCell are mysteriously large.

Simulator Screen Shot - iPhone 11 Pro - 2020-09-07 at 17 39 05

The instant that you scroll the ASCollectionView, all cells are rendered correctly for the duration of the ASCollectionView's existence:

Simulator Screen Shot - iPhone 11 Pro - 2020-09-07 at 17 41 06

Xcode Version:

  • 11.7

Simulator, Device, Both?

  • Simulator and device, iOS 13.6.1 and iOS 13.7