All Projects â†’ babylonhealth â†’ Bento

babylonhealth / Bento

Licence: mit
Swift library for building component-based interfaces on top of UITableView and UICollectionView 🍱

Programming Languages

swift
15916 projects
declarative
70 projects

Projects that are alternatives of or similar to Bento

Datasource
Simplifies the setup of UITableView data sources using type-safe descriptors for cells and sections. Animated diffing built-in.
Stars: ✭ 72 (-80.59%)
Mutual labels:  diffing, uitableview
Jsondiffpatch
Diff & patch JavaScript objects
Stars: ✭ 3,951 (+964.96%)
Mutual labels:  diff, diffing
Diffabledatasources
💾 A library for backporting UITableView/UICollectionViewDiffableDataSource.
Stars: ✭ 601 (+61.99%)
Mutual labels:  diff, diffing
Carbon
🚴 A declarative library for building component-based user interfaces in UITableView and UICollectionView.
Stars: ✭ 1,034 (+178.71%)
Mutual labels:  diffing, uitableview
Ace Diff
A diff/merging wrapper for Ace Editor built on google-diff-match-patch
Stars: ✭ 257 (-30.73%)
Mutual labels:  diff, diffing
Sirix
SirixDB is a temporal, evolutionary database system, which uses an accumulate only approach. It keeps the full history of each resource. Every commit stores a space-efficient snapshot through structural sharing. It is log-structured and never overwrites data. SirixDB uses a novel page-level versioning approach called sliding snapshot.
Stars: ✭ 638 (+71.97%)
Mutual labels:  diff, diffing
Changeset
Minimal edits from one collection to another
Stars: ✭ 807 (+117.52%)
Mutual labels:  diff, uitableview
Nbdime
Tools for diffing and merging of Jupyter notebooks.
Stars: ✭ 2,135 (+475.47%)
Mutual labels:  diff, diffing
go-delta
go-delta - A Go package and utility to generate and apply binary delta updates.
Stars: ✭ 25 (-93.26%)
Mutual labels:  diff, diffing
Awesome Website Change Monitoring
A curated list of awesome tools for website diffing and change monitoring.
Stars: ✭ 224 (-39.62%)
Mutual labels:  diff, diffing
Multidiff
Binary data diffing for multiple objects or streams of data
Stars: ✭ 282 (-23.99%)
Mutual labels:  diff, diffing
Differencekit
đŸ’ģ A fast and flexible O(n) difference algorithm framework for Swift collection.
Stars: ✭ 2,986 (+704.85%)
Mutual labels:  diff, diffing
Pgdiff
Compares the PostgreSQL schema between two databases and generates SQL statements that can be run manually against the second database to make their schemas match.
Stars: ✭ 333 (-10.24%)
Mutual labels:  diff, diffing
Linediff.vim
A vim plugin to perform diffs on blocks of code
Stars: ✭ 331 (-10.78%)
Mutual labels:  diff
Functionaltabledata
Declarative UITableViewDataSource implementation
Stars: ✭ 347 (-6.47%)
Mutual labels:  uitableview
Uistackviewplayground
Playground to play with UIStackViews.
Stars: ✭ 319 (-14.02%)
Mutual labels:  uitableview
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 (-17.79%)
Mutual labels:  uitableview
Uitableviewdynamiclayoutcacheheight
🖖éĢ˜æ€§čƒŊįš„č‡ĒåŠ¨čŽĄįŽ—采į”¨ Autolayout å¸ƒåą€įš„ UITableViewCell 和 UITableViewHeaderFooterView įš„éĢ˜åēĻīŧŒå†…部č‡Ē动įŽĄį†éĢ˜åēĻįŧ“存。
Stars: ✭ 360 (-2.96%)
Mutual labels:  uitableview
Gsync
gSync is an rsync based library for sending delta updates of files to a remote server.
Stars: ✭ 344 (-7.28%)
Mutual labels:  diff
Diff2html Cli
Pretty diff to html javascript cli (diff2html-cli)
Stars: ✭ 287 (-22.64%)
Mutual labels:  diff

Bento 🍱 åŧåŊ“

is a single-portion take-out or home-packed meal common in Japanese cuisine. A traditional bento holds rice or noodles, fish or meat, with pickled and cooked vegetables, in a box.

Bento is a Swift library for building component-based interfaces on top of UITableView.

  • Declarative: provides a painless approach for building UITableView interfaces
  • Diffing: reloads your UI with beautiful animations when your data changes
  • Component-based: Design reusable components and share your custom UI across multiple screens of your app

In our experience it makes UI-related code easier to build and maintain. Our aim is to make the UI a function of state (i.e: UI = f(state)), which makes Bento a perfect fit for Reactive Programming.

Content 📋

Installation 💾

  • Cocoapods
target 'MyApp' do
    pod 'Bento'
end
  • Carthage
github "Babylonpartners/Bento"

What's it like? 🧐

When building a Box, all you need to care about are Sectionss and Nodes.

let box = Box<SectionId, RowId>.empty
            |-+ Section(id: SectionId.user,header: EmptySpaceComponent(height: 24, color: .clear))
            |---+ Node(id: RowID.user, component: IconTitleDetailsComponent(icon: image, title: patient.name))
            |-+ Section(id: SectionId.consultantDate, header: EmptySpaceComponent(height: 24, color: .clear))
            |---+ Node(id: RowID.loading, component: LoadingIndicatorComponent(isLoading: true))

        tableView.render(box)

How does it work? 🤔

Setup

Bento automatically performs the data source and delegate setup upon the very first time UITableView or UICollectionView is asked to render a Bento Box.

In other words, for Bento to work, it cannot be overridden with your own data source and delegate. If you wish to respond to delegate messages which Bento does not support as a feature, you may consider supplying a custom adapter using prepareForBoxRendering(_:).

