Shuffle icon indicating copy to clipboard operation
Shuffle copied to clipboard

One unresponsive image appears at top of stack

Open mran3 opened this issue 5 years ago • 26 comments

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 avatar Jul 13 '20 06:07 mran3

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 avatar Jul 13 '20 21:07 mac-gallagher

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

mac-gallagher avatar Jul 17 '20 21:07 mac-gallagher

Hi I needed to send some example project so I ended up using another library. It could be my fault because I was adding images to the stack downloaded from an URL and the error used to appear when calling reloadData.

Ingeniero de sistemas y escritor Twitter: @mran3

On 17/07/2020, at 4:01 PM, Mac Gallagher [email protected] wrote:



@mran3https://github.com/mran3 did you find a fix for this? I am still unable to reproduce it and would like to address this issue

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/mac-gallagher/Shuffle/issues/108#issuecomment-660335976, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAT4W5JYLA5QNSWZHBIZH23R4C32HANCNFSM4OYGJ2MA.

mran3 avatar Jul 17 '20 23:07 mran3

@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

mac-gallagher avatar Jul 18 '20 01:07 mac-gallagher

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

sharadchauhan0504 avatar Sep 10 '20 09:09 sharadchauhan0504

Yeah, that is what happened to me.


De: Sharad Chauhan [email protected] Enviado: jueves, 10 de septiembre de 2020 4:38 a. m. Para: mac-gallagher/Shuffle [email protected] Cc: Andres Acevedo [email protected]; Mention [email protected] Asunto: Re: [mac-gallagher/Shuffle] One unresponsive image appears at top of stack (#108)

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:

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/mac-gallagher/Shuffle/issues/108#issuecomment-690115648, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAT4W5MNE55LI5XIJPZYOFLSFCNBNANCNFSM4OYGJ2MA.

mran3 avatar Sep 11 '20 01:09 mran3

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

mac-gallagher avatar Sep 11 '20 19:09 mac-gallagher

@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)

sharadchauhan0504 avatar Sep 12 '20 04:09 sharadchauhan0504

Ok, where are you calling this code block from? One of the delegate methods?

mac-gallagher avatar Sep 12 '20 04:09 mac-gallagher

@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.

sharadchauhan0504 avatar Sep 12 '20 04:09 sharadchauhan0504

So you’re not calling the API immediately after a swipe?

mac-gallagher avatar Sep 12 '20 19:09 mac-gallagher

No, it’s adding as soon as it is getting response.

sharadchauhan0504 avatar Sep 12 '20 19:09 sharadchauhan0504

Got it. Will look into this. I’m wondering if it’s updating the card stack in the middle of an animation

mac-gallagher avatar Sep 12 '20 19:09 mac-gallagher

Yes, that is correct. I feel so, it updates the cards in between.

sharadchauhan0504 avatar Sep 12 '20 19:09 sharadchauhan0504

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

sharadchauhan0504 avatar Sep 23 '20 07:09 sharadchauhan0504

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: https://github.com/mac-gallagher/Shuffle/issues/112#issuecomment-673252305. 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

mac-gallagher avatar Sep 24 '20 02:09 mac-gallagher

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

davidecastello avatar Oct 23 '20 12:10 davidecastello

@mac-gallagher Hi, sorry to bother you. I just wanted to ask you if you plan on working on what you mentioned here https://github.com/mac-gallagher/Shuffle/issues/112#issuecomment-673252305 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!

davidecastello avatar Oct 29 '20 16:10 davidecastello

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

lukasrosenke avatar Feb 08 '21 22:02 lukasrosenke

I'm also interested in a fix - thanks.

LoopingLouieX avatar Feb 09 '21 09:02 LoopingLouieX

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!

davidecastello avatar Feb 09 '21 12:02 davidecastello

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?

LoopingLouieX avatar Feb 09 '21 16:02 LoopingLouieX

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

IsaiahJTurner avatar Feb 11 '21 02:02 IsaiahJTurner

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 avatar Feb 11 '21 17:02 davidecastello

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!

davidecastello avatar Mar 08 '21 14:03 davidecastello

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

ifamirhasan avatar Apr 03 '24 09:04 ifamirhasan