Closed xavier-villelegier closed 6 years ago
it also happens if there is more than one element in an array. After last element first element appears again, then after swiping that element screen gets clear
import React, { Component } from "react";
import Swiper from "react-native-deck-swiper";
import { Button, StyleSheet, Text, View } from "react-native";
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
cards: [
{ text: "is", color: "red" },
{ text: "that", color: "green" },
{ text: "what", color: "blue" },
{ text: "you", color: "yellow" },
{ text: "meant", color: "pink" }
],
swipedAllCards: false,
swipeDirection: "",
isSwipingBack: false,
cardIndex: 0
};
}
renderCard = (card, index) => {
return (
<View style={styles.card}>
<Text
style={{
textAlign: "center",
fontSize: 50,
fontWeight: "bold",
backgroundColor: "transparent",
color: card.color
}}
>
{card.text}
</Text>
</View>
);
};
onSwipedAllCards = () => {
this.setState({
swipedAllCards: true
});
};
swipeBack = () => {
if (!this.state.isSwipingBack) {
this.setIsSwipingBack(true, () => {
this.swiper.swipeBack(() => {
this.setIsSwipingBack(false);
});
});
}
};
setIsSwipingBack = (isSwipingBack, cb) => {
this.setState(
{
isSwipingBack: isSwipingBack
},
cb
);
};
swipeLeft = () => {
this.swiper.swipeLeft();
};
render() {
return (
<View style={styles.container}>
<Swiper
ref={swiper => {
this.swiper = swiper;
}}
onSwiped={this.onSwiped}
onTapCard={this.swipeLeft}
cards={this.state.cards}
cardIndex={this.state.cardIndex}
cardVerticalMargin={80}
renderCard={this.renderCard}
onSwipedAll={this.onSwipedAllCards}
stackSize={3}
stackSeparation={15}
overlayLabels={{
bottom: {
title: "BLEAH",
style: {
label: {
backgroundColor: "black",
borderColor: "black",
color: "white",
borderWidth: 1
},
wrapper: {
flexDirection: "column",
alignItems: "center",
justifyContent: "center"
}
}
},
left: {
title: "NOPE",
style: {
label: {
backgroundColor: "black",
borderColor: "black",
color: "white",
borderWidth: 1
},
wrapper: {
flexDirection: "column",
alignItems: "flex-end",
justifyContent: "flex-start",
marginTop: 30,
marginLeft: -30
}
}
},
right: {
title: "LIKE",
style: {
label: {
backgroundColor: "black",
borderColor: "black",
color: "white",
borderWidth: 1
},
wrapper: {
flexDirection: "column",
alignItems: "flex-start",
justifyContent: "flex-start",
marginTop: 30,
marginLeft: 30
}
}
},
top: {
title: "SUPER LIKE",
style: {
label: {
backgroundColor: "black",
borderColor: "black",
color: "white",
borderWidth: 1
},
wrapper: {
flexDirection: "column",
alignItems: "center",
justifyContent: "center"
}
}
}
}}
animateOverlayLabelsOpacity
animateCardOpacity
>
<Button onPress={this.swipeLeft} title="Swipe Left" />
</Swiper>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#F5FCFF"
},
card: {
flex: 1,
borderRadius: 4,
borderWidth: 2,
borderColor: "#E8E8E8",
justifyContent: "center",
backgroundColor: "white"
},
text: {
textAlign: "center",
fontSize: 50,
backgroundColor: "transparent"
},
done: {
textAlign: "center",
fontSize: 30,
color: "white",
backgroundColor: "transparent"
}
});
the problem occures when i set the state in any event
I'm having the same issue. It only happens when only 1 card is rendered.
I've just tried to replicate this using the demo app and I could validate it. I'll try looking into it.
Hey !
I think there is a bug when
cards
is only an array of 1 element. The card just reappears and you have to swipe it again, or wait until it suddenly disappears.GIF
Code
Repro
And here is a snack repro