Coder Social home page Coder Social logo

appunite / stefan Goto Github PK

View Code? Open in Web Editor NEW
47.0 21.0 1.0 3.67 MB

A guy that helps you manage collections and placeholders in easy way.

License: MIT License

Swift 97.99% Objective-C 0.83% Ruby 1.18%
swift states uitableview uicollectionview placeholder error

stefan's Introduction

Carthage compatible Cocoapods Platform License

Stefan logo

Why?

As mobile developers we all have to handle displaying collections of data. But is it always as simple as it sounds?

Stefan spaghetti

Looks like spaghetti? It is a common situation that application displays data / placeholders (which may be different depending for example on loading state) and some of us end up with defining states and tangling everything together.

Stefan overview

Stefan is a framework that helps you to manage states in your collection views. Basically it is a middleman between data source and the view itself. Of course it supports UITableView and UICollectionView out of box, but it is up to you to decide what is your ReloadableView and what is PlaceholderView. It contains most commonly used states that might occur when loading data collection.

Basic setup

  • Define Stefan object, the best solution is to define one Stefan per one ReloadableView.
  • Connect Stefan's reloadableView and placeholderPresenter (which both might be nil).

Remember: class that implements LoadableStatePlaceholderPresentable must have a weak reference to a placeholderView.

  • Call stefan.load(newState: ...)

Example of setup:

private func setupStefan() {
	viewModel.stefan.reloadableView = self.tableView
	viewModel.stefan.placeholderPresenter = self
	viewModel.stefan.load(newState: .noContent) // initial state
}

For reading current items just call

try stefan.state.items()

Few words about placeholder

  • We have tried to make it as flexible as possible so you can provide a custom placeholder view which should conform to LoadableStatePlaceholderView and also implement ItemsLoadableStateBindable protocol. To display custom placeholder view just implement your own version of function customPlaceholderView that is handled by Stefan's placeholderPresenter.

Example for customization:

public func customPlaceholderView() -> LoadableStatePlaceholderView {
	let view = LoadingPlaceholderView.instanceFromNib()
    view.dataSource = self.viewModel
    return view
}
  • There is also a default placeholder view built from title, subtitle and activity indicator which might also be useful for you. Feel free to see how it works in the example project.

Closures

To make Stefan fully generic we provided delegate by common closures pattern. Following delegate closures are available:

public var shouldReload: ((ReloadableView!) -> Bool)
    
public var didChangeState: ((ItemsLoadableState<ItemType>) -> Void)
    
public var shouldDisplayPlaceholder: ((ItemsLoadableState<ItemType>) -> Bool)

Differing

Stefan provides default implementation of differring function which result should be ItemReloadingResult. This result tells Stefan what should be reloaded (or maybe there is nothing to do for him). You can provide your own implementation by defining

stefan.statesDiffer = ...

Please remember that this is a weak object so you have to handle retaining it.

Stefan has a Differ dependency which is needed for performing fast operations on collections while comparing. When initializing Stefan you are able to provide reloading type which might be animated or basic. By default animations are disabled, but when you'll enable it Stefan will handle collection animation automatically by himself.

RxStefan

We've added some RxSwift extensions for Stefan please follow this repo.

Carthage

Add the following entry in your Cartfile:

github "appunite/Stefan"

Then run carthage update.

Cocoapods

Add the following entry in your Podfile

pod 'Stefan'

Then run pod install.

Known issues

โ€ข Nothing yet

Contribution

Project is created and maintened by Piotr Bernad and Szymon Mrozek.

We could use your help with reporting or fixing bugs. We would also like to hear from you about feature suggestions. If you have an idea how to make Stefan better you are welcome to send us a Pull Request.

License

Stefan is released under an MIT license. See License.md for more information.

stefan's People

Contributors

damiankolasinski avatar emu-pl avatar kubson98 avatar lukkas avatar newdiscoblack avatar piotrbernad avatar szymonmrozek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.