All Projects β†’ onmyway133 β†’ Micro

onmyway133 / Micro

Licence: other
🏎Fast diffing and type safe SwiftUI style data source for UICollectionView

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Micro

Datasources
πŸ’Ύ πŸ”œπŸ“± Type-safe data-driven CollectionView, TableView Framework. (We can also use ASCollectionNode)
Stars: ✭ 553 (+618.18%)
Mutual labels:  diff, uicollectionview, datasource
Carbon
🚴 A declarative library for building component-based user interfaces in UITableView and UICollectionView.
Stars: ✭ 1,034 (+1242.86%)
Mutual labels:  uicollectionview, datasource
Thinningcoordinator
The UITableView/UICollectionView dataSource/delegate thinning coordinator, help thinning your UIViewController!
Stars: ✭ 25 (-67.53%)
Mutual labels:  uicollectionview, datasource
Rglistkit
RGListKit is a Protocol & MVVM based framework to easily populate a UITableView or UICollectionView via single api.
Stars: ✭ 178 (+131.17%)
Mutual labels:  uicollectionview, datasource
TinyCoordinator
The Swift version of ThinningCoordinator focus on lighter view controllers.
Stars: ✭ 18 (-76.62%)
Mutual labels:  uicollectionview, datasource
Dtcollectionviewmanager
Protocol-oriented UICollectionView management, powered by generics and associated types.
Stars: ✭ 300 (+289.61%)
Mutual labels:  uicollectionview, datasource
Closures
Swifty closures for UIKit and Foundation
Stars: ✭ 1,720 (+2133.77%)
Mutual labels:  uicollectionview, datasource
iOSEasyList
A data-driven UICollectionView and UITableView framework for building fast and flexible lists
Stars: ✭ 29 (-62.34%)
Mutual labels:  uicollectionview, datasource
Diffabledatasources
πŸ’Ύ A library for backporting UITableView/UICollectionViewDiffableDataSource.
Stars: ✭ 601 (+680.52%)
Mutual labels:  diff, datasource
Parchment
A paging view controller with a highly customizable menu ✨
Stars: ✭ 2,812 (+3551.95%)
Mutual labels:  uicollectionview, swiftui
Genericdatasource
A generic small reusable components for data source implementation for UITableView/UICollectionView in Swift.
Stars: ✭ 127 (+64.94%)
Mutual labels:  uicollectionview, datasource
Rxdatasources Texture
ASTable and ASCollection Data Sources for RxSwift (Texture)
Stars: ✭ 25 (-67.53%)
Mutual labels:  diff, datasource
Flowkit
A declarative type-safe framework for building fast and flexible list with Tables & Collection
Stars: ✭ 215 (+179.22%)
Mutual labels:  uicollectionview, datasource
Changeset
Minimal edits from one collection to another
Stars: ✭ 807 (+948.05%)
Mutual labels:  diff, uicollectionview
Rxdatasources
UITableView and UICollectionView Data Sources for RxSwift (sections, animated updates, editing ...)
Stars: ✭ 2,784 (+3515.58%)
Mutual labels:  diff, datasource
sanic-admin
sanic-admin is a command line tool for automatically restarting sanic.
Stars: ✭ 15 (-80.52%)
Mutual labels:  reload
unidiff-rs
Unified diff parsing/metadata extraction library for Rust
Stars: ✭ 19 (-75.32%)
Mutual labels:  diff
TreeWalker
PHP JSON diff
Stars: ✭ 58 (-24.68%)
Mutual labels:  diff
2DUICollectionViewSwift
A simple and elegant 2Dimensional UICollectionView which is most commonly used in ecommerce apps, music streaming apps etc. Easily customisable as per your requirements as it is designed keeping the superset requirement in mind. Developed in latest Swift syntax.
Stars: ✭ 28 (-63.64%)
Mutual labels:  uicollectionview
LineChartView
An interactive line chart written in SwiftUI with many customizations (colors, line size, dots, haptic feedbacks). Support value and time series.
Stars: ✭ 59 (-23.38%)
Mutual labels:  swiftui

