Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/muukii/Presenter
Screen transition with safe and clean code.
https://github.com/muukii/Presenter
Last synced: 6 days ago
JSON representation
Screen transition with safe and clean code.
- Host: GitHub
- URL: https://github.com/muukii/Presenter
- Owner: muukii
- License: mit
- Created: 2016-04-26T15:28:44.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-25T08:43:29.000Z (about 8 years ago)
- Last Synced: 2024-11-27T18:48:30.378Z (15 days ago)
- Language: Swift
- Homepage:
- Size: 68.4 KB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Presenter - Screen transition with safe and clean code. (UI / Transition)
- awesome-ios-star - Presenter - Screen transition with safe and clean code. (UI / Transition)
README
# Presenter
[![CI Status](http://img.shields.io/travis/muukii/Presenter.svg?style=flat)](https://travis-ci.org/muukii/Presenter)
[![Version](https://img.shields.io/cocoapods/v/Presenter.svg?style=flat)](http://cocoapods.org/pods/Presenter)
[![License](https://img.shields.io/cocoapods/l/Presenter.svg?style=flat)](http://cocoapods.org/pods/Presenter)
[![Platform](https://img.shields.io/cocoapods/p/Presenter.svg?style=flat)](http://cocoapods.org/pods/Presenter)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)Screen transition with safe and clean code.
With Presenter, you can…
- Assure that the ViewController's requirements are met, such as a ViewModel to be injected.
- Constrain transition types (push or present modal or both)**This library is recommended to be used together with [Instantiatable](https://github.com/muukii/Instantiatable).**
## Usage
### Clean Screen Transition
```swift
MyViewController.Presenter(userID: "muukii").push(self.navigationController)
MyViewController.Presenter(userID: "muukii").present(self)
```#### Advanced
```swift
MyViewController.Presenter(userID: "muukii").push(self.navigationController) { (transaction: PushTransaction in// Pop
transaction.pop()// Get
transaction.viewController
}MyViewController.Presenter(userID: "muukii").present(self) { (transaction: ModalTransaction) in
// Pop
transaction.dismiss()// Get
transaction.viewController
}
```### Create Presenter
Push
```swift
extension MyViewController {final class Presenter: PushPresenter {
let userID: String
init(userID: String) {
self.userID = userID
}func createViewController() -> MyViewController {
let controller = MessagesViewController() // Init from Stroyboard or XIB
controller.userID = userID
return controller
}
// Optional:
public func willPush(viewController: MyViewController) {
}
public func didPush(viewController: MyViewController) {
}
}
}
```Present
```swift
extension MyViewController {final class Presenter: ModalPresenter {
let userID: String
init(userID: String) {
self.userID = userID
}func parentController(viewController: UIViewController) -> UIViewController? {
return UINavigationController(rootViewController: viewController)
}func createViewController() -> MyViewController {
let controller = MessagesViewController() // Init from Stroyboard or XIB
controller.userID = userID
return controller
}
// Optional
public func willPresent(viewController: MyViewController) {
}
public func didPresent(viewController: MyViewController) {
}
}
}
```Present or Push
```swift
extension MyViewController {final class Presenter: PushPresenter, ModalPresenter {
let userID: String
init(userID: String) {
self.userID = userID
}func parentController(viewController: UIViewController) -> UIViewController? {
// Call Present() only
return UINavigationController(rootViewController: viewController)
}func createViewController() -> MyViewController {
let controller = MessagesViewController() // Init from Stroyboard or XIB
controller.userID = userID
return controller
}
// Optional
public func willPresent(viewController: MyViewController) {
}
public func didPresent(viewController: MyViewController) {
}
public func willPush(viewController: MyViewController) {
}
public func didPush(viewController: MyViewController) {
}
}
}
```## Requirements
## Installation
Presenter is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod "Presenter"
```## Author
muukii, [email protected]
## License
Presenter is available under the MIT license. See the LICENSE file for more info.