Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gesture recognizer conflicts with UITableViewCell gesture recognizers for cell actions #71

Closed
bryan1anderson opened this issue Jul 14, 2020 · 7 comments

Comments

@bryan1anderson
Copy link

Describe the bug
Gesture recognizer conflicts with UITableViewCell gesture recognizers for cell actions
Expected behavior
I should reliably be able to swipe on a cell when it is placed in the overlaycontainer.

I pan gesture property is private so I don't have access to require it to fail to the cell swipe gestures.

How do I get swipeable tableviewcells to work using OverlayContainer?

@hberenger
Copy link

I had exactly the same issue as yours: it was not possible to open the the Swipe Actions of a tableview embedded in an OverlayContainer, below the overlay view controller.

It seems that, as you mention, there is a conflict between the tableview gesture recognizers and the OverlayTranslationGestureRecognizer defined by the OverlayContainer library (subclass of UIPanGestureRecognizer).
It happens that :

  • this class is internal to the library
  • the library sets no delegate into OverlayTranslationGestureRecognizer

So, I came up with the following workaround, consisting in implementing gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:) for the internal pan recognizer :

// Defined on client application side:
class OverlayContainerTweak: NSObject, UIGestureRecognizerDelegate {

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,
                           shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
    }
}

then:

let overlayTranslationGestureRecognizer = overlayContainerViewController.view.gestureRecognizers?.first {
    String(describing: type(of: $0)).contains("OverlayTranslationGestureRecognizer")
}

(where overlayContainerViewController is the OverlayContainerViewController), and finally:

let overlayContainerTweak = OverlayContainerTweak()
overlayTranslationGestureRecognizer?.delegate = overlayContainerTweak

Clearly this is pretty hacky, but it did the job.
Not sure whether returning always true is meaningful from the library point of view, so I did not submit any PR to push this fix on the library side.

@gaetanzanella : if you confirm that the OverlayTranslationGestureRecognizer should always be recognized simultaneously with other gesture recognizers, I can submit a fix similar to the workaround above. Let us know what you think.

@bryan1anderson
Copy link
Author

@hberenger So this allowed you to use the tableview actions?

@gaetanzanella I'm always afraid of claiming delegate ownership to gestures as that can cause problems if it relies on it somehow. Do you have any recommendations?

@hberenger
Copy link

@bryan1anderson : yes, I confirm this workaround repaired the tableview swipe actions

@gaetanzanella
Copy link
Contributor

gaetanzanella commented Aug 12, 2020

Hi @bryan1anderson @hberenger, thanks for raising the issue. A fix is available. I will release it soon.

If you return false in the shouldStartDraggingOverlay callback, the container pan gesture will be disabled. So you can do something like:

func overlayContainerViewController(_ containerViewController: OverlayContainerViewController,
                                    shouldStartDraggingOverlay overlayViewController: UIViewController,
                                    at point: CGPoint,
                                    in coordinateSpace: UICoordinateSpace) -> Bool {
    let position = overlayViewController.view.convert(point, from: coordinateSpace)
    return overlayViewController.view.bounds.contains(position)
}

@bryan1anderson
Copy link
Author

bryan1anderson commented Sep 14, 2020

But I don't want it to be disabled. There is effectually a point on every single point on the view because its just a tableview. I need them to behave together. I don't care about horizontal pans on the container view, and I don't care about vertical pans on the tableview. It seems what you're saying the fix does is just not allow panning if the touch is on a certain point. All my points need to be able to handle both of these @gaetanzanella

@gaetanzanella
Copy link
Contributor

gaetanzanella commented Sep 14, 2020

I'm not sure I understand. Could you provide a sample code?

@bryan1anderson
Copy link
Author

@gaetanzanella Sorry to be unclear. Your solution doesn't support recognizing multiple gesture recognizers. Your solution seems to support only supporting panGesture1 or panGesture2. I need it to recognize both of them simultaneously

For example:
If my entire view needs to be swiped on from left to right. There is no point at which I don't want the view to be swiped on. Therefore I either need to disable OverlayContainer pan gesture, or I need to disable my views pan gesture. I need simultaneous gestures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants