mirror of
https://github.com/zhigang1992/react-native-card-stack-swiper.git
synced 2026-01-12 17:42:18 +08:00
Add initialize deck method
This commit is contained in:
24
CardStack.js
24
CardStack.js
@@ -121,7 +121,20 @@ export default class CardStack extends Component {
|
||||
}
|
||||
|
||||
componentDidMount(){
|
||||
this.initDeck();
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps){
|
||||
if (nextProps.children !== this.props.children) {
|
||||
this.setState({
|
||||
cards: nextProps.children,
|
||||
cardA: nextProps.children[(this.state.topCard=='cardA')? this.state.sindex-2 : this.state.sindex-1],
|
||||
cardB: nextProps.children[(this.state.topCard=='cardB')? this.state.sindex-2 : this.state.sindex-1]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
initDeck() {
|
||||
// check if we only have 1 child
|
||||
if(typeof this.props.children !== 'undefined' && !Array.isArray(this.props.children)){
|
||||
this.setState({
|
||||
@@ -138,17 +151,6 @@ export default class CardStack extends Component {
|
||||
sindex: 2,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps){
|
||||
if (nextProps.children !== this.props.children) {
|
||||
this.setState({
|
||||
cards: nextProps.children,
|
||||
cardA: nextProps.children[(this.state.topCard=='cardA')? this.state.sindex-2 : this.state.sindex-1],
|
||||
cardB: nextProps.children[(this.state.topCard=='cardB')? this.state.sindex-2 : this.state.sindex-1]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_resetCard(){
|
||||
|
||||
Reference in New Issue
Block a user