All Projects → RxSwiftCommunity → Rxdatasources

RxSwiftCommunity / Rxdatasources

Licence: mit
UITableView and UICollectionView Data Sources for RxSwift (sections, animated updates, editing ...)

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to Rxdatasources

Datasources
💾 🔜📱 Type-safe data-driven CollectionView, TableView Framework. (We can also use ASCollectionNode)
Stars: ✭ 553 (-80.14%)
Mutual labels:  rxswift, datasource, diff, collectionview
Diffabledatasources
💾 A library for backporting UITableView/UICollectionViewDiffableDataSource.
Stars: ✭ 601 (-78.41%)
Mutual labels:  datasource, diff, tableview, collectionview
Differencekit
💻 A fast and flexible O(n) difference algorithm framework for Swift collection.
Stars: ✭ 2,986 (+7.26%)
Mutual labels:  diff, tableview, collectionview
Rxdatasources Texture
ASTable and ASCollection Data Sources for RxSwift (Texture)
Stars: ✭ 25 (-99.1%)
Mutual labels:  rxswift, datasource, diff
Rxasdatasources
RxDataSource for AsyncDisplayKit/Texture
Stars: ✭ 114 (-95.91%)
Mutual labels:  rxswift, tableview, collectionview
Modelassistant
Elegant library to manage the interactions between view and model in Swift
Stars: ✭ 26 (-99.07%)
Mutual labels:  datasource, tableview, collectionview
Rxrealmdatasources
An easy way to bind an RxRealm observable to a table or collection view
Stars: ✭ 154 (-94.47%)
Mutual labels:  binding, tableview, collectionview
Shsegmentedcontroltableview
Both scroll horizontal and vertical for segment scrollview which have a same header. — 类似半糖、美丽说主页与QQ音乐歌曲列表布局效果,实现不同菜单的左右滑动切换,同时支持类似tableview的顶部工具栏悬停(既可以左右滑动,又可以上下滑动)。兼容下拉刷新,上拉加载更多。现已加入swift豪华套餐,使用样例助你快速使用
Stars: ✭ 259 (-90.7%)
Mutual labels:  tableview, collectionview
Containercontroller
UI Component. This is a copy swipe-panel from app: Apple Maps, Stocks. Swift version
Stars: ✭ 273 (-90.19%)
Mutual labels:  tableview, collectionview
Buffer
Swift μ-framework for efficient array diffs and datasource adapters.
Stars: ✭ 349 (-87.46%)
Mutual labels:  datasource, tableview
mvcvm-swift-file-templates
Swift file templates for boosting mobile app development.
Stars: ✭ 16 (-99.43%)
Mutual labels:  rxswift, tableview
Rxswift
Reactive Programming in Swift
Stars: ✭ 21,163 (+660.17%)
Mutual labels:  rxswift, unidirectional
Iossampleapp
Sample iOS app demonstrating Coordinators, Dependency Injection, MVVM, Binding
Stars: ✭ 510 (-81.68%)
Mutual labels:  rxswift, binding
SNAdapter
iOS swift tableview and collectionView Adapter
Stars: ✭ 35 (-98.74%)
Mutual labels:  tableview, collectionview
DailyNews
Daily News is a news app with good looking user interface ! Apps architecture is MVVM and used RxSwift for binding.
Stars: ✭ 31 (-98.89%)
Mutual labels:  rxswift, collectionview
Rxiglistkit
RxSwift wrapper for IGListKit
Stars: ✭ 44 (-98.42%)
Mutual labels:  rxswift, collectionview
Emptykit
A lightweight, swift library for displaying emptyView whenever the view(tableView/collectionView) has no content to display, just like DZNEmptyDataSet
Stars: ✭ 117 (-95.8%)
Mutual labels:  tableview, collectionview
Micro
🏎Fast diffing and type safe SwiftUI style data source for UICollectionView
Stars: ✭ 77 (-97.23%)
Mutual labels:  diff, datasource
Pageable
An easy way to Pagination or Infinite scrolling for TableView/CollectionView
Stars: ✭ 44 (-98.42%)
Mutual labels:  tableview, collectionview
Reactorkit
A library for reactive and unidirectional Swift applications
Stars: ✭ 2,237 (-19.65%)
Mutual labels:  rxswift, unidirectional

Travis CI

Table and Collection view data sources

Features

  • O(N) algorithm for calculating differences
    • the algorithm has the assumption that all sections and items are unique so there is no ambiguity
    • in case there is ambiguity, fallbacks automagically on non animated refresh
  • it applies additional heuristics to send the least number of commands to sectioned view
    • even though the running time is linear, preferred number of sent commands is usually a lot less than linear
    • it is preferred (and possible) to cap the number of changes to some small number, and in case the number of changes grows towards linear, just do normal reload
  • Supports extending your item and section structures
    • just extend your item with IdentifiableType and Equatable, and your section with AnimatableSectionModelType
  • Supports all combinations of two level hierarchical animations for both sections and items
    • Section animations: Insert, Delete, Move
    • Item animations: Insert, Delete, Move, Reload (if old value is not equal to new value)
  • Configurable animation types for Insert, Reload and Delete (Automatic, Fade, ...)
  • Example app
  • Randomized stress tests (example app)
  • Supports editing out of the box (example app)
  • Works with UITableView and UICollectionView

Why

