question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rerendering card resets Swiper to first card

See original GitHub issue

how can i rerender a card, but not reset the Swiper to the first card ?

consider the following within the render function:

const cardData = this.state.cardData
const myCards = map(cardData, (card, cardIndex) => {
  return (
    <CardComponent
      key={cardIndex}
      prop={card.prop}
      onEvent={this.onEvent}
    />
  )
})

return (
  <Swiper
    ref={swiper => this.swiper = swiper}
    cards={myCards}
    cardVerticalMargin={0}
    cardHorizontalMargin={0}
    infinite={true}
    renderCard={card => card}
    backgroundColor={'transparent'}
    verticalSwipe={false}
    onSwiped={() => false}
    onSwipedAll={() => false}
    onSwipedLeft={() => false}
    onSwipedRight={() => false}
  ></Swiper>
)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
yonahforstcommented, Dec 26, 2017

@bispul I fixed my issue by adding cardIndex to the state and then incrementing it in the onSwiped callback

2reactions
webraptorcommented, Nov 3, 2017

Ah, ok … The bug is re-rendering and swiping will keep the second card to the second one in the original card deck, rather than the one you’ve swiped to so far … We’ve experienced this issue for about a month now, just created the PR with the fix. https://github.com/alexbrillant/react-native-deck-swiper/pull/76/files

Read more comments on GitHub >

github_iconTop Results From Across the Web

Content of card does not render when state changed in react ...
Unfortunately the Swiper will not know whether to rerender itself if a state changes inside unless you swipe the card around which will ......
Read more >
Swiper breaks when using Sprig - Craft CMS Stack Exchange
I am using Sprig to re-render some cards based on some parameters (with a dropdown filter). These cards also use Swiper to create...
Read more >
Swiper API
Swiper is the most modern free mobile touch slider with hardware accelerated transitions and amazing native behavior.
Read more >
Slow rendering - Android Developers
To fix jank, inspect which frames aren't completing in 16.7ms, and look for what is going wrong. Is Record View#draw taking abnormally long...
Read more >
useMemo Hook - React Hooks Handbook - Design+Code
Create your first React app. 4:23 ... Re-rendering of the card. Now, this isn't really optimal, since the UserCard is a component that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found