Code Monkey home page Code Monkey logo

Comments (4)

jegnux avatar jegnux commented on August 12, 2024 1

Hum it would be possible, but as this operator can take any gesture recognizer, I don't feel comfortable by overriding it's delegate. I could check if there's already a delegate and set it to RxGestureRecognizerDelegate only if there isn't already one, but I don't really like this.
What you could do is to use it by yourself:

let gesture = SpecializedGestureRecognizer()
let delegate = RxGestureRecognizerDelegate()
gesture.delegate= delegate
view.rx.gesture(gesture).when(.recognized).subscribe(onNext: { g in
...
})

But you'll have to maintain a strong reference to it, otherwise it will be dealloc immediately because gesture.delegate is a weak reference.

from rxgesture.

jegnux avatar jegnux commented on August 12, 2024

@JohnEstropia I don't understand...
RxGesture supports all gestures defined by UIKit.
Also, the API is extensible so if in your projects, you want to support your own gesture recognizer, it's possible.

You can do:

let gesture = SpecializedGestureRecognizer()
view.rx.gesture(gesture).when(.recognized).subscribe(onNext: { g in
...
})

You can also implement the same shortcuts as ones provided by RxGesture with native recognizer. You can inspire yourself with this implementation: https://github.com/RxSwiftCommunity/RxGesture/blob/master/Pod/Classes/iOS/UITapGestureRecognizer%2BRxGesture.swift

from rxgesture.

JohnEstropia avatar JohnEstropia commented on August 12, 2024

Sorry if I wasn't clear. First, thanks for mentioning the gesture(...) factory method that accepts a UIGestureRecognizer instance directly, I am now using that for my implementation.

I guess when I first asked the question I was looking for a factory method that lets me configure the RxGestureRecognizerDelegate without having to create my own concrete GestureRecognizerFactory. Now I found the gesture(_:) method, my suggestion now is wouldn't it be convenient to have an overload method gesture(_:configuration:) where we can configure the RxGestureRecognizerDelegate policies?

from rxgesture.

jegnux avatar jegnux commented on August 12, 2024

@JohnEstropia Hey,

I think this should be doable now with RxGesture 2.x:

class MyCustomGestureRecognizer : UIGestureRecognizer {
    // ...
}

public typealias CustomGestureConfiguration = Configuration<MyCustomGestureRecognizer>
public typealias CustomGestureControlEvent = ControlEvent<MyCustomGestureRecognizer>
public typealias CustomGestureObservable = Observable<MyCustomGestureRecognizer>

extension Factory where Gesture == GestureRecognizer {
    public static func custom(configuration: CustomGestureConfiguration? = nil) -> AnyFactory {
        return Factory(configuration: configuration).abstracted()
    }
}

public extension Reactive where Base: View {
    public func customGesture(configuration: CustomGestureConfiguration? = nil) -> TapControlEvent {
        return gesture(Factory(configuration: configuration))
    }
}

from rxgesture.

Related Issues (20)

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.