CollectionManager - a UICollectionView manager that allows you to easily manage sections. Sections can be: vertical, horizontal and consist of one cell.
- Add CollectionManager in the pod file.
target 'app_name' do
use_frameworks!
pod 'CollectionManager' -> 'last.version'
- Next, install the library from the root folder of the project.
pod install
- Connect the library in the desired class.
import CollectionManager
final class ViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView! {
didSet {
collectionManager = CollectionViewManager(
collectionView: collectionView,
sections: [
section
],
hiddenSections: [],
config: .default
)
}
}
var collectionManager: Manager!
var section: SectionManager!
override func viewDidLoad() {
super.viewDidLoad()
}
}
Property | getter, setter |
---|---|
collectionView | ✅, ❌ |
flowLayout | ✅, ❌ |
config | ✅, ❌ |
visibleSections | ✅, ❌ |
delegate | ✅, ✅ |
Property | getter, setter |
---|---|
collectionManager | ✅, ❌ |
sectionConfig | ✅, ✅ |
numberOfItems | ✅, ❌ |
cellSize | ✅, ✅ |
headerHeight | ✅, ✅ |
SectionManager properties also available in TypedSection and ViewControllerSection.
Property | getter, setter |
---|---|
skeletonSetup | ✅, ✅ |
loadingState | ✅, ❌ |
rows | ✅, ✅ |
columns | ✅, ✅ |
onLoadingView | ✅, ✅ |
isNeedOnLoadingBottomViewCell | ✅, ✅ |
onLoadingBottomViewCellSize | ✅, ✅ |
Property | getter, setter |
---|---|
viewController | ✅, ❌ |
reusableId | ✅, ✅ |
loadingState | ✅, ❌ |
func reloadData(
in section: SectionManager? = nil,
onlyVisible: Bool = true
)
Example:
// Reload data in only visible sections.
collectionManager.reloadData()
// Reload data in all sections.
collectionManager.reloadData(onlyVisible: false)
// Reload data in the section if it is visible.
collectionManager.reloadData(in: section)
// Will reload data in the section even if it is hidden.
collectionManager.reloadData(in: section, onlyVisible: false)
func reloadSection(_ section: SectionManager)
Example:
// Reload data in the section if it is visible.
collectionManager.reloadSection(section)
func setSection(
_ section: SectionManager,
hidden: Bool
)
Example:
// Show/hide section You need.
collectionManager.setSection(section, hidden: true)
func scrollToTop()
Example:
collectionManager.scrollToTop()
func sectionDidLoadData(_ section: SectionManager)
Example:
class Section: SectionManager {
var loadingState: SectionLoadingState = .none {
didSet {
guard loadingState != oldValue else { return }
switch loadingState {
case .full:
// You can show the skeleton on a cell there.
break
case .partial:
break
case .none:
// You can hide the skeleton from the cell there.
collectionManager?.sectionDidLoadData(self)
@unknown default:
fatalError("Unknown section loading state: \(loadingState)")
}
}
}
}
extension Section: SectionLoadable {
func loadData() {
loadingState = .full
}
}
❗️When using the method, the delegate will work on the completion of the data loading. Therefore, for better work, it is necessary to extend the class with the SectionLoadable protocol.
func setupCell(
cellFactory: CellFactory
) -> UICollectionViewCell {
fatalError("setupCell(at:cellFactory:) must be implemented in a sub-class")
}
Example:
override func setupCell(
cellFactory: CellFactory
) -> UICollectionViewCell {
return cellFactory.cell(of: YourCell.self)
}
func setupHeader(
cellFactory: CellFactory
) -> UICollectionReusableView? {
return nil
}
Example:
override func setupHeader(
cellFactory: CellFactory
) -> UICollectionReusableView? {
return cellFactory.header(of: YourHeaderView.self)
}
func itemDidSelect(index: Int)
Example:
override func itemDidSelect(index: Int) {
// Do something with Your data.
}
func didScrollToEnd()
Example:
override func didScrollToEnd() {
// You can upload data there, for example.
}
SectionManager methods also available in TypedSection and ViewControllerSection.
func update(with cellObjects: [Cell.CardCellObject]?)
Example:
update(with: ArrayOfItems)
func loadData()
Example:
func loadData() {
super.loadData()
// Request data there.
}
This method also available in a ViewControllerSection.
func uploadData()
Example:
func uploadData() {
super.uploadData()
// Request additional data there.
}
func dataLoaded()
Example:
func onDataLoaded() {
dataLoaded()
}
Kirill Kapis, [email protected]
CollectionManager is available under the MIT license. See the LICENSE file for more info.