Code Monkey home page Code Monkey logo

Comments (2)

jegnux avatar jegnux commented on August 12, 2024

RxGesture uses PermissiveGestureRecognizerDelegate by default in View+RxGesture.swift#L92. Is there any reason to use this by default?

This delegate is here for an easier use of anyGesture() operator allowing to attach multiple gestures at once. In that case they should be recognized simulteanously.

To prevent this, I have to create such like ExclusiveGestureRecognizerDelegate and pass it to configuration closure.

This is exactly what the configuration closure is for 👍

Provide such like defaultGestureRecognizerDelegate to give an opportunity to set default delegate.

The problem is that if you use another third 3rd library that also uses RxGesture, and if you change the default delegate for the whole RxGesture library, it can lead to bugs in the 3rd party library relying on the default delegate.

Maybe I can add a system to push/pop a delegate locally:

RxGesture.pushDefaultDelegate(ExclusiveGestureRecognizerDelegate.shared)
_ = myView.tapGesture().subscribe(onNext: { ... }) // Use ExclusiveGestureRecognizerDelegate
RxGesture.popDefaultDelegate()

But it's a really uncommon pattern for this use case so I don't think it's a great idea (and it's more verbose than the configuration solution).

The must you can do is to create free functions for configuration (you can even compose them with a + operator :

func + <I> (lhs: @escaping (I) -> Void, rhs: @escaping (I) -> Void) -> ((I) -> Void) {
    return  {
        lhs($0)
        rhs($0)
    }
}

func useExclusiveDelegate(_ gesture: UIGestureRecognizer) {
    gesture.delegate = ExclusiveGestureRecognizerDelegate.shared
}

func requireTableViewPanFail(_ gesture: UIGestureRecognizer) {
    gesture.require(toFail: tableView.panGestureRecognizer)
}

_ = myView.rx
    .tapGesture(configuration: useExclusiveDelegate + requireTableViewPanFail)
    .when(.recognized)
    .subscribe(onNext: { _ in
        print("did tap")
    })

@devxoul I let you close this issue if my answer is enough. Otherwise, feel free to suggest new solutions.

from rxgesture.

devxoul avatar devxoul commented on August 12, 2024

That makes sense. Thanks for your detailed explanation!

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.