All Projects → Shopify → Functionaltabledata

Shopify / Functionaltabledata

Licence: mit
Declarative UITableViewDataSource implementation

Programming Languages

swift
15916 projects
declarative
70 projects

Projects that are alternatives of or similar to Functionaltabledata

Persei
Animated top menu for UITableView / UICollectionView / UIScrollView written in Swift
Stars: ✭ 3,395 (+878.39%)
Mutual labels:  uicollectionview, uitableview
XLRefresh
iOS 下拉刷新工具
Stars: ✭ 25 (-92.8%)
Mutual labels:  uitableview, uicollectionview
GenericCells
Creating generic UITableViewCells and UICollectionViewCells instead of subclasses.
Stars: ✭ 81 (-76.66%)
Mutual labels:  uitableview, uicollectionview
HDEmptyView
一个Swift语言封装的EmptyView显示库,可作用于WKWebView、UITableView、UICollectionView 无网络提醒或者空数据提醒
Stars: ✭ 29 (-91.64%)
Mutual labels:  uitableview, uicollectionview
iOSEasyList
A data-driven UICollectionView and UITableView framework for building fast and flexible lists
Stars: ✭ 29 (-91.64%)
Mutual labels:  uitableview, uicollectionview
PagedLists
Paginated UITableView and UICollectionViews for iOS.
Stars: ✭ 69 (-80.12%)
Mutual labels:  uitableview, uicollectionview
Transfiguration
Mystical way to transform data into reusable view in Swift
Stars: ✭ 14 (-95.97%)
Mutual labels:  uitableview, uicollectionview
Squaremosaiclayout
An extandable mosaic UICollectionViewLayout with a focus on extremely flexible customizations 🔶
Stars: ✭ 243 (-29.97%)
Mutual labels:  uicollectionview, uitableview
WBListKit
A data-driven UICollectionView&UITableView framework for building fast and flexible lists by declarative syntax.
Stars: ✭ 32 (-90.78%)
Mutual labels:  uitableview, uicollectionview
MultiSelect
swift
Stars: ✭ 12 (-96.54%)
Mutual labels:  uitableview, uicollectionview
Cyanic
Declarative, state-driven UI framework
Stars: ✭ 32 (-90.78%)
Mutual labels:  uitableview, uicollectionview
Wlemptystate
WLEmptyState is an iOS based component that lets you customize the view when the dataset of a UITableView or a UICollectionView is empty. We created a sample project with the WLEmptyState component to show how you can use it.
Stars: ✭ 305 (-12.1%)
Mutual labels:  uicollectionview, uitableview
IQListKit
Model driven UITableView/UICollectionView
Stars: ✭ 51 (-85.3%)
Mutual labels:  uitableview, uicollectionview
TinyCoordinator
The Swift version of ThinningCoordinator focus on lighter view controllers.
Stars: ✭ 18 (-94.81%)
Mutual labels:  uitableview, uicollectionview
Macroid
A modular functional UI language for Android
Stars: ✭ 537 (+54.76%)
Mutual labels:  functional-programming, user-interface
ios ui recipe showcase
iOSアプリ開発 - UI実装であると嬉しいレシピブック掲載サンプル
Stars: ✭ 54 (-84.44%)
Mutual labels:  uitableview, uicollectionview
Flowkit
A declarative type-safe framework for building fast and flexible list with Tables & Collection
Stars: ✭ 215 (-38.04%)
Mutual labels:  uicollectionview, uitableview
Tabanimated
A skeleton screen framework based on native for iOS. (一个由iOS原生组件映射出骨架屏的框架,包含快速植入,低耦合,兼容复杂视图等特点,提供国内主流骨架屏动画的加载方案,同时支持上拉加载更多、自定制动画。)
Stars: ✭ 2,909 (+738.33%)
Mutual labels:  uicollectionview, uitableview
CollectionAndTableViewCompatible
A set of Swift protocols and Xcode snippets that will make it easy to do clean UITableView code
Stars: ✭ 34 (-90.2%)
Mutual labels:  uitableview, uicollectionview
Baraba
Make your UIScrollView scroll automatically when user is looking 👀 by tracking face using ARKit and AVFoundation
Stars: ✭ 268 (-22.77%)
Mutual labels:  uicollectionview, uitableview