Writing table and collection view data sources is tedious. There is a large number of delegate methods that need to be implemented for the simplest case possible.

RxSwift helps alleviate some of the burden with a simple data binding mechanism:

  1. Turn your data into an Observable sequence
  2. Bind the data to the tableView/collectionView using one of:
  • rx.items(dataSource:protocol<RxTableViewDataSourceType, UITableViewDataSource>)
  • rx.items(cellIdentifier:String)
  • rx.items(cellIdentifier:String:Cell.Type:_:)
  • rx.items(_:_:)
let data = Observable<[String]>.just(["first element", "second element", "third element"])

data.bind(to: tableView.rx.items(cellIdentifier: "Cell")) { index, model, cell in
  cell.textLabel?.text = model
}
.disposed(by: disposeBag)

This works well with simple data sets but does not handle cases where you need to bind complex data sets with multiples sections, or when you need to perform animations when adding/modifying/deleting items.

These are precisely the use cases that RxDataSources helps solve.

With RxDataSources, it is super easy to just write

let dataSource = RxTableViewSectionedReloadDataSource<SectionModel<String, Int>>(configureCell: configureCell)
Observable.just([SectionModel(model: "title", items: [1, 2, 3])])
    .bind(to: tableView.rx.items(dataSource: dataSource))
    .disposed(by: disposeBag)

RxDataSources example app

How

Given the following custom data structure:

struct CustomData {
  var anInt: Int
  var aString: String
  var aCGPoint: CGPoint
}
  1. Start by defining your sections with a struct that conforms to the SectionModelType protocol:
  • define the Item typealias: equal to the type of items that the section will contain
  • declare an items property: of type array of Item
struct SectionOfCustomData {
  var header: String    
  var items: [Item]
}
extension SectionOfCustomData: SectionModelType {
  typealias Item = CustomData

   init(original: SectionOfCustomData, items: [Item]) {
    self = original
    self.items = items
  }
}
  1. Create a dataSource object and pass it your SectionOfCustomData type:
let dataSource = RxTableViewSectionedReloadDataSource<SectionOfCustomData>(
  configureCell: { dataSource, tableView, indexPath, item in
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
    cell.textLabel?.text = "Item \(item.anInt): \(item.aString) - \(item.aCGPoint.x):\(item.aCGPoint.y)"
    return cell
})
  1. Customize closures on the dataSource as needed:
  • titleForHeaderInSection
  • titleForFooterInSection
  • etc
dataSource.titleForHeaderInSection = { dataSource, index in
  return dataSource.sectionModels[index].header
}

dataSource.titleForFooterInSection = { dataSource, index in
  return dataSource.sectionModels[index].footer
}

dataSource.canEditRowAtIndexPath = { dataSource, indexPath in
  return true
}

dataSource.canMoveRowAtIndexPath = { dataSource, indexPath in
  return true
}
  1. Define the actual data as an Observable sequence of CustomData objects and bind it to the tableView
let sections = [
  SectionOfCustomData(header: "First section", items: [CustomData(anInt: 0, aString: "zero", aCGPoint: CGPoint.zero), CustomData(anInt: 1, aString: "one", aCGPoint: CGPoint(x: 1, y: 1)) ]),
  SectionOfCustomData(header: "Second section", items: [CustomData(anInt: 2, aString: "two", aCGPoint: CGPoint(x: 2, y: 2)), CustomData(anInt: 3, aString: "three", aCGPoint: CGPoint(x: 3, y: 3)) ])
]

Observable.just(sections)
  .bind(to: tableView.rx.items(dataSource: dataSource))
  .disposed(by: disposeBag)

Animated Data Sources

RxDataSources provides two special data source types that automatically take care of animating changes in the bound data source: RxTableViewSectionedAnimatedDataSource and RxCollectionViewSectionedAnimatedDataSource.

To use one of the two animated data sources, you must take a few extra steps on top of those outlined above:

  • SectionOfCustomData needs to conform to AnimatableSectionModelType
  • Your data model must conform to
    • IdentifiableType: The identity provided by the IdentifiableType protocol must be an immutable identifier representing an instance of the model. For example, in case of a Car model, you might want to use the car's plateNumber as its identity.
    • Equatable: Conforming to Equatable helps RxDataSources determine which cells have changed so it can animate only these specific cells. Meaning, changing any of the Car model's properties will trigger an animated reload of that cell.

Requirements

Xcode 10.2

Swift 5.0

For Swift 4.x version please use versions 3.0.0 ... 3.1.0 For Swift 3.x version please use versions 1.0 ... 2.0.2 For Swift 2.3 version please use versions 0.1 ... 0.9

Installation

We'll try to keep the API as stable as possible, but breaking API changes can occur.

CocoaPods

Podfile

pod 'RxDataSources', '~> 5.0'

Carthage

Cartfile

github "RxSwiftCommunity/RxDataSources" ~> 5.0

Swift Package Manager

Create a Package.swift file.

import PackageDescription

let package = Package(
    name: "SampleProject",
    dependencies: [
        .package(url: "https://github.com/RxSwiftCommunity/RxDataSources.git", from: "5.0.0")
    ]
)

If you are using Xcode 11 or higher, go to File / Swift Packages / Add Package Dependency... and enter package repository URL https://github.com/RxSwiftCommunity/RxDataSources.git, then follow the instructions.

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