Skip to content

Transition breaks when quickly gesturing up with a table view #4

@scottpchow23

Description

@scottpchow23

I copied most of your code from the branch that does drag to dismiss with a table view, and found that the transition breaks when you pull the modal view controller down slightly, then push quickly upwards.

`@IBAction func handleGesture(sender: UIPanGestureRecognizer) {
// let shouldDismiss = DragToDismissHelper.sharedInstance.dragToDismiss(sender, searchViewController: self, tableView: googleSearchTableView, view: view)
print("state: (sender.state.rawValue)")
let percentThreshold:CGFloat = 0.3

    // convert y-position to downward pull progress (percentage)
    let translation = sender.translationInView(view)
    // using the helper method
    let progress = progressAlongAxis(translation.y, axisLength: view.bounds.height)

    guard let interactor = interactor,
        let originView = sender.view else { return }

    // Only let the table view dismiss the modal only if we're at the top.
    // If the user is in the middle of the table, let him scroll.
    switch originView {
    case view:
        break
    case googleSearchTableView:
        if googleSearchTableView.contentOffset.y > 0 {
            print("scroll content offset: \(googleSearchTableView.contentOffset.y)")
            return
        }
    default:
        print("about to break")
        break
    }

    print("entering switch")

    switch sender.state {
    case .Began:
        googleSearchTableView.userInteractionEnabled = false
        interactor.hasStarted = true
        dismissViewControllerAnimated(true, completion: nil)
    case .Changed:
        interactor.shouldFinish = progress > percentThreshold
        interactor.updateInteractiveTransition(progress)
    case .Cancelled:
        interactor.hasStarted = false
        interactor.cancelInteractiveTransition()
    case .Ended:

        interactor.hasStarted = false
        interactor.shouldFinish
            ? interactor.finishInteractiveTransition()
            : interactor.cancelInteractiveTransition()
    default:
        break
    }

`
Ignoring the first line of code, which was my attempt to refactor the handleGesture code into a helper function, everything else is the same (googleSearchTableView is equivalent to tableView).

What I believe is happening is that when you add the panGestureRecognizer() to the tableView, it still treats the gesture like a scroll. This means that when the upward gesture occurs, it is actually scrolling the tableView which means that content offset changes, preventing the code from setting the state of the Modal View's interactor appropriately.

I personally fixed the bug by adding a boolean inMiddleOfTransitioning that is initialized as false to the Modal View Controller. Then, I wrap the contentOffset check in an if statement with the parameter !inMiddleOfTransitioning; this is to say that if you're in the middle of the transition to DISREGARD the content offset, allowing for the Interactor state to be set. Then I simply set inMiddleOfTransitioning to true in the .Began case of the sender switch statement.

Sorry if this was a bit convoluted but this has been driving me mad for weeks.

Cheers!

scottpchow23

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions