HomeOur TeamContact

Tinder Swipe Cards

By Utkarsh Lubal
Published in Swiper
April 01, 2023
1 min read
Tinder Swipe Cards

Table Of Contents

01
Introduction
02
Installation
03
Example
04
Tutorial

Introduction

React Native Swipe Cards is a popular library for building swipeable card interfaces in React Native applications. It provides a highly customizable and responsive card swipe interface that allows users to swipe cards left or right to interact with the app. With this library, you can easily create Tinder-style swipe cards that can be used for a variety of purposes, such as displaying products, news articles, user profiles, and more. React Native Swipe Cards provides several configurable props that allow you to customize the look and behavior of the swipeable cards, such as the swipe threshold, the card size, the card style, and more.

Props

Props nameTypeDescriptionDefault
cards*ArrayData that will be provided as props for the cards
renderCard*FunctionRenders the card with the current data
loopBooleanIf true, start again when run out of cardsfalse
onLoopFunctionCalled when card list returns to the beginning
renderNoMoreCardsFunctionRenders what is shown after swiped last card
showYupBooleanShows the ‘Yup’ componenttrue
showNopeBooleanShows the ‘Nope’true
showMaybeBooleanShows the ‘Maybe’true
hasMaybeActionBooleanIncludes the possibility to swipe up and its componentsfalse
renderYupFunctionRenders Yup
renderNopeFunctionRenders Nope
renderMaybeFunctionRenders Maybe
handleYupFunctionCalled when card is ‘passed’ with that card’s data
handleNopeFunctionCalled when card is ‘rejected’ with that card’s data
containerStylestyleOverride default style
yupStylestyleOverride default style
yupTextStylestyleOverride default style
nopeStylestyleOverride default style
nopeTextStylestyleOverride default style
maybeStylestyleOverride default style
maybeTextStylestyleOverride default style
yupViewelementReact component to render on a Yes vote
yupTextstringText to render on Yes voteYep
noViewelementReact component to render on a No vote
noTextstringText to render on No voteNope
maybeViewelementReact component to render on a Maybe vote
maybeTextstringText to render on Maybe voteMaybe
smoothTransitionBooleanDisables a slow transition fading the current card outfalse
cardKeyStringReact key to be used to for each card
dragYBooleanAllows dragging cards verticallytrue
stackBooleanEnables the stack modefalse
stackOffsetXNumberHorizontal offset between cards in stack25
stackOffsetYNumberVertical offset between cards in stack0
cardRemovedFunctionA callback passing the card reference that just got removed
onClickHandlerFunctionA callback clicking the cardalert(‘tap’)

Installation

npm install --save react-native-swipe-cards

Example

import React from 'react';
import {StyleSheet, Text, View, Image} from 'react-native';

import SwipeCards from 'react-native-swipe-cards';

class Card extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <View style={styles.card}>
        <Image style={styles.thumbnail} source={{uri: this.props.image}} />
        <Text style={styles.text}>This is card {this.props.name}</Text>
      </View>
    )
  }
}

class NoMoreCards extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <View style={styles.noMoreCards}>
        <Text>No more cards</Text>
      </View>
    )
  }
}

const cards = [
  {name: '1', image: 'https://media.giphy.com/media/GfXFVHUzjlbOg/giphy.gif'},
  {name: '2', image: 'https://media.giphy.com/media/irTuv1L1T34TC/giphy.gif'},
  {name: '3', image: 'https://media.giphy.com/media/LkLL0HJerdXMI/giphy.gif'},
  {name: '4', image: 'https://media.giphy.com/media/fFBmUMzFL5zRS/giphy.gif'},
  {name: '5', image: 'https://media.giphy.com/media/oDLDbBgf0dkis/giphy.gif'},
  {name: '6', image: 'https://media.giphy.com/media/7r4g8V2UkBUcw/giphy.gif'},
  {name: '7', image: 'https://media.giphy.com/media/K6Q7ZCdLy8pCE/giphy.gif'},
  {name: '8', image: 'https://media.giphy.com/media/hEwST9KM0UGti/giphy.gif'},
  {name: '9', image: 'https://media.giphy.com/media/3oEduJbDtIuA2VrtS0/giphy.gif'},
]

const cards2 = [
  {name: '10', image: 'https://media.giphy.com/media/12b3E4U9aSndxC/giphy.gif'},
  {name: '11', image: 'https://media4.giphy.com/media/6csVEPEmHWhWg/200.gif'},
  {name: '12', image: 'https://media4.giphy.com/media/AA69fOAMCPa4o/200.gif'},
  {name: '13', image: 'https://media.giphy.com/media/OVHFny0I7njuU/giphy.gif'},
]

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      cards: cards,
      outOfCards: false
    }
  }

  handleYup (card) {
    console.log("yup")
  }

  handleNope (card) {
    console.log("nope")
  }

  cardRemoved (index) {
    console.log(`The index is ${index}`);

    let CARD_REFRESH_LIMIT = 3

    if (this.state.cards.length - index <= CARD_REFRESH_LIMIT + 1) {
      console.log(`There are only ${this.state.cards.length - index - 1} cards left.`);

      if (!this.state.outOfCards) {
        console.log(`Adding ${cards2.length} more cards`)

        this.setState({
          cards: this.state.cards.concat(cards2),
          outOfCards: true
        })
      }

    }

  }

  render() {
    return (
      <SwipeCards
        cards={this.state.cards}
        loop={false}

        renderCard={(cardData) => <Card {...cardData} />}
        renderNoMoreCards={() => <NoMoreCards />}
        showYup={true}
        showNope={true}

        handleYup={this.handleYup}
        handleNope={this.handleNope}
        cardRemoved={this.cardRemoved.bind(this)}
      />
    )
  }
}

const styles = StyleSheet.create({
  card: {
    alignItems: 'center',
    borderRadius: 5,
    overflow: 'hidden',
    borderColor: 'grey',
    backgroundColor: 'white',
    borderWidth: 1,
    elevation: 1,
  },
  thumbnail: {
    width: 300,
    height: 300,
  },
  text: {
    fontSize: 20,
    paddingTop: 10,
    paddingBottom: 10
  },
  noMoreCards: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  }
})

Tutorial

Coming Soon…


Tags

tindercardsswipe
Previous Article
React Native Secure Storage
Utkarsh Lubal

Utkarsh Lubal

Full Stack Developer

Related Posts

Swiper Animated
Swiper Animated
May 06, 2023
1 min

Quick Links

Advertise with usAbout UsContact Us

Social Media