Coder Social home page Coder Social logo

rxgesture's Introduction

RxGesture

Version License Platform

Usage

To run the example project, clone the repo, in the Example folder open RxGesture.xcworkspace.

You might need to run pod install from the Example directory first.


RxGesture allows you to easily turn any view into a tappable or swipeable control like so:

myView.rx_gesture(.Tap).subscribeNext {_ in
   //react to taps
}.addDisposableTo(stepBag)

You can also react to more than one type of gesture. For example to dismiss a photo preview you might want to do that when the user taps it, or swipes up or down:

myView.rx_gesture(.Tap, .SwipeUp, .SwipeDown).subscribeNext {_ in
   //dismiss presented photo
}.addDisposableTo(stepBag)

rx_gesture is defined as Observable<RxGestureTypeOption> so what it emits is the concrete type of the gesture that was triggered (handy if you are observing more than one type)

On iOS RXGesture supports:

  • .Tap
  • .SwipeLeft, SwipeRight, SwipeUp, SwipeDown
  • .LongPress
  • .Pan(.Began), .Pan(.Changed), .Pan(.Ended), .Pan(.Any)
  • .Rotate(.Began), .Rotate(.Changed), .Rotate(.Ended), .Rotate(.Any)

On OSX RXGesture supports:

  • .Click
  • .RightClick
  • .Pan(.Began), .Pan(.Changed), .Pan(.Ended), .Pan(.Any) (if used in one call to rx_gesture until NSGestureRecognizer implements rx_event)
  • .Rotate(.Began), .Rotate(.Changed), .Rotate(.Ended), .Rotate(.Any) (if used in one call to rx_gesture until NSGestureRecognizer implements rx_event)

If you are writing multi-platform code you can eventually write:

myView.rx_gesture(.Tap, .Click).subscribeNext {...}

to observe for the concrete gesture on each platform.

Continuous gestures

Some recognizers fire a single event per gesture and don't provide any values. For example .Tap just lets you know a view has been tapped - that's all.

Other recognizers provide details about the gesture (that also might be ongoing). For example the pan gesture will continuously provide you with the offset from the initial point where the gesture started:

myView.rx_gesture(.Pan(.Changed)).subscribeNext {[weak self] gesture in
    switch gesture {
    case .Pan(let data):
	    print("offset: \(data.translation)")
    default: break
    }
}.addDisposableTo(bag)

Pattern match the associated value of type PanConfig to get the translation, velocity, and a ref to the recognizer itself.

The demo app includes examples for all recognizers.

Requirements

This library depends on both RxSwift and RxCocoa.

Installation

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

pod "RxGesture"

TODO

  • defo add tests
  • make pr to rxcocoa to add native support for rx_event to NSGestureRecognizer and remove the implementation from this repo

Thanks

Everyone in the RxSwift Slack channel ๐Ÿ’ฏ

License

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

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.