Micro

❀️ Support my apps ❀️

β€οΈβ€οΈπŸ˜‡πŸ˜πŸ€˜β€οΈβ€οΈ

For demo, check DemoMicro

Read more

Description

Most of the time, we want to apply model data to cell with smart diffing. Micro provides type safe SwiftUI style data source for UICollectionView, with super fast diffing powered by DeepDiff. Just declare a State with SwiftUI style forEach and Micro will reload with animated diffing

struct Blog: DiffAware {}
class BlogCell: UICollectionViewCell {}

let dataSource = DataSource(collectionView: collectionView)
dataSource.state = State {
    ForEach(blogs) { blog in
        Cell<BlogCell>() { context, cell in
            cell.nameLabel.text = blog.name
        }
        .onSelect { context in 
            print("cell at index \(context.indexPath.item) is selected")
        }
        .onSize { context in 
            CGSize(
                width: context.collectionView.frame.size.width, 
                height: 40
            )
        }
    }
}

The above uses Swift 5.1 function builder syntax, which uses forEach method under the hood. You can also do like below with forEach method.

dataSource.state = forEach(blogs) { blog in
    Cell<BlogCell>() { context, cell in
        cell.nameLabel.text = blog.name
    }
    .onSelect { context in 
        print("cell at index \(context.indexPath.item) is selected")
    }
    .onSize { context in 
        CGSize(
            width: context.collectionView.frame.size.width, 
            height: 40
        )
    }
}

Features

  • Supports iOS 8+
  • Declare in type safe manner with forEach
  • context provides additional information, like UICollectionView and IndexPath
  • Automatic reload with smart diffing whenever state is set
  • By default, diffing is animated, you can use dataSource.reload(newState:isAnimated:completion) to specify animated and completion

Advanced

Animate reloading

By default, when you set state on DataSource, animated diffing is performed. If you want to set animated property and to listen to completion event, you can use reload method

dataSource.reload(
    newState: newState,
    isAnimated: false,
    completion: { finished in
        print("reloade is finished")
    }
)

Complex model with multiple cell types

You can declare different Cell in forEach with different kinds of cell.

struct Movie: DiffAware {
    enum Kind: Equatable {
        case show(String)
        case loading
        case ad
    }

    let diffId = UUID()
    let kind: Kind

    static func compareContent(_ a: Movie, _ b: Movie) -> Bool {
        return a.kind == b.kind
    }
}

class MovieCell: UICollectionViewCell {
    let nameLabel: UILabel = .init()
}

class LoadingCell: UICollectionViewCell {}

class AdCell: UICollectionViewCell {}

let layout = UICollectionViewFlowLayout()
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
let dataSource = DataSource(collectionView: collectionView)
collectionView.dataSource = dataSource
collectionView.delegate = dataSource

let movies: [Movie] = [
    Movie(kind: .show("Titanic")),
    Movie(kind: .show("Batman")),
    Movie(kind: .loading),
    Movie(kind: .ad)
]

dataSource.state = forEach(movies) { movie in
    switch movie.kind {
    case .show(let name):
        return Cell<MovieCell>() { context, cell in
            cell.nameLabel.text = name
        }
        .onSelect { _ in

        }
        .onDeselect { _ in

        }
        .onWillDisplay { _, _ in

        }
        .onDidEndDisplay { _, _ in

        }
        .onSize { context in
            CGSize(width: context.collectionView.frame.size.width, height: 40)
        }
    case .loading:
        return Cell<LoadingCell>()
    case .ad:
        return Cell<AdCell>()
    }
}

Customize with subclass

DataSource is completely overridable, if you want to customize any methods, just subclass DataSource, override methods and access its state.models

class CustomDataSource: DataSource {
    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let blog = state.models[indexPath.item] as? Blog
        print(blog)
    }
}

Installation

Micro is also available through Swift Package Manager

.package(url: "https://github.com/onmyway133/Micro", from: "1.2.0")

Author

Khoa Pham, [email protected]

License

Micro is available under the MIT license. See the LICENSE file for more info.

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].