0.0.2 • Published 6 months ago

expo-deck-swiper v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Expo Deck Swiper

A highly customizable and performant deck swiper component for React Native and Expo, featuring smooth animations, gesture controls, and extensive customization options.

Features

  • 👆 Smooth swipe gestures (left, right, up, down)
  • 🎯 Single and double tap support
  • 🎨 Customizable overlay labels for swipe directions
  • 💅 Flexible styling options for cards and container
  • 🔄 Card recycling for optimal performance
  • 📱 Built for React Native and Expo
  • 📦 TypeScript support

Installation

npm install expo-deck-swiper
# or
yarn add expo-deck-swiper

This package requires the following peer dependencies:

{
  "react": ">=16.8.0",
  "react-native": ">=0.60.0",
  "react-native-gesture-handler": ">=2.0.0",
  "react-native-reanimated": ">=2.0.0"
}

Basic Usage

import { DeckSwiper } from "expo-deck-swiper";

const data = [
  { id: "1", name: "Card 1" },
  { id: "2", name: "Card 2" },
];

export default function App() {
  return (
    <DeckSwiper
      data={data}
      renderCard={(item) => (
        <View style={styles.card}>
          <Text>{item.name}</Text>
        </View>
      )}
      onSwipeLeft={(item) => console.log("Swiped left:", item)}
      onSwipeRight={(item) => console.log("Swiped right:", item)}
    />
  );
}

Props

Required Props

PropTypeDescription
dataT[]Array of items to be rendered as cards
renderCard(item: T) => React.ReactNodeFunction to render individual cards

Optional Props

PropTypeDescription
onSwipeLeftSwipeCallback<T>Callback when card is swiped left
onSwipeRightSwipeCallback<T>Callback when card is swiped right
onSwipeUpSwipeCallback<T>Callback when card is swiped up
onSwipeDownSwipeCallback<T>Callback when card is swiped down
onSingleTapSwipeCallback<T>Callback for single tap on card
onDoubleTapSwipeCallback<T>Callback for double tap on card
onDragStartSwipeCallback<T>Callback when card drag starts
onDragEndSwipeCallback<T>Callback when card drag ends
overlayLabelsOverlayLabelsCustom overlay components for each swipe direction
containerStyleViewStyleStyle for the container component
cardStyleViewStyleStyle for the card component
backCardStyleViewStyleStyle for the card behind the top card
overlayContainerStyleViewStyleStyle for the overlay container
renderAheadCountnumberNumber of cards to render ahead (default: 2)

Advanced Usage

Custom Overlay Labels

<DeckSwiper
  data={data}
  renderCard={renderCard}
  overlayLabels={{
    left: <Text style={{ color: "red" }}>NOPE</Text>,
    right: <Text style={{ color: "green" }}>LIKE</Text>,
    up: <Text style={{ color: "blue" }}>SUPER LIKE</Text>,
    down: <Text style={{ color: "orange" }}>MAYBE</Text>,
  }}
/>

Custom Styling

<DeckSwiper
  data={data}
  renderCard={renderCard}
  containerStyle={{
    backgroundColor: "#f5f5f5",
    padding: 10,
  }}
  cardStyle={{
    borderRadius: 15,
    shadowColor: "#000",
    shadowOpacity: 0.2,
    shadowRadius: 5,
  }}
  backCardStyle={{
    opacity: 0.7,
    transform: [{ scale: 0.9 }],
  }}
/>

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT