Skip to content

maios/DataSourcerer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DataSourcerer

DataSourcerer provides a type-safe DSL style data source for UICollectionView powered by UICollectionViewDiffableDataSource

This project is heavily inspired by https://github.com/onmyway133/Micro

Basic Usage

To fill in collection view with data:

  1. Connect the data source to the collection view.
  2. Apply a State with a list of Section or a single Section by using ForEach.
let dataSource = CollectionViewDataSource(collectionView: collectionView)
dataSource.state = State {
    ForEach(items) { item in 
        BaseListCell<Item> { cell, _, _ in 
            // config cell
        }
        .onSelected {
            // Cell is selected
        }
        .onDeselected {
            // Cell is deselected
        }
    }
}

Section

Section represents a section in the collection view's data source, consisted of a list of data models and its corresponding cell. It also has its own section header and section footer. Additionally you are going to have to specify support for section header and section footer in your collection view's layout.

Example using UICollectionLayoutListConfiguration

var listConfig = UICollectionLayoutListConfiguration(appearance: .grouped)
listConfig.headerMode = .supplementary
listConfig.footerMode = .supplementary

dataSource.state = State {
    Section(sectionIdentifier: .main) {
        ForEach(items) { item in 
            BaseListCell<Item> { cell, _, _ in
                // configure cell
            }
        }
    }
    .registerHeader(HeaderView.self) { headerView in 
        // configure header
    }
    .registerFooter(FooterView.self) { footerView in 
        // configure footer
    }
}

About

Collection View Data source wizard at your service

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages