ViewElements is a framework to build UITableView with ease.
All iOS apps have at least one UITableView. It displays a list of elements (called UITableViewCell) that users can scroll vertically. These cells are reused automatically as they go in and out of screen. So, displaying a thousand of items is not a problem.
You can see this in most builtin apps from Apple, like Settings.
However we shouldn’t stop here. See these pages:
They are just rows of elements stacking together:
It is clear now that UITableView can be used to build any kinds of page in the app, not only table views. Another huge advantage of this is that the cells are reused automatically.
However, creating a table view is a repetitive and tiresome task. It uses the concept of data source, and thus the code for the presentational layer is separated into multiple functions (e.g., cellForRowAtIndexPath, heightForRowAtIndexPath, estimatedHeightForRowAtIndexPath). This makes the code hard to work with as it grows.
ViewElements simplifies the process of building UITableView and reusing UITableViewCell. It allows developers to declare arrays of rows such that the final appearance and the order of the rows, will directly mirror the code. Thus, all parts of the code for each row are close together, make it easier to work with.
It also provides API, called Component, to build a view by nesting UIStackView together. With a combination of UITableView and UIStackView. While table view deals with displaying and reusing cells in the vertical direction, stack view deals with UI creation in each cell.
ViewElements has data structures that wrap those complexities and provide APIs to construct a complete view. Once a view is setup, it can be reused anywhere, under the provided API. But the built-in elements provided can already do a lot!
Check this quick demo:
This proves to be great solution for static pages in the app. However, for a dynamic page, and those that interact with data such as form inputs, we need more.
Currently, I’m combining a reactive programming library called RxSwift with ViewElements, in order to enable data-driven UI.