apptekstudios / ASCollectionView

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

Update Readme #37

Closed toyinswift closed 4 years ago

toyinswift commented 4 years ago

Please update the readme with very basic usage example. Am an android developer learning SwiftUi, so all these can be a little daunting!

Here is what i tried but am getting errors:

ASCollectionView(data: dataExample,
                         id: \.self,
                         layout: .init(layout: ASCollectionViewLayoutGrid(layoutMode: .adaptive(withMinItemSize: 100),
                        itemSpacing: 10,
                        lineSpacing: 10,
                        itemSize: .absolute(100))))
        { item in
            Color.blue
                .overlay(
                    Text("\(item)")
            )
        }

found that Grid example on stackoverflow. But am am getting this error message in Xcode "Use of unresolved identifier 'ASCollectionViewLayoutGrid'"

apptekstudios commented 4 years ago

Thanks for trying out this library :) I've added an example to the readme that demonstrates a collectionView with a single section. I also went and edited the stackoverflow answer as that was for an earlier version of this library.

Here's an example with the current version:

import ASCollectionView
import SwiftUI

struct SingleSectionExampleView: View {
    @State var dataExample = (0 ..< 30).map { $0 }

    var body: some View
    {
        ASCollectionView(data: dataExample, dataID: \.self) { item, _ in
            Color.blue
                .overlay(Text("\(item)"))
        }
        .layout {
            .grid(layoutMode: .adaptive(withMinItemSize: 100),
                  itemSpacing: 5,
                  lineSpacing: 5,
                  itemSize: .absolute(50))
        }
    }
}
apptekstudios commented 4 years ago

To make sure you're using the latest version you'll likely need to go to File → Swift packages → Update to latest package versions 👍