0.7.0 • Published 5 months ago

react-native-intro-carousel v0.7.0

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

react-native-intro-carousel

An introduction page carousel animated with pagination

Installation

npm install react-native-intro-carousel

or

yarn add react-native-intro-carousel

Usage

import Carousel from "react-native-intro-carousel";

// ...

<Carousel
  data={[
    {
      key: '1',
      title: 'Cool package',
      description: 'This is a cool package',
      backgroundColor: '#e879f2',
      image: require('./..'),
      titleStyle: {
        color: 'white',
      },
      descriptionStyle: {
        color: 'white',
      },
    },
  ]}
  paginationConfig={{
    ...
    dotSize: 20,
  }}
  buttonsConfig={{
    ...
    // useBottomButtons: true,
  }}
/>

Demo

DefaultuseBottomButtons
DemoDemo3

Customizable

You can use your own component

<Carousel
  data={[
    {
      key: '1',
      title: 'Cool package',
      description: 'This is a cool package',
      image: require('./..'),
      data: {
        ... // you can add any data here
      }
    },
  ]}
  buttonsConfig={{
    disabled: true,
  }}
  renderItem={({ item, index }, goToSlide) => (
    <View style={styles.content}>
      <Image
        source={item.image}
        style={styles.image}
      />
      <Text>{item.title}</Text>
      <Text>{item.description}</Text>
      <View style={styles.buttonsContainer}>
        <Pressable
          style={styles.button}
          onPress={() => goToSlide(index - 1)}
        >
          <Text>Previous</Text>
        </Pressable>
        <Pressable
          style={[styles.button, { marginLeft: 10 }]}
          onPress={() => goToSlide(index + 1)}
        >
          <Text>Next</Text>
        </Pressable>
      </View>
    </View>
  )}
/>

will result in:

Demo2

Customizable buttons

You can use your own component

<Carousel
  data={[...]}
  buttonsConfig={{
    next: {
      renderButton: (index, onChangeSlider) => (
        <Pressable onPress={() => onChangeSlider(index + 1)}>
          <Image source={arrowIcon} />
        </Pressable>
      )
    },
    prev: {
      disabled: true,
    },
    done: {
      renderButton: (index, onChangeSlider) => (
        <Pressable onPress={() => {...}}>
          <Image source={checkIcon} />
        </Pressable>
      )
    },
  }}
/>

will result in:

DemoButtons

Banners

you can also use this lib to create cool banners, look the example code here

Demo Banner

Props

NameTypeDefaultDescription
dataobjectNone, requiredArray of pages in carousel
paginationConfigobjectNonePagination configurations (see table below)
renderItemfunctionNoneYou can create your own component to be rendered on the page
onPressSkipfunctionNoneCalled when user press 'skip' (null = hide skip button)
onFinishfunctionNoneCalled when user press 'Done' on last slider
buttonsConfigobjectNoneButtons configuration (see table below)

paginationConfig

NameTypeDefaultDescription
dotSizenumber15Size of pagination dots
bottomOffsetnumber50pagination distance from bottom
animatedbooleantrueallows disabling dots animation
disabledbooleanfalsehide the pagination
dotIncreaseSizenumber1.4size the dot will grow when it is on a page (hint: use 1 if you don't want the dot to grow)
colorstring#ffffff80Default dot color
activeColorstring#fffActive dot color
dotSpacingnumber12spacing between pagination dots
activeDotStyleViewStyleNonestyles for the dot indicating the current page

buttonsConfig

NameTypeDefaultDescription
disabledbooleanfalseHide the buttons
next{label?: string; textStyle?: TextStyle; buttonStyle?: ViewStyle; renderButton?: ( currentIndex: number, goToSlide: (index: number) => void ) => JSX.Element; // render your own button }NoneNext button configurations
prevsame as the line aboveNonePrevious button configurations
skipsame as the line aboveNoneSkip button configurations
donesame as the line aboveNoneLast slide button configurations
useBottomButtonsbooleanfalseShow buttons below pagination

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT