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

How do I prevent my view controller from loading twice when I use the didDragCard function? #68

Open
tracknemo opened this issue Feb 27, 2020 · 5 comments
Labels

Comments

@tracknemo
Copy link

tracknemo commented Feb 27, 2020

New Issue Checklist

Question

Hi, I am overriding the didDragCard method and I essentially want a custom view controller I created to display upon dragging the card to the left. The issue arises after swiping the card, where the view controller is being pushed twice rather than only once. Here is my code:
`func didDragCard(card: CardCell, index: Int, swipeDirection: SwipeDirection) {

    let info = myArr[index]
    switch swipeDirection{
    case SwipeDirection.Left:
        let myVC = AccountOverviewVC(songType: info.songInfo, userId: info.uid)
        self.navigationController?.pushViewController(myVC, animated: false)
    default:
        print("do nothing because be we didn't drag left")
    }
}`

As mentioned, the function works although the view controller is pushed onto my view twice. I noticed that when I lightly drag the card (barely even dragging it) the expected behavior occurs (the view is only pushed once). But if I do a long drag in the left direction, the view is pushed multiple times.

@JoniVR
Copy link
Owner

JoniVR commented Feb 27, 2020

Hi,

This is intended behaviour. The didDragCard method is called while you're dragging a card, so it's supposed to be called repeatedly.

Depending on what you want to achieve exactly, you could either use the willSwipeCardAway or didSwipeCardAway delegate method or simply disable side swiping after the first call of didDragCard (cardSwiper.isSideSwipingEnabled = false).

I could perhaps implement something like a didChangeSwipeDirection delegate method but that would be called instantly once you start dragging, so it'd achieve the exact same result you'd get simply using the didDragCard method I described above.

My guess would be your best bet is to use either the willSwipeCardAway or didSwipeCardAway method.

If I'm overlooking something here, let me know what it is you want to achieve (aka when exactly you want to receive a dragging notification or what you're missing).

@tracknemo
Copy link
Author

Hi,

This is intended behaviour. The didDragCard method is called while you're dragging a card, so it's supposed to be called repeatedly.

Depending on what you want to achieve exactly, you could either use the willSwipeCardAway or didSwipeCardAway delegate method or simply disable side swiping after the first call of didDragCard (cardSwiper.isSideSwipingEnabled = false).

I could perhaps implement something like a didChangeSwipeDirection delegate method but that would be called instantly once you start dragging, so it'd achieve the exact same result you'd get simply using the didDragCard method I described above.

My guess would be your best bet is to use either the willSwipeCardAway or didSwipeCardAway method.

If I'm overlooking something here, let me know what it is you want to achieve (aka when exactly you want to receive a dragging notification or what you're missing).

I agree that using the ** willSwipeCardAway** or didSwipeCardAway functions will ensure that the card is only being dragged once, although the issue is that I still want the card to be available after swiping left. This way, once the user is done viewing the new view controller that swiping a card produces, he/she has the ability to go back and view the card they swiped on.

@JoniVR
Copy link
Owner

JoniVR commented Feb 27, 2020

Makes sense, do you have any suggestions? Perhaps we could add an extra didDragCard delegate method that returns a dragOffset indicating how far the card is relative to the center? Of course you'd still need to disable swiping after reaching the offset you need..

@tracknemo
Copy link
Author

Makes sense, do you have any suggestions? Perhaps we could add an extra didDragCard delegate method that returns a dragOffset indicating how far the card is relative to the center? Of course you'd still need to disable swiping after reaching the offset you need..

Hmm...I think that is a good idea. Although, when would I as a developer know where to re-enable swiping once the card is visible again?

@JoniVR
Copy link
Owner

JoniVR commented Feb 27, 2020

You'd want to re-enable it when you dismiss the new ViewController right? Plenty of ways of doing that, you could use a delegate callback or notification (observer) to re-enable it once you dismiss the viewcontroller for example.

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

No branches or pull requests

2 participants