Functional Table Data implements a functional renderer for UITableView. You pass it a complete description of your table state, and Functional Table Data compares it with the previous render call to insert, update, and remove the sections and cells that have changed. This massively simplifies state management of complex UI.

No longer do you have to manually track the number of sections, cells, and indices of your UI. Build one method that generates your table state structure from your data. The provided HostCell generic makes it easy to add FunctionalTableData support to UITableViewCells.

Noteworthy features
💯 Functional approach for maintaining table state
👷‍ Reusable views and states
Unit tests
🔀 Automatic diff in your states
❤️ Used across Shopify's iOS apps
🙅 No more IndexPath bookkeeping

Installation

Manual

Simply drag and drop FunctionalTableData/FunctionalTableData.xcodeproj into your Xcode project.

Swift Package Manager (SPM)

Add https://github.com/Shopify/FunctionalTableData to your package dependencies.

Carthage

Add the following to your Cartfile:

github "Shopify/FunctionalTableData"

Getting started

To use the Functional Table Data (FTD) two things are required, one instance of UITableView, and an instance of the FTD itself. Once both are available, typically in a view controller's viewDidLoad, they are connected together using functionalTableData.tableView = yourTableViewInstance. After this, every time we want to display/update the data we simply call functionalTableData.renderAndDiff(sections).

For more information, read our documentation.

Usage

Any time you want to update the data currently being displayed you generate the new state and pass it off to your instance of the Functional Table Data. The FTD is then responsible for computing the differences between the previous state and the next state and updating itself as necessary.

The FunctionalTableData holds onto an array of sections where each section has a key. This key must be unique across all sections but should be deterministic so that it's possible to adjust the rows contained within that section without replacing the entire section itself.

let section = TableSection(key: "header-unique-key", rows: [])

Each section contains a series of rows where each row value must conform to the CellConfigType protocol.

/// The simplest possible version of a cell that displays a label.
/// Useful to get started, but in most cases a more robust state should be used allowing more customization.
typealias LabelCell = HostCell<UILabel, String, LayoutMarginsTableItemLayout>

let cells: [CellConfigType] = [
	LabelCell(key: "company", state: "Shopify") { view, state in
		view.text = state
	},
	LabelCell(key: "location", state: "🇨🇦") { view, state in
		view.text = state
	}
]

The rows themselves also have a key which must be unique inside of that section. This key is used to determine when new rows are added to a section, if any were removed, or if any moved to a different location. Additionally, each CellConfig type implements an isEqual function to determine if two of them represent the same data being displayed. This allows for a single cell to perform a state change operation, that is, a toggle changing from its off to on state, a text value changing, etc.

After assigning the variable rows to our previously created section, all that is needed to display the data in the table view is this method.

functionalTableData.renderAndDiff([section])

Building new Cells

Knowing that a cell consists of a view and state let's start with a simple example, a cell that displays a label. By specifying the generic requirements of HostCell, the simplest possible example is one that takes an UILabel as its view, a String as its state and LayoutMarginsTableItemLayout as the layout (See TableItemLayout for more info).

typealias LabelCell = HostCell<UILabel, String, LayoutMarginsTableItemLayout>

// Usage
LabelCell(key: "company", state: "Shopify") { view, state in
	view.text = state
}

Although, the previous code is very useful to get started, in most cases a more robust state should be used allowing more customization. A better example would be something like this

typealias LabelCell = HostCell<UILabel, LabelState, LayoutMarginsTableItemLayout>

struct LabelState: Equatable {
	let text: String
	let alignment: NSTextAlignment
	let color: UIColor

	static func ==(lhs: LabelState, rhs: LabelState) -> Bool {
		return lhs.text == rhs.text && lhs.alignment == rhs.alignment && lhs.color == rhs.color
	}
}

// Usage
LabelCell(key: "company", state: LabelState(text: "Shopify",
                                            alignment: .center,
                                            color: .green)) { view, state in
	guard let state = state else {
		// If the state is `nil`, prepare this view to be reused
		view.text = ""
		view.textAlignment = .natural
		view.textColor = .black
		return
	}
	view.text = state.text
	view.textAlignment = state.alignment
	view.textColor = state.color
}

At the end of the day HostCell is just one of the possible implementations of CellConfigType, that's the underlying power of this framework.

Other resources

Seen other articles in the wild? Feel free to open a pull request.

License

Functional Table Data is under the MIT License

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