1.1.1 • Published 2 years ago

rn-card-swiper v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React Native Card Swiper

A card swiper library using Reanimated 2

Preview

@screenshot-rn-card-swiper

Installation

npm install --save rn-card-swiper

or

yarn add rn-card-swiper

Dependencies

yarn add react-native-gesture-handler react-native-reanimated

Usage

import { CardSwiper } from 'rn-card-swiper';

// ...
const Data = [{ id: '1' }, { id: '2' }, { id: '3' }, { id: '4' }, { id: '5' }, { id: '6' }, { id: '7' }];

const _renderCard = (item: any) => {
    return (
      <View
        style={{
          flex: 1,
          alignItems: 'flex-end',
          justifyContent: 'flex-end',
        }}>
        <Text
          style={{
            fontSize: 400,
            fontWeight: 'bold',
            color: '#C7E2FF',
            right: -40,
            bottom: -20,
          }}>
          {item.id}
        </Text>
      </View>
    );
  };

const _renderEmptyMessage = () => {
    return (
      <View>
        <Text
          style={{
            fontSize: 28,
            fontWeight: 'bold',
            color: '#C7E2FF',
          }}
        >
          No more cards...
        </Text>
      </View>
    );
  };
// ...
<CardSwiper
  stackSize={5}
  cardsData={Data}
  renderCard={_renderCard}
  renderEmptyView={_renderEmptyMessage}
  cardStyle={
    {
      width: 300,
      height: 400,
      backgroundColor: 'white',
      borderColor: '#0095FF',
      borderWidth: 1,
    }
  }
  />;
// ...

Component props

proptypedefaultdescription
cardsDataarray[]array of data for the cards to be rendered
renderCardfuncrenders the card based on the data
renderEmptyViewfuncrenders the view to be shown after swiped last card
stackSizenumber5number of cards to be shown
startIndexnumber0initial card index
infinitebooleantruekeep swiping indefinitely
cardStyleobjectOoverride default card style
containerStyleobjectoverride default container style
offsetDirectionobject"Top"which way cards offsets will be shown
offsetSpacenumber8distance between cards
scaleRationumber0.8cards scale ratio in stack
disableLeftSwipebooleanfalsedisable left swipe
disableRightSwipebooleanfalsedisable right swipe
disableTopSwipebooleanfalsedisable top swipe
disableBottomSwipebooleanfalsedisable bottom swipe
disableSwipebooleanfalsedisable swipe in all directions
horizontalSwipebooleantrueswipe cards horizontally
verticalSwipebooleantrueswipe cards vertically
onlyTopSwipeablebooleanfalseonly top card can be swiped
cardElevatedbooleantrueputs shadows on card
touchInsetnumber10card's touch range from the edge
onSwipedAllfuncfunction to be called when the last card is swiped
onSwipedfuncfunction to be called when a card is swiped
onTapfuncfunction to be called when a card is tapped
onResetfuncfunction to be called when a card is released back to it's original position
onSwipedLeftfuncfunction to be called when a card 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

MIT