Skip to content

Instantly share code, notes, and snippets.

@truongtv22
Forked from alexbrillant/lazy-loading.js
Created June 26, 2017 08:29
Show Gist options
  • Save truongtv22/2d792067d4f1628ad2d89b29ffb551c1 to your computer and use it in GitHub Desktop.
Save truongtv22/2d792067d4f1628ad2d89b29ffb551c1 to your computer and use it in GitHub Desktop.
import React, { Component } from "react"
import Swiper from "react-native-deck-swiper"
import { StyleSheet, View, Text, Image, Button } from "react-native"
export default class Exemple extends Component {
constructor(props) {
super(props)
this.state = {
cards: [1, 2],
swipedAllCards: false,
isSwipingBack: false,
cardIndex: 0
}
}
renderCard = (card) => {
return (
<View style={styles.card}>
<Text style={styles.text}>{card}</Text>
</View>
)
}
onSwiped = () => {
const {cards} = this.state
const newCardNumber = cards[cards.length - 1] + 1
this.setState({
cards: [...this.state.cards, newCardNumber]
})
}
render() {
return (
<View style={styles.container}>
<Swiper
ref={swiper => {
this.swiper = swiper
}}
onSwiped={this.onSwiped}
cards={this.state.cards}
cardIndex={this.state.cardIndex}
cardVerticalMargin={80}
renderCard={this.renderCard} />
</View>
)
}
}
const styles = StyleSheet.create({
box1: {
flex: 1
},
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"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment