All Projects → xiaody → React Touch Carousel

xiaody / React Touch Carousel

Licence: mit
Ultra-customizable carousel framework for React.JS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Touch Carousel

React Responsive Carousel
React.js Responsive Carousel (with Swipe)
Stars: ✭ 1,962 (+1141.77%)
Mutual labels:  swipe, react-component, carousel
Vue Picture Swipe
🖼 Vue Picture Swipe Gallery (a gallery of image with thumbnails, lazy-load and swipe) backed by photoswipe
Stars: ✭ 322 (+103.8%)
Mutual labels:  swipe, carousel
React Items Carousel
Items Carousel Built with react-motion and styled-components
Stars: ✭ 150 (-5.06%)
Mutual labels:  react-component, carousel
Swiper
Most modern mobile touch slider with hardware accelerated transitions
Stars: ✭ 29,519 (+18582.91%)
Mutual labels:  swipe, carousel
react-carousel-minimal
React.js Responsive Minimal Carousel
Stars: ✭ 76 (-51.9%)
Mutual labels:  react-component, carousel
react-gallery-carousel
Mobile-friendly gallery carousel 🎠 with server side rendering, lazy loading, fullscreen, thumbnails, touch, mouse emulation, RTL, keyboard navigation and customisations.
Stars: ✭ 178 (+12.66%)
Mutual labels:  carousel, swipe
Discretescrollview
A scrollable list of items that centers the current element and provides easy-to-use APIs for cool item animations.
Stars: ✭ 5,533 (+3401.9%)
Mutual labels:  swipe, carousel
React Native Swiper Flatlist
👆 Swiper component implemented with FlatList using Hooks & Typescript + strict automation tests with Detox
Stars: ✭ 217 (+37.34%)
Mutual labels:  swipe, carousel
React Grid Carousel
React responsive carousel component w/ grid layout
Stars: ✭ 29 (-81.65%)
Mutual labels:  react-component, carousel
React Splide
The Splide component for React.
Stars: ✭ 32 (-79.75%)
Mutual labels:  react-component, carousel
React Soft Slider
Simple, fast and impartial slider
Stars: ✭ 54 (-65.82%)
Mutual labels:  swipe, carousel
skeleton-carousel
Carousel component. Horizontal and vertical swipe navigation
Stars: ✭ 31 (-80.38%)
Mutual labels:  carousel, swipe
react-native-viewpager-carousel
a flexible viewpager library with carousel functionality
Stars: ✭ 39 (-75.32%)
Mutual labels:  carousel, swipe
React Native Card Stack Swiper
Tinder like react-native card stack swiper
Stars: ✭ 315 (+99.37%)
Mutual labels:  swipe, react-component
vue-product-carousel
Simple product carousel with hot image replacement, Zoom and Swipe mode
Stars: ✭ 37 (-76.58%)
Mutual labels:  carousel, swipe
React Alice Carousel
React responsive component for building content galleries, content rotators and any React carousels
Stars: ✭ 419 (+165.19%)
Mutual labels:  react-component, carousel
React Awesome Slider
React content transition slider. Awesome Slider is a 60fps, light weight, performant component that renders an animated set of production ready UI general purpose sliders with fullpage transition support for NextJS and GatsbyJS. 🖥️ 📱
Stars: ✭ 2,343 (+1382.91%)
Mutual labels:  react-component, carousel
Slider
Touch swipe image slider/slideshow/gallery/carousel/banner mobile responsive bootstrap
Stars: ✭ 2,046 (+1194.94%)
Mutual labels:  swipe, carousel
Splide
Splide is a lightweight, powerful and flexible slider and carousel, written in pure JavaScript without any dependencies.
Stars: ✭ 786 (+397.47%)
Mutual labels:  swipe, carousel
React Easy Swipe
Easy handler for common swipe operations
Stars: ✭ 85 (-46.2%)
Mutual labels:  swipe, react-component

Build Status npm version dependencies Status js-standard-style

react-touch-carousel

Micro carousel framework for React.JS https://xiaody.github.io/react-touch-carousel/docs/

Yes, there are a few carousel libraries out there. Most of them are mature and easy to use for common usage, but none of them are convenient for the highly customized fancy UX that your team's cool designer wants.

react-touch-carousel does it in a different way. Instead of accepting some static DOM nodes and providing a thousand options, it does an inversion of control and lets you decide what content inside carousel are rendered and how they are styled, totally and dynamically.

Installation

To install the stable version:

npm install --save react-touch-carousel

Usage

import TouchCarousel from 'react-touch-carousel'

const listOfData = [
  // your data array here
]

function CarouselContainer (props) {
  // render the carousel structure
}

function renderCard (index, modIndex, cursor) {
  const item = listOfData[modIndex]
  // render the item
}


<TouchCarousel
  component={CarouselContainer}
  cardCount={listOfData.length}
  cardSize={375}
  renderCard={renderCard}
  loop
  autoplay={3000}
/>

The CarouselContainer() and renderCard() are where all the magic happens, which shall be directed by you. See some detailed examples.

Options

props.component {Component}

Your container component of the carousel.

react-touch-carousel will pass it's touch listeners, dragging/active state, current position cursor to this component.

It is actually called like this:

<Component
  cursor={usedCursor}
  carouselState={carouselState}
  onTouchStart={onTouchStart}
  onTouchMove={onTouchMove}
  onTouchEnd={onTouchEnd}
  onTouchCancel={onTouchCancel}
>
  {allYourRenderedCards}
</Component>

props.renderCard(index, modIndex, cursor, carouselState) {Function}

The card renderer.

All rendered cards joined as an array will be passed to props.component as it's children.

props.cardCount {Number}

The count of your cards, not including the padded ones.

props.cardPadCount {Number}

The count of padded cards, necessary for looping.

Ignored if loop is false.

props.cardSize {Number}

The width (or height if vertical is true) in pixels of a card.

props.vertical {Boolean}

Listen to vertical touch moves instead of horizontal ones. Default false.

props.loop {Boolean}

Tail to head, head to tail. Default true.

props.autoplay {Number}

Interval in milliseconds, 0 as disabled. Default 0.

props.defaultCursor {Number}

The cursor value for initial render.

Notice the sign of the number, normally it should be negative or zero(default).

props.onRest(index, modIndex, cursor, carouselState) {Function}

Callback when the carousel is rested at a card.

props.onDragStart/onDragEnd/onDragCancel

Add some listeners if you need.

props.ignoreCrossMove {Number|Boolean}

If deltCrossAxis * ignoreCrossMove > deltMainAxis, carousel would ignore the dragging.

true as 1 and false as 0. Default true.

Concepts

Cursor

A cursor indicates the transition position of the carousel.

When the user swipes right, the number gets bigger. When the user swipes left, the number get smaller.

There are three steps to calculating the cursor's final value: specified, computed, used.

In most cases you just use the used cursor value to render your carousel content.

CarouselState

A carouselState is always passed to your component and renderCard.

It contains:

{
  cursor, // the specified cursor
  active, // is user interacting with the component, no matter dragging or pressing or clicking?
  dragging, // is user dragging the component?
  springing, // has user dragged and released the component, and the component is transitioning to the specified cursor?
  moding // is the cursor moding?
}

Mod

This happens if you enable loop. We keep the cursor in a valid range by "moding" it.

Advanced options

There are some advanced options, but normally you don't need to touch them.

Methods

go(targetCursor)

Transition to a position.

next()

Transition to next card.

prev()

Transition to previous card.

modAs(targetCursor)

Hard jump to a position.

Mouse support

We provide an HOC for very basic mouse support. Internally it simulates touch events with the mouse events.

import touchWithMouseHOC from 'react-touch-carousel/lib/touchWithMouseHOC'

const Container = touchWithMouseHOC(CarouselContainer)

<TouchCarousel
  component={Container}
/>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].