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

One unresponsive image appears at top of stack #108

Open
mran3 opened this issue Jul 13, 2020 · 26 comments
Open

One unresponsive image appears at top of stack #108

mran3 opened this issue Jul 13, 2020 · 26 comments
Labels
bug Something isn't working

Comments

@mran3
Copy link

mran3 commented Jul 13, 2020

Screen Shot 2020-07-13 at 01 14 48
Describe the bug
I think it might have something to to with adding images dynamically. I am doing it this way:

self.cardImages.append(loadedImg)                    
let newIndices = Array(self.cardImages.count-1..<self.cardImages.count)
self.cardStack.appendCards(atIndices: newIndices)
@mran3 mran3 added the bug Something isn't working label Jul 13, 2020
@mac-gallagher
Copy link
Owner

mac-gallagher commented Jul 13, 2020

Hey @mran3, the code snippet you provided looks fine. Also if you're only adding one card at a time, you can just do

cardImages.append(loadedImg)
cardStack.appendCards(atIndices: [cardImages.count - 1])

Where is this code being called? Are you calling on the main thread?

@mac-gallagher
Copy link
Owner

@mran3 did you find a fix for this? I am still unable to reproduce it and would like to address this issue

@mran3
Copy link
Author

mran3 commented Jul 17, 2020 via email

@mac-gallagher
Copy link
Owner

@mran3 Thanks for the update. The appendCards feature is new so it could very well be an issue with the library. I will keep this open for now in case others face the same issue

@sharadchauhan0504
Copy link
Contributor

Hi, I am facing this issue I guess.
I am adding cards dynamically using the apendCards method. Also, I am adding cards again and again to achieve infinite swiping.

Issue:

  • Sometimes, when I do a swipe, one card gets stuck on the top. I am able to do the swiping, but the cards below the stuck card get swiped and the stuck card never goes away.
  • Here is how it behaves:
    ezgif com-video-to-gif

@mran3
Copy link
Author

mran3 commented Sep 11, 2020 via email

@mac-gallagher mac-gallagher reopened this Sep 11, 2020
@mac-gallagher
Copy link
Owner

mac-gallagher commented Sep 11, 2020

@mran3 @SKDEVIL can you share how you're adding the new cards? Are you calling appendCards on the main thread?

@sharadchauhan0504
Copy link
Contributor

@mac-gallagher Yes I am using that on main thread.
This is how I am adding more cards:


let oldModelsCount = self.offersArray.count
let newModelsCount = oldModelsCount + self.individualOffersArray.count
self.offersArray   += self.individualOffersArray
let newIndices     = Array(oldModelsCount..<newModelsCount)
self.cardStack.appendCards(atIndices: newIndices)

@mac-gallagher
Copy link
Owner

mac-gallagher commented Sep 12, 2020 via email

@sharadchauhan0504
Copy link
Contributor

@mac-gallagher No, I am calling this after I get a response from API. It's a paginated API, so right after I get one page, I call this code.

@mac-gallagher
Copy link
Owner

mac-gallagher commented Sep 12, 2020 via email

@sharadchauhan0504
Copy link
Contributor

sharadchauhan0504 commented Sep 12, 2020 via email

@mac-gallagher
Copy link
Owner

mac-gallagher commented Sep 12, 2020 via email

@sharadchauhan0504
Copy link
Contributor

sharadchauhan0504 commented Sep 12, 2020 via email

@sharadchauhan0504
Copy link
Contributor

@mac-gallagher Hi, did you get a chance to look into it?

@mac-gallagher
Copy link
Owner

Hey @SKDEVIL . Yes, I took a look and it doesn't seem like a straightforward fix. I'd like to do something similar to what I mentioned here: #112 (comment). Maybe to detect if the card stack is animating, you could subclass SwipeCard and override the beginSwiping/continueSwiping/endSwiping methods to detect if the top card is being dragged. However, there is still the issue of detecting if the top card is animating.

Unfortunately, I won't have the time to put out a fix anytime soon (working full time + other side projects). Feel free to throw any suggestions out or put up a PR in the meantime

@davidecastello
Copy link

@mac-gallagher Hi, did you get a chance to work on this issue? I'm having some troubles as well.

@davidecastello
Copy link

@mac-gallagher Hi, sorry to bother you.
I just wanted to ask you if you plan on working on what you mentioned here #112 (comment) or if maybe there's already a PR or a fork of this repo that does this, or fixes this bug.
Thanks for your time, and this library is great!

@lukasrosenke
Copy link

Hey, did any of you fix/ got a workaround for this.

@LoopingLouieX
Copy link

LoopingLouieX commented Feb 9, 2021

I'm also interested in a fix - thanks.

@davidecastello
Copy link

davidecastello commented Feb 9, 2021

I found these two forks that mentions this issue:

  1. https://github.com/Yahenskyi/Shuffle
  2. https://github.com/LiuSky/Shuffle

I haven't tried them yet, but maybe they work. Let me know!

@LoopingLouieX
Copy link

LoopingLouieX commented Feb 9, 2021

I've integrated LiuSky's method of fetching the isAnimated status and optimized it to my needs a little bit.
It's working better than before but in case of faster swipes it's still the case that the issue appears.
Edit: After some more testing I can say that this method is not helping much..

@mac-gallagher Do you have an alternative solution for this?

@IsaiahJTurner
Copy link

I'm also experiencing this. I'll try using isAnimating but in any case this is not good.

@davidecastello
Copy link

I wrote an email to @mac-gallagher and he said that he's working on some other projects right now + fulltime job, so I don't think he'll be able to help us.

Anyone got any idea on how to fix this?

@davidecastello
Copy link

Guys, we fixed it by appending the cards on the swipeCardStack on the main thread.

So wrap the method where you append the cards like:

DispatchQueue.main.async {
  self.updateCards(values)
}

Let me know if this solution fixes the problem for you as well!

@ifamirhasan
Copy link

ifamirhasan commented Apr 3, 2024

Guys try this temporary fix:
update this function in this file:
SwipeCardStack.swift

func reloadVisibleCards() {
      visibleCards.forEach {
          $0.card.swipeDirections = []
          $0.card.removeFromSuperview()
      }
      visibleCards.removeAll()
      
      cardContainer.subviews.forEach { $0.removeFromSuperview() }
      
      let numberOfCards = min(stateManager.remainingIndices.count, numberOfVisibleCards)
      for position in 0..<numberOfCards {
          let index = stateManager.remainingIndices[position]
          if let card = loadCard(at: index) {
              self.insertCard(Card(index: index, card: card), at: position)
        }
      }
      
      isAnimating = false
  }

you can also check my fork:
https://github.com/ifamirhasan/Shuffle/tree/dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants