Latest 0.6
Homepage https://github.com/lm2343635/RxAlertViewable
License MIT
Platforms ios 9.0
Dependencies RxSwift, RxCocoa
Authors

RxAlertViewable Build Status Version License Platform

RxAlertViewable is created for developing the MVVM app with RxSwift.
It supports to show a simple alert from the view model class using the signal Observable<RxAlert>.

Installation

RxAlertViewable is available through CocoaPods.
To install it, simply add the following line to your Podfile:

pod 'RxAlertViewable'

Run Demo

To run the demo application, install the dependencies with CocoaPods and open the project by .xcworkspace.

pod install
open RxAlertViewable.xcworkspace

Documentaion

To use RxAlertViewable, confirm the RxAlertViewable protocol in your view controller class at first.

class ViewController: UIViewController, RxAlertViewable {}

Prepare a singal Observable<RxAlert> in your view model class.

let clickTimes = BehaviorRelay<Int>(value: 0)

var tip: Observable<RxAlert> {
    return clickTimes.map {
        RxAlert.tip(message: "Clicked ($0) times.")
    }
}

RxAlertViewable supports the following alert types.

  • tip(_ message:, onConfirm:)
  • customTip(title:, message: String, onConfirm:)
  • warning(_ message:, onConfirm:)
  • error(_ message:, onConfirm:)
  • confirm(_ message:, onConfirm:, onDeny:)
  • customConfirm(title: String, message:, confirmTitle:, denyTitle:, onConfirm:, onDeny:)

Bind it in the view controller class.

viewModel.tip.bind(to: rx.alert).disposed(by: disposeBag)

When we invoke the clickTimes.accept(times) method in the view model class, an alert controller will be shown in the view controller.

Demo

Customization

Customize your own strings and tint color using the following code.

RxAlert.config = RxAlertConfig(tip: "My Tip",
                               confirm: "My Confirm",
                               warning: "My Warning",
                               error: "My Error",
                               yes: "My Yes",
                               no: "My No",
                               ok: "My OK",
                               tintColor: .blue)

Global Alert

RxAlertViewable supports to show a global alert view in a new UIWindow instance above the current window, by binding to the rx.globalAlert singal from any class.

viewModel.globalTip.bind(to: rx.globalAlert).disposed(by: disposeBag)

Author

lm2343635, [email protected]

License

RxAlertViewable is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "RxAlertViewable",
    "version": "0.6",
    "summary": "A simple alert library with RxSwift supported.",
    "description": "RxAlertViewable is created for developing the MVVM app with RxSwift. It supports to show a simple alert from the view model class using the signal Observable.",
    "homepage": "https://github.com/lm2343635/RxAlertViewable",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "lm2343635": "[email protected]"
    },
    "source": {
        "git": "https://github.com/lm2343635/RxAlertViewable.git",
        "tag": "0.6"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "RxAlertViewable/Classes/**/*",
    "dependencies": {
        "RxSwift": [
            "~> 5"
        ],
        "RxCocoa": [
            "~> 5"
        ]
    }
}

Pin It on Pinterest

Share This