Git Product home page Git Product logo

rxalertcontroller's Introduction

RxAlertController

CI Status Version License Platform Carthage compatible

I'm tired of copying same file into the project every time I need to display a message in the application, so I decided to create a pod.

Changelog

  • 3.0 Convert return values from Observables to Single and Maybe
  • 2.1 Add Carthage support
  • 2.0 Move to Swift 4
  • 1.1 Add methods to display already instantiated alert controller

Introduction

RxAlertController allows you to display messages on the screen, using the sequence of RxSwift observable streams instead of traditional closures. Thus, the dialog box can be chained with other observables, for example, as follows:

api.someNetworkFunctionThatMayFail()
.retryWhen({ (error) -> Observable<Int> in
    return error.flatMap({ error -> Maybe<Int> in
        return UIAlertController.rx.show(in: self, title: "Error", message: error.localizedDescription, buttonTitles: ["Retry", "Abort"])
            .filter({value in value == 0})
    })
})
.subscribe(onNext, onError, etc)

And using RxMediaPicker from RxSwiftCommunity, you can choose pictures like this:

UIAlertController.rx.show(in: self,
                       title: "Change avatar", 
                     message: "Select source", 
                     buttons: [.default("Take a picture"), .default("Select from gallery"), .cancel("Cancel")],
              preferredStyle: .actionSheet)
    .flatMap({ [unowned self] choice in
        if choice == 0 {
            return self.picker.takePhoto()
        } else {
            return self.picker.selectImage(source: .photoLibrary)
        }
    })
    .map { (original, edited) -> UIImage in
        return original
    }
    .bind(to: imageView.rx.image)
    .disposed(by: disposeBag)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

RxSwift is required, obviously.

Installation

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

pod "RxAlertController"

Also you can use Carthage. To install it, add line to Cartfile:

github "evgeny-sureev/RxAlertController"

Author

Evgeny Sureev, [email protected]

License

RxAlertController is available under the Apache License 2.0. See the LICENSE file for more info.

rxalertcontroller's People

Contributors

evgeny-sureev avatar

Watchers

James Cloos avatar The Pham ( Lucio ) 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.