Make sure you set showSecondCard={false} for smoother and proper transitions while going back to previous card.
Props
type
description
default
goBackToPreviousCardOnSwipeLeft
bool
previous card is rendered on left swipe
false
goBackToPreviousCardOnSwipeRight
bool
previous card is rendered on right swipe
false
goBackToPreviousCardOnSwipeTop
bool
previous card is rendered on top swipe
false
goBackToPreviousCardOnSwipeBottom
bool
previous card is rendered on bottom swipe
false
Style props
Props
type
description
default
backgroundColor
string
background color for the view containing the cards
'#4FD0E9'
marginTop
number
marginTop for the swiper container
0
marginBottom
number
marginBottom for the swiper container
0
cardVerticalMargin
number
card vertical margin
60
cardHorizontalMargin
number
card horizontal margin
20
childrenOnTop
bool
render children on top or not
false
cardStyle
node
override swipable card style
{}
Methods
To trigger imperative animations, you can use a reference to the Swiper component.
Props
arguments
description
swipeLeft
mustDecrementCardIndex = false
swipe left to the next card
swipeRight
mustDecrementCardIndex = false
swipe right to the next card
swipeTop
mustDecrementCardIndex = false
swipe top to the next card
swipeBottom
mustDecrementCardIndex = false
swipe bottom to the next card
swipeBack
callback
swipe back into deck last swiped card
jumpToCardIndex
cardIndex
set the current card index
Usage example
render(){<Viewstyle={styles.container}><Swipercards={['DO','MORE','OF','WHAT','MAKES','YOU','HAPPY']}renderCard={(card)=>{return(<Viewstyle={styles.card}><Textstyle={styles.text}>{card}</Text></View>)}}onSwiped={(cardIndex)=>{console.log(cardIndex)}}onSwipedAll={()=>{console.log('onSwipedAll')}}cardIndex={0}backgroundColor={'#4FD0E9'}stackSize={3}><ButtononPress={()=>{console.log('oulala')}}title="Press me">
You can press me
</Button></Swiper></View>}
Updating props on card content? (dynamic card content)
Card properties may change, including on already swiped cards, which would yield no effects to users as the cards would no longer be displayed [based on initial issue].
A possible fix for the situation is setting the cardIndex on the parent component whenever deck re-renders are needed.
Passing along the cardIndex to the swiper will allow external changes on the property, thus triggering a re-render of the deck of cards. All onSwipe callbacks return the cardIndex that can be used to push the updated cardIndex to app state (redux or something else).
By making sure that external changes on the cardIndex match those the swiper performs (increment on swipes, decrement on swipeBack) one can ensure no re-renders occur when not needed.