Collection View Adapter Base Class Required Protocol Conformances
UITableView TableViewAdapterBase UITableViewDataSource & UITableViewDelegate
UICollectionView CollectionViewAdapterBase UITableViewDataSource & UITableViewDelegate

Box đŸ“Ļ

Box is a fundamental component of the library, essentially a virtual representation of the UITableView content. It has two generic parameters - SectionId and RowId - which are unique identifiers for Section<SectionId, RowId> and Node<RowId>, used by the diffing engine to perform animated changes of the UITableView content. Box is just a container for an array of sections.

Sections and Nodes 🏗

Sections and Nodes are building blocks of a Box:

  • Section is an abstraction of UITableView's section which defines whether a header or footer should be shown.
  • Node is an abstraction of UITableView's row which defines how the data is rendered.
struct Section<SectionId: Hashable, RowId: Hashable> {
    let id: SectionId
    let header: AnyRenderable?
    let footer: AnyRenderable?
    let rows: [Node<RowId>]
}

public struct Node<Identifier: Hashable> {
    let id: Identifier
    let component: AnyRenderable
}

Identity đŸŽĢ

Identity, one of the key concepts, is used by the diffing algorithm to perform changes.

For general business concerns, full inequality of two instances does not necessarily mean inequality in terms of identity — it just means the data being held has changed if the identity of both instances is the same.

(More info here.)

SectionID and ItemID define the identity of sections and their items, respectively.

Renderable đŸ–ŧ

Renderable is similar to React's Components. It's an abstraction of the real UITableViewCell that is going to be displayed. The idea is to make it possible to create small independent components that can be reused across many parts of your app.

public protocol Renderable: class {
    associatedtype View: UIView

    func render(in view: View)
}

class IconTextComponent: Renderable {
    private let title: String
    private let image: UIImage

    init(image: UIImage,
         title: String) {
        self.image = image
        self.title = title
    }

    func render(in view: IconTextCell) {
        view.titleLabel.text = title
        view.iconView.image = image
    }
}

Bento's arithmetics 💡

There are several custom operators that provide syntax sugar to make it easier to build Bentos:

precedencegroup ComposingPrecedence {
    associativity: left
    higherThan: NodeConcatenationPrecedence
}

precedencegroup NodeConcatenationPrecedence {
    associativity: left
    higherThan: SectionConcatenationPrecedence
}

precedencegroup SectionConcatenationPrecedence {
    associativity: left
    higherThan: AdditionPrecedence
}

infix operator |-+: SectionConcatenationPrecedence
infix operator |-?: SectionConcatenationPrecedence
infix operator |---+: NodeConcatenationPrecedence
infix operator |---?: NodeConcatenationPrecedence

let bento = Box.empty
	|-+ Section(id: SectionID.first) // 2
	|---+ Node(id: RowID.someId, Component()) // 1

As you might have noticed:

  • |-+ has SectionConcatenationPrecedence;
  • |---+ has NodeConcatenationPrecedence

NodeConcatenationPrecedence is higher than |-+ / SectionConcatenationPrecedence, meaning Nodes will be computed first.

The order of the expression above is:

  1. Section() |---+ Node() => Section
  2. Box() |-+ Section() => Box

Conditional operators ❓

In addition to the |-+ and |---+ concatenation operators, Bento has conditional concatenation operators:

  • |-? for Section
  • |---? for Node

They are used to provide a Section or Node in a closure for the Bool and Optional happy path, via the .iff and .some functions.

Here are some examples:

let box = Box.empty
    |-? .iff(aBoolCondition) {
        Section()  // <-- Section only added if `boolCondition` is `true`
    }
let box = Box.empty
    |-? anOptional.map { unwrappedOptional in  // <-- the value of anOptional unwrapped
        Section()  // <-- Section only added if `anOptional` is not `nil`
    }

|---? works in exactly the same way for Node.

Components & StyleSheets 🎨

Bento includes set of generic components like ``Description,TextInput`, `EmptySpace` etc. Bento uses StyleSheets to style components.

StyleSheets are a way to define how particular view should be rendered. Component's job is to provide what should be displayed while StyleSheets provide a style how it's done. Fonts, colors, alignment should go into StyleSheet.

StyleSheets support KeyPaths for easier composition.

let styleSheet = LabelStyleSheet()
    .compose(\.numberOfLines, 3)
    .compose(\.font, UIFont.preferredFont(forTextStyle: .body))

StyleSheets can be used with Bento's components. All you need to do is to use correct stylesheet:

return .empty
  |-+ Section(id: .first)
  |---+ Node(
         id: .componentId,
         component: Component.Description(
             text: "Text",
             styleSheet: Component.Description.StyleSheet()
                 .compose(\.text.font, UIFont.preferredFont(forTextStyle: .body))
         )
   )

Example 😎

Additional documentation 📙

Development Installation 🛠

If you want to clone the repo for contributing or for running the example app you will need to install its dependencies which are stored as git submodules:

git submodule update --init --recursive

Or, if you have Carthage installed, you can use it to do the same thing:

carthage checkout

State of the project 🤷‍♂ī¸

Feature Status
UITableView ✅
UICollectionView ✅
Carthage Support ✅
Free functions as alternative to the operators ❌

Development Resources

  • Bento Component Contract

    Define requirements that must be complied by the components from Bento, and best practices for developing a custom component.

Contributing ✍ī¸

Contributions are very welcome and highly appreciated! ❤ī¸ Here's how to do it:

  • If you have any questions feel free to create an issue with a question label;
  • If you have a feature request you can create an issue with a Feature request label;
  • If you found a bug feel free to create an issue with a bug label or open a PR with a fix.

Image attributions

Coffee Pomegranate fruit Cherries Strawberries

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