1.1.0 • Published 4 years ago

@siac/react-native-swipable-deck v1.1.0

Weekly downloads
-
License
MIT
Repository
bitbucket
Last release
4 years ago

Swipable Deck for React Native

React Native component for a deck with swipable items


Attention!

This library is built for internal use at Siac. There may be frequent changes in the functionality or new versions will introduce breaking changes without any prior notice.

Installation

yarn add @siac/react-native-swipable-deck

Usage

import { Deck, DeckItem } from "@siac/react-native-swipable-deck";
<Deck
  style={styles.content}
  ref={(stack) => {
    this.stack = stack;
  }}
>
  <DeckItem style={[styles.card, styles.card1]}>
    <Text style={styles.label}>A</Text>
  </DeckItem>
  <DeckItem style={[styles.card, styles.card2]}>
    <Text style={styles.label}>B</Text>
  </DeckItem>
  <DeckItem style={[styles.card, styles.card1]}>
    <Text style={styles.label}>C</Text>
  </DeckItem>
</Deck>

Components

Deck

Deck props

Propstypedescriptionrequireddefault
styleobjectcontainer style{}
cardContainerStyleobjectcardContainerStyle style{}
secondCardZoomnumbersecond card zoom0.95
durationnumberanimation duration300
initialIndexnumberinitial card index0
loopboolkeep swiping indefinitelyfalse
renderNoMoreCardsfuncfalse
disableTopSwipebooldisable top swipefalse
disableBottomSwipebooldisable bottom swipefalse
disableLeftSwipebooldisable left swipefalse
disableRightSwipebooldisable right swipefalse
verticalSwipeboolenable/disable vertical swipingtrue
horizontalSwipeboolenable/disable horizont swipingtrue
verticalThresholdnumbervertical swipe thresholdheight/4
horizontalThresholdnumberhorizontal swipe thresholdwidth/2
outputRotationRangearrayrotation values for the x values'-15deg', '0deg', '15deg'

Deck events

Propstypedescription
onSwipeStartfuncfunction to be called when a card swipe starts
onSwipeEndfuncfunction to be called when a card swipe ends (card is released)
onSwipedfuncfunction to be called when a card is swiped. it receives the swiped card index
onSwipedLeftfuncfunction to be called when a card is swiped left. it receives the swiped card index
onSwipedRightfuncfunction to be called when a card is swiped right. it receives the swiped card index
onSwipedTopfuncfunction to be called when a card is swiped top. it receives the swiped card index
onSwipedBottomfuncfunction to be called when a card is swiped bottom. it receives the swiped card index
onSwipedAllasync funcfunction to be called when the last card is swiped. Could trig action to refresh cards
onSwipefuncfunction to be called when a card is swiped. It receives the current x, and y coordinates

Deck actions

Propstype
swipeLeftfunc
swipeRightfunc
swipeBottomfunc
swipeTopfunc
goBackFromLeftfunc
goBackFromRightfunc
goBackFromBottomfunc
goBackFromTopfunc
  <Deck style={styles.content} ref={swiper => { this.swiper = swiper }}>
    <DeckItem style={[styles.card, styles.card1]}><Text style={styles.label}>A</Text></DeckItem>
    <DeckItem style={[styles.card, styles.card2]}><Text style={styles.label}>B</Text></DeckItem>
  </Deck>

  <TouchableOpacity onPress={ () => { this.swiper.swipeLeft() }}>
    <Text>Left</Text>
  </TouchableOpacity>

DeckItem

DeckItem props

Propstypedescriptionrequireddefault
styleobjectcontainer style{}

DeckItem events

Propstypedescription
onSwipedfuncfunction to be called when a card is swiped.
onSwipedLeftfuncfunction to be called when a card is swiped left.
onSwipedRightfuncfunction to be called when a card is swiped right.
onSwipedTopfuncfunction to be called when a card is swiped top.
onSwipedBottomfuncfunction to be called when a card is swiped bottom.

License

Swipable Deck is licensed under the MIT license.

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago