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

#60 - Allows horizontal swipe on the table cells #61

Closed
wants to merge 1 commit into from

Conversation

AndreaMiotto
Copy link

This solve issue #60

@MarioIannotta MarioIannotta self-requested a review June 3, 2019 13:57
@MarioIannotta
Copy link
Owner

Hi Andrea, I've tested you branch and there's one regression when the user try to drag the panel from the top view (the one where the search bar is placed).
Basically the panel scrolls a little bit and then stops, I've attached a video.

pullup#60.mov.zip

@zmh
Copy link

zmh commented Jun 21, 2019

@AndreaMiotto any thoughts on how to fix this? I have the same issue where swiping to delete on a tableview doesn't work, but the fix also prevents the pullupcontroller from swiping up and down. thanks for the help!

@shurwit
Copy link

shurwit commented Jul 17, 2019

The source of the issue highlighted in the video that @MarioIannotta posted appears to be these lines suggested in the pull request

@objc private func handlePanGestureRecognizer(_ gestureRecognizer: UIPanGestureRecognizer) {
		guard
			isPortrait,
			let topConstraint = topConstraint
			else { return }

		let xVelocity = gestureRecognizer.velocity(in: self.view).x
		let xTranslation = gestureRecognizer.translation(in: view).x
		if abs(xVelocity) > 0 || abs(xTranslation) > 0 { return }

		...
	}

As @AndreaMiotto noted in the initial issue thread, these lines are added in order to prevent the PullUpController from moving vertically while you are swiping horizontally on the table cell. However, this results in the motion of the PullUpController being interrupted every time the swipe gesture contains even the slightest horizontal motion.

Our solution was to simply remove this entire added section. This means that the PullUpController can move vertically while attempting to swipe the table cells horizontally, but the motion is smooth and the horizontal swipes work fine. If you absolutely need to prevent the simultaneous vertical motion, a more complex variation of the above code which keeps track of the initial direction of the gesture like the following should do the trick.

open class PullUpController: UIViewController {
    private var verticalSwipe = true

    ...

    @objc private func handlePanGestureRecognizer(_ gestureRecognizer: UIPanGestureRecognizer) {
        guard
            isPortrait,
            let topConstraint = topConstraint
            else { return }
        
        let xVelocity = gestureRecognizer.velocity(in: self.view).x
        let yVelocity = gestureRecognizer.velocity(in: self.view).y
        let yTranslation = gestureRecognizer.translation(in: view).y
        
        switch gestureRecognizer.state {
        case .began:
            verticalSwipe = abs(xVelocity) <= abs(yVelocity)
            
        case .changed:
            if verticalSwipe {
                setTopOffset(topConstraint.constant + yTranslation, allowBounce: true)
                gestureRecognizer.setTranslation(.zero, in: view)
            }
            
        case .ended:
            if verticalSwipe {
                goToNearestStickyPoint(verticalVelocity: gestureRecognizer.velocity(in: view).y)
            }

        default:
            break
        }
    }

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

Successfully merging this pull request may close these issues.

4 participants