All Projects → bannzai → Conv

bannzai / Conv

Licence: mit
Conv smart represent UICollectionView data structure more than UIKit.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Conv

Carbon
🚴 A declarative library for building component-based user interfaces in UITableView and UICollectionView.
Stars: ✭ 1,034 (+598.65%)
Mutual labels:  uicollectionview
Basecomponents
BaseComponents aims to provide easily reusable and understandable components to increase productivity with UIKit and Foundation APIs
Stars: ✭ 92 (-37.84%)
Mutual labels:  uicollectionview
Closures
Swifty closures for UIKit and Foundation
Stars: ✭ 1,720 (+1062.16%)
Mutual labels:  uicollectionview
Expandable Collection View Kit
🗂 Expandable, hierarchical, flexible, declarative UICollectionView with diffable data sources & SwiftUI-like tree items builder [Swift 5.1, iOS & iPadOS 13].
Stars: ✭ 69 (-53.38%)
Mutual labels:  uicollectionview
Bubblecollectionviewlayout
Create bubble layout of UICollectionView using custom layout
Stars: ✭ 79 (-46.62%)
Mutual labels:  uicollectionview
Yltagschooser
用UICollectionView实现的兴趣标签选择器 (A interest tag selector implemented with the UICollectionView.)
Stars: ✭ 106 (-28.38%)
Mutual labels:  uicollectionview
Allkit
🛠 Async List Layout Kit
Stars: ✭ 40 (-72.97%)
Mutual labels:  uicollectionview
Stickyheaderflowlayout
Sticky headers for UICollectionView written in pure Swift (based on CSStickyHeaderFlowLayout)
Stars: ✭ 144 (-2.7%)
Mutual labels:  uicollectionview
Infinite Uicollectionview
Make a UICollectionView infinitely scrolling by looping through content
Stars: ✭ 82 (-44.59%)
Mutual labels:  uicollectionview
Genericdatasource
A generic small reusable components for data source implementation for UITableView/UICollectionView in Swift.
Stars: ✭ 127 (-14.19%)
Mutual labels:  uicollectionview
Drcollectionviewtablelayout Ios
UICollectionView 2d-table / grid / spreadsheet layout
Stars: ✭ 74 (-50%)
Mutual labels:  uicollectionview
Zjflexiblelayout
custom waterfall flow based on UICollectionView
Stars: ✭ 78 (-47.3%)
Mutual labels:  uicollectionview
Skeletonview
☠️ An elegant way to show users that something is happening and also prepare them to which contents they are awaiting
Stars: ✭ 10,804 (+7200%)
Mutual labels:  uicollectionview
Bmlongpressdragcellcollectionview
🎉 🎉 🎉 🎉 🎉 让你轻松实现类似支付宝的拖拽重排功能, 支持各种自定义操作。
Stars: ✭ 1,090 (+636.49%)
Mutual labels:  uicollectionview
Cpcollectionviewkit
Interesting UICollectionView layouts and transitions
Stars: ✭ 140 (-5.41%)
Mutual labels:  uicollectionview
Pagingkit
PagingKit provides customizable menu UI. It has more flexible layout and design than the other libraries.
Stars: ✭ 1,030 (+595.95%)
Mutual labels:  uicollectionview
Flowlayout
UICollectionView WaterFlowLayout. 瀑布流.
Stars: ✭ 94 (-36.49%)
Mutual labels:  uicollectionview
Wrcalendarview
Calendar Day and Week View for iOS
Stars: ✭ 147 (-0.68%)
Mutual labels:  uicollectionview
Squareflowlayout
🌄 UICollectionViewLayout subclass inspired by Instagram Discover page style layout.
Stars: ✭ 142 (-4.05%)
Mutual labels:  uicollectionview
Gskstretchyheaderview
A generic stretchy header for UITableView and UICollectionView
Stars: ✭ 1,624 (+997.3%)
Mutual labels:  uicollectionview

Swift4 CocoaPods Carthage Platform Lincense

Conv

Conv smart represent UICollectionView data structure more than UIKit.
Easy definition for UICollectionView DataSource and Delegate methods.

And Conv reload fast to use diffing algorithm based on the Paul Heckel's algorithm.

Insert and Delete Move item and section

Conv(called KONBU) means Seaweed in Japan.
This library is inspired by Shoyu. Thanks @yukiasai.

Usage

First, Conv need to prepare array of definition datastructure for section and item. And then it should conform Differenciable protocol for difference algorithm.

Section

enum SectionType: Int {
  case one
  case two
  case three

