0.0.2 • Published 10 months ago

react-native-slide-cards v0.0.2

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

 

react-native-slide-cards

"react-native-slide-cards" is an easy-to-use React Native package that allows you to turn your data into animated sliding cards. It is suitable for simple and medium-sized projects, and simplifies the process of creating interactive cards.

This package is simply built by me using expo and Moti with function-based components.

gif1 gif2

 

Installation

To use "react-native-slide-cards," you can install it using npm:

npm install react-native-slide-cards

 

Properties

PropertyDescriptionTypeDefault
cardsThe data array used to create the cards (required)array-
closenessThe closeness level of the cardsnumber1.5
cardHeightThe height of the cardsnumber230
radiusThe border radius of the cardsnumber50
dampingdumping ratenumber15
massmass ratenumber1
durationThe animation durationnumber300
gapThe distance between cards when openednumber-
headerImagePressabilityWhether the image in the header is clickablebooleantrue
cardPressThe function triggered when a card is pressedfunction-
headerAppearanceThe appearance layout of the headerobject{ left: 'image', 'title', middle: [], right: 'icon' }
cardBackgroundTagThe data array key for the background image in the cardstring-
cardBackgroundBlurThe blur level of the card background (0-100)number-
headerTextTagThe data array key for the header textstring-
headerImageTagThe data array key for the header imagestring-
headerIconTagThe data array key for the header iconstring-
headerIconPressThe function triggered when the header icon is pressedfunction-
headerImagePressThe function triggered when the header image is pressedfunction-
headerIconVisibilityThe visibility of the header iconbooleantrue
headerImageStyleThe style of the header imageobject-
headerTextStyleThe style of the header textobject-
headerIconStyleThe style of the header iconobject-
modeThe view mode ('light' or 'dark')string'light'
cardColorThe background color(s) of the cardsarray-
mainContentThe main content of the cardfunction-
cardBackgroundUrlThe URL for the card background imagestring-
headerIconCustom icon view--

 

Example

import { ScrollView, StyleSheet, Text, View } from 'react-native';
import { SlidingCards } from 'react-native-slide-cards'
import React from "react";

export default function App() {
  const myData = [
    { id: 15412678, name: 'John Doe', phoneNum: '+1 (555) 123-4567', address: '1234 Dummy Street, Springfield, CA 12345', email: 'john.doe@example.com' },
    { id: 69273842, name: 'Olivia Martinez', phoneNum: '+61 2 9876 5432', address: '5432 Dummy Road, Sydney, Australia 2000', email: 'olivia.martinez@example.com' },
    { id: 37294815, name: 'Alex Johnson', phoneNum: '+49 (0)30 9876 5432', address: '9876 Dummy Lane, Berlin, Germany 10115', email: 'alex.johnson@example.com' },
    { id: 49027486, name: 'Emily Brown ', phoneNum: '+33 (0)1 2345 6789', address: '3456 Dummy Street, Paris, France 75001', email: 'emily.brown@example.com' },
    { id: 51284759, name: 'William Wilson', phoneNum: '+81 3-1234-5678', address: '1234 Dummy Blossom Lane, Tokyo, Japan 100-0001', email: 'william.wilson@example.com' }
  ]

  const mainContent = (data) => {
    return (
      <View style={{ width: '100%', height: '100%' }}>
        <Text>{data.phoneNum}</Text>
        <Text>{data.email}</Text>
        <Text>{data.address}</Text>
      </View>
    )
  }

  return (
    <View style={styles.container}>
      <ScrollView style={{ width: '100%' }}>
        <SlidingCards
          cards={myData}
          headerTextTag={'name'}
          mainContent={mainContent}
        />
      </ScrollView>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#000000',
    alignItems: 'center',
  },
});

 

Dependencies

moti

expo-linear-gradient

react-native-gesture-handler

react-native-reanimated

 

Notes

Make sure the dependencies required for this package are compatible with your react-native and expo version.

This package is using react-native-reanimated. Update your babel.config file as follows

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: ['react-native-reanimated/plugin'], <-- add this
  };
};

 

0.0.2

10 months ago

0.0.1

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago