apptekstudios / ASCollectionView

A SwiftUI collection view with support for custom layouts, preloading, and more.
MIT License
1.36k stars 160 forks source link

ASCollectionView Incorrect Cell Sizing Before Scroll? #178

Open moxie0 opened 4 years ago

moxie0 commented 4 years ago

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:

Simulator, Device, Both?