  static var allCases: [SectionType] {
    return [.one, .two, .three]
  }
}

extension SectionType: Differenciable {
  var differenceIdentifier: DifferenceIdentifier {
    return "\(self)"
  }
}
let sectionTypes = SectionType.allCases

Item

struct ItemModel {
    let index: Int
    let imageName: String
    var image: UIImage {
        return UIImage(named: imageName)!
    }
}

extension ItemModel: Differenciable {
    var differenceIdentifier: DifferenceIdentifier {
        return "\(index)" + imageName
    }
}
let itemModels = [
    ItemModel(index: 1, imageName: "forest"),
    ItemModel(index: 2, imageName: "moon"),
    ItemModel(index: 3, imageName: "pond"),
    ItemModel(index: 4, imageName: "river"),
]

Second, start to define data structure for section and item.
It use prepared Differenciable array.

collectionView
    .conv // #1
    .diffing() 
    .start() 
    .append(for: sectionTypes) { (sectionType, section) in // #2
        section.append(.header, headerOrFooter: { (header: SectionHeaderFooter<ListCollectionReusableView>) in // #3
            header.reusableIdentifier = "ListCollectionReusableView"
            header.size = CGSize(width: UIScreen.main.bounds.width, height: 50)
            header.configureView { view, _ in
                view.nameLabel.text = "\(sectionType)".uppercased()
                view.nameLabel.textColor = .white
                view.backgroundColor = sectionType.backgroundColor
            }
        })
        section.append(for: itemModels, items: { (itemModel, item: Item<ListCollectionViewCell>) in // #4
            item.reusableIdentifier = "ListCollectionViewCell"
            item.sizeFor({ _ -> CGSize in
                let gridCount: CGFloat = 3
                let edge = floor((UIScreen.main.bounds.width - (gridCount - 1)) / gridCount)
                let size = CGSize(width: edge, height: edge)
                return size
            })
            
            item.configureCell { (cell, info) in
                cell.setup(with: itemModel)
            }
            
            item.didSelect { [weak self] (item) in
                let viewController = DetailViewController(imageName: itemModel.imageName)
                self?.navigationController?.pushViewController(viewController, animated: true)
            }
        })
}

This swift code has the following meaning. It explain for # mark in code.

  1. Start to define UICollectionView data structure it using Conv.
  2. Append sections that number of sectionTypes. And start define about section.
  3. Append section header for each section. And start define about section header.
  4. Append items that number of itemModels for each section. And start define about item.

Last, If you want to render of collectionView, you call collectionView.update() your best timing.
update() calculate diff for minimum reloading data between before section and between before items.

collectionView.conv.update()

Or if you want to all realod cells, you can call reload(). It will be same behavior of collectionView.reloadData().

collectionView.conv.reload()

You can see more example to ConvExmaple

Algorithm

Conv to use diffing algorithm based on the Paul Heckel's algorithm.
And I also referred to other libraries below.

Install

CocoaPods

Conv is available through Cocoapods.
You can write it into target and exec pod install.

pod 'Conv'

Carthage

Conv is available through Carhtage.
You can write it into target and exec carthage update --platform iOS. And find conv framework and embed your project.

github 'bannzai/Conv'

Why Conv?

UIKit.UICollectionView has some problems.

  1. UICollectionView.dequeueXXX method not type safe. So, should convert to want class each cells.
  2. UICollectionViewDataSource and UICollectionViewDelegate(or DelegateFlowLayout) far away each configured functions. So, reading configuration flow for each indexPath very difficalt.
  3. Many case to use UICollectionView with Array. But extract element from array using indexPath many time.

Conv resolve these problem.

  1. Conv does not need to call UICollectionView.dequeueXXX. Because you can define configureCell method and get converted custom class cell.
section.append(for: itemModels, items: { (itemModel, item: Item<ListCollectionViewCell>) in // #4
    ...
    item.configureCell { (cell, info) in
        // cell is converted ListCollectionViewCell
        cell.setup(with: itemModel)
    }
})
  1. You can write to neary for each UICollectionView component. section,item,header and footer. So, this definition to be natural expression for UICollectionView data strcture, hierarchy, releation.

  2. When append section or item, you can passed allCases for configure UICollectionView. Next each element pass closure argument that define Conv.Section or Conv.Item. So, You can represent CollectionView data structure with extracted each element.

LICENSE

Conv is released under the MIT license. See LICENSE for details.

Header logo is released CC BY-NC 4.0 license. Original design by noainoue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].