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

Append card without UI interference #112

Open
LoopingLouieX opened this issue Aug 4, 2020 · 11 comments
Open

Append card without UI interference #112

LoopingLouieX opened this issue Aug 4, 2020 · 11 comments

Comments

@LoopingLouieX
Copy link

Hi,

from time to time I am appending some cards to the cardStack with the cardModels.append(newModel) method.
As you have written in the docs i have to update the card stack occasionally.
But if I update the cardstack with cardStack.reloadData() in the same moment as a user is dragging the top card in the UI i.e a little bit to the right side so that the overlay is visible (but didn't finished the swipe) then the top card catches back to the middle automatically.
Is there any possibility to avoid that ? Maybe reloading the cardstack in the background without interfering the UI?

@mac-gallagher
Copy link
Owner

mac-gallagher commented Aug 5, 2020

Hi @LoopingLouieX. You should not be calling reloadData after appending your cards, as it will remove all of your swipe history. The append method on SwipeCardStack will take care of reloading the data for you.

Any call to reloadData will immediately re-fetch the data from the data source - this is intentional. It should also only be called from the main thread.

@LoopingLouieX
Copy link
Author

LoopingLouieX commented Aug 5, 2020

Understand!
Just tried that out but adding the cards in the background without disturbing the UI is still not possible.
The top card is always dragged back automatically to the original position.
Is there any way to avoid that ? That's really disturbing for users I think.

Edit: I mean it's understandable for me if there is just one or two cards in the stack as example.
But if there's a stack with 20 cards and I append one after the last card so that 21 are in the stack then the top card get's still interrupted and the user could be irritated.

@mac-gallagher mac-gallagher reopened this Aug 5, 2020
@mac-gallagher
Copy link
Owner

mac-gallagher commented Aug 13, 2020

Hey @LoopingLouieX,

I think I see the issue now. I am considering adding cardStackDidBeginAnimating and cardStackDidFinishAnimating delegate methods or something similar so that one can refresh only when the user is not interacting with the card stack. This is similar to the scrollViewDidEndScrollingAnimation: method on UIScrollViewDelegate.

Your code would look something like this:

let cardStack = SwipeCardStack()

var cardModels: [CardModel] = [cardModel1, cardModel2 cardModel3]
var cardModelsToAdd: [CardModel] = []

var isAnimating = false {
  didSet {
    if !isAnimating && !cardModelsToAdd.isEmpty {
      cardStack.appendCards(cardModelsToAdd)
      cardModelsToAdd.removeAll()
    }
  }
}

// Call to fetch new card models
func fetchNewCardModels() {
  NetworkUtility.fetchCardModels { cardModels in
    self.cardModelsToAdd.append(cardModels)
  }
}

// MARK: - SwipeCardStackDelegate

func cardStackDidBeginAnimating(_ cardStack: SwipeCardStack) {
  isAnimating = true
}

func cardStackDidEndAnimating(_ cardStack: SwipeCardStack) {
  isAnimating = false
}

Let me know if this would resolve your situation

@LiuSky
Copy link

LiuSky commented Oct 12, 2020

Sorry, I didn't find the cardstackdidbiginanimating method,I think I can try the way you say

@LiuSky
Copy link

LiuSky commented Oct 12, 2020

It works, but I don't think it's perfect。

@LoopingLouieX
Copy link
Author

@LiuSky How did you managed to get this working?
I'm also unable to find cardStackDidBeginAnimating

@LiuSky
Copy link

LiuSky commented Oct 13, 2020

截屏2020-10-13 上午9 07 44

截屏2020-10-13 上午9 11 26

截屏2020-10-13 上午9 11 44

@LiuSky
Copy link

LiuSky commented Oct 13, 2020

@LoopingLouieX I'll fork one if you need it

@LoopingLouieX
Copy link
Author

@LiuSky Thanks for the help!
Now I got endSwiping recognized correctly, but somehow cardStackDidBeginAnimating & cardStackDidEndAnimating is still not getting executed.
Can you please so kind to fork this for me?
Thanks!

@LiuSky
Copy link

LiuSky commented Oct 14, 2020

https://github.com/LiuSky/Shuffle It works, but I don't think it's perfect。I'm going to deal with dynamic logic when I'm free。@LoopingLouieX

@LoopingLouieX
Copy link
Author

@LiuSky Thanks a lot! But it's still not perfect..
Anyway, any updates on this?

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