Simple carousel component.Fully implemented using Reanimated v2.Support to IOS and ANDROID.

Overview

react-native-reanimated-carousel

platforms npm npm github issues github closed issues


Simple carousel component!

Infinitely scrolling very smooth!

Fully implemented using Reanimated 2!

The common RN infinite scroll component. It's common to get stuck on a fast slide. Wait for the next element to appear. This component will not have similar problems. That's why this library was created.

🎉 🎉 🎉

At present, it only meets the needs of my work. Welcome to raise PR/ISSUES.Try it with snack


Installation

Open a Terminal in the project root and run:

yarn add react-native-reanimated-carousel

Or if you use npm:

npm install react-native-reanimated-carousel

Now we need to install react-native-gesture-handler and react-native-reanimated(>=2.0.0).

EXPO

If use EXPO managed workflow please ensure that the version is greater than 41.Because the old version not support Reanimated(v2)

Usage

width={width} data={[{ color: "red" }, { color: "purple" }, { color: "yellow" }]} renderItem={({ color }) => { return ( ); }} />; ">
import Carousel from "react-native-reanimated-carousel";

// ...

<Carousel<{ color: string }>
  width={width}
  data={[{ color: "red" }, { color: "purple" }, { color: "yellow" }]}
  renderItem={({ color }) => {
    return (
      <View
        style={{
          backgroundColor: color,
          justifyContent: "center",
          flex: 1,
        }}
      />
    );
  }}
/>;

Props

name required default types description
data true T[] Carousel items data set
width true number Specified carousel container width
renderItem true (data: T, index: number) => React.ReactNode Render carousel item
autoPlay false false boolean Auto play
autoPlayReverse false false boolean Auto play reverse playback
autoPlayInterval false 1000 autoPlayInterval Auto play playback interval
mode false defalut 'default'|'parallax' Carousel Animated transitions
loop false true boolean Carousel loop playback
parallaxScrollingOffset false 100 number When use 'default' Layout props,this prop can be control prev/next item offset
parallaxScrollingScale false 0.8 number When use 'default' Layout props,this prop can be control prev/next item scale
style false {} ViewStyle Carousel container style
height false '100%' undefined | string | number Specified carousel container height
timingConfig false {duration: 250} Animated.WithTimingConfig Timing config of translation animated
onSnapToItem false (index: number) => void Callback fired when navigating to an item

Ref

name types description
prev ()=>void Play the last one
loop ()=>void Play the next one
goToIndex (index: number, animated?: boolean) => void Go to index
getCurrentIndex ()=>number Get current item index

Example

yarn example -- ios
yarn example -- android

Contributing

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

License

MIT

Comments
  • Reanimated global.__reanimatedWorkletInit is not a function

    Reanimated global.__reanimatedWorkletInit is not a function

    Describe the bug

    When i try use library with Expo, the follow message shows

    TypeError: global.__reanimatedWorkletInit is not a function. (In 'global.__reanimatedWorkletInit(_f)', 'global.__reanimatedWorkletInit' is undefined)

    If i put the code

    global.__reanimatedWorkletInit = () => {};

    on '.../lib/commonjs/utils/dealWithAnimation.js works correctly

    To Reproduce Steps to reproduce the behavior:

    1. Install library and try use
    2. See error

    Screenshots image

    Versions:

    • expo: ~45.0.0
    • react: v17.0.2
    • react-native: v0.68.1
    • react-native-reanimated: v^2.8.0
    • react-native-reanimated-carousel: v^2.3.10
    • react-native-gesture-handler: v~2.2.0

    Smartphone:

    • Device: iPhoneXR
    • OS: iOS 15.4
    bug help wanted waiting 
    opened by jhorranisbr 33
  • Crash when updating to react-native-reanimated 2.7.0 ( undefined is not a function )

    Crash when updating to react-native-reanimated 2.7.0 ( undefined is not a function )

    Describe the bug Updating react-native-reanimated to version 2.7.0 seems to be breaking the library, causing crashes on iOS and Android

    To Reproduce Steps to reproduce the behavior:

    1. Update react-native-reanimated to version 2.7.0

    Expected behavior No crashes

    Screenshots

    Versions (please complete the following information):

    • react: v17.0.2
    • react-native: v0.68.0
    • react-native-reanimated: v2.3.7
    • react-native-reanimated-carousel: v2.3.4
    • react-native-gesture-handler: v2.3.2

    Smartphone (please complete the following information):

    • Device: Pixel 4a
    • OS: Android 12
    bug help wanted P1 waiting 
    opened by 1987cr 31
  • Lazy loading

    Lazy loading

    Hi,

    Thank you for this repo.

    I wanted to ask whether you had plans to implement lazy loading or recycling of items?

    I really liked the component, but I am planning to have +200 scrollable cards in the carousel, and right now its not performing very well, because all items are rendered in memory

    enhancement 
    opened by emilstepanian 23
  • Suggestion: Add momentum to slider

    Suggestion: Add momentum to slider

    Hello sir @dohooo, is it possible to add a flag that controls the momentum when we slide and it'll snap when the momentum slows down.

    This link is an example of what i meant. The stronger you swipe, the further it slides.

    Will this feature be possible? It may affect the logic of the infinity slider is what I thought. It will be a great improvement if this was possible.

    bug 
    opened by frostwilly 21
  • Is it really performant and smooth?

    Is it really performant and smooth?

    I wanted to give this a try to upgrade from snap-carousel, but I am not getting a performant and smooth experience as written in the documentation. I tried it on iphone 8 plus, and it felt buggy and lots of frames dropped. on Samsung note 4, it was so bad and laggy. Here is a video from my iphone

    https://user-images.githubusercontent.com/80689446/155302787-2e37b095-66f4-4299-9386-09b6f55c7e04.mp4

    opened by itsramiel 18
  • onSnapToItem gives floating index

    onSnapToItem gives floating index

    https://user-images.githubusercontent.com/27767989/138818412-a3a22b6f-0e2b-4588-b92b-305c27f90eb9.mp4

    Hello, There's a bug where onSnapToItem gives floating numbered index when you changed index a few times.

    bug 
    opened by frostwilly 18
  • error on ios with version 1.0.10

    error on ios with version 1.0.10

    Getting this error on ios

    Simulator Screen Shot - iPhone 13 - 2021-12-20 at 09 43 24

    Version: "react-native": "0.66.4", "react-native-reanimated-carousel": "1.0.10", "react-native-reanimated": "2.3.1", "react-native-gesture-handler": "2.1.0",

    opened by danferd33 13
  • RTL support

    RTL support

    Thanks for the amazing performance and effort in creating this package. I saw the previous issue but it needs to reopen again in react native on change layout direction to RTL, the component should start and be animated from right to left also by default react-native inverts the dimensions from right to left for most of the styles and this should be considered if the user is using RTL Device This is a 2 recorded videos for the basic "parallax" mode on LTR and RTL on IOS

    • On LTR Working great

    https://user-images.githubusercontent.com/37451755/147994123-1578d992-8dba-4a03-ad33-2ab4e9513760.mov

    • On RTL the issue appears

    https://user-images.githubusercontent.com/37451755/147994251-c590b0f0-8e02-47d2-baed-a1f36da99ca0.mov

    you can reproduce the issue with the basic example by converting to RTL, it think I18nManager.forceRTL(false); and then restarting the app is enough

    enhancement 
    opened by Mohamed-kassim 12
  • When using Pressable inside a horizontal carousel, the scroll is registered as a tap

    When using Pressable inside a horizontal carousel, the scroll is registered as a tap

        "react-native-reanimated": "2.2.4",
        "react-native-reanimated-carousel": "^2.3.2",
        "react-native-gesture-handler": "^2.3.2",
    

    I'm using the Carousel in its default mode horizontally scrolling. When the items rendered use Pressable and the user scrolls horizontally, the scroll happens but a press is also registered when lifting the finger. If I swap Pressable for a Gesture Handler Touchable, the error disappears.

    Please advise, thank you.

    bug 
    opened by diego-paired 10
  • Cannot Scroll down/up when the Carousel is in a ScrollView (Must Click Outside the carousel)

    Cannot Scroll down/up when the Carousel is in a ScrollView (Must Click Outside the carousel)

    I have a simple image carousel in a scroll view component.

    When I want to scroll down past the Carousel the screen will only allow me to animate the carousel.

    All movements down/up on a ScrollView will not scroll the page if your finger is on the carousel.

    opened by tylerkrett 10
  • 手势操作没反应

    手势操作没反应

    https://user-images.githubusercontent.com/8955903/140000222-e307f8cd-80f6-4de1-8cf7-df2e3cb6977b.mp4

    import React, {PureComponent} from 'react';
    import {
      View,
      Text,
      StyleSheet,
      TouchableOpacity,
      ImageSourcePropType,
      Dimensions,
      Image,
    } from 'react-native';
    import Carousel, {ICarouselInstance} from 'react-native-reanimated-carousel';
    
    const {width} = Dimensions.get('window');
    const data: ImageSourcePropType[] = [
      require('./assets/album-art-1.jpg'),
      require('./assets/album-art-2.jpg'),
      require('./assets/album-art-3.jpg'),
    ];
    
    export default function App() {
      const r = React.useRef<ICarouselInstance | null>(null);
      return (
        <View
          style={{
            flex: 1,
            alignItems: 'center',
            backgroundColor: 'black',
            paddingTop: 100,
          }}>
          <View style={{height: 300}}>
            <Carousel<ImageSourcePropType>
              style={{width: width, backgroundColor: 'red'}}
              ref={r}
              width={width}
              data={data}
              parallaxScrollingScale={0.8}
              renderItem={source => (
                <View style={{flex: 1}}>
                  <Image source={source} style={{width: '100%', height: '100%'}} />
                </View>
              )}
            />
          </View>
          <View style={{height: 300}}>
            <Carousel<ImageSourcePropType>
              ref={r}
              mode="parallax"
              width={width}
              data={data}
              parallaxScrollingScale={0.8}
              renderItem={source => (
                <View style={{flex: 1}}>
                  <Image source={source} style={{width: '100%', height: '100%'}} />
                </View>
              )}
            />
          </View>
        </View>
      );
    }
    

    package.json

    {
      "name": "tabview",
      "version": "0.0.1",
      "private": true,
      "scripts": {
        "android": "react-native run-android",
        "ios": "react-native run-ios",
        "start": "react-native start",
        "test": "jest",
        "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
      },
      "dependencies": {
        "react": "17.0.2",
        "react-native": "0.65.1",
        "react-native-gesture-handler": "^1.10.3",
        "react-native-reanimated": "2.2.1",
        "react-native-reanimated-carousel": "^1.0.1"
      },
      "devDependencies": {
        "@babel/core": "^7.12.9",
        "@babel/runtime": "^7.12.5",
        "@react-native-community/eslint-config": "^2.0.0",
        "babel-jest": "^26.6.3",
        "eslint": "7.14.0",
        "jest": "^26.6.3",
        "metro-react-native-babel-preset": "^0.66.0",
        "react-native-codegen": "^0.0.7",
        "react-test-renderer": "17.0.2",
        "typescript": "^3.8.3"
      },
      "jest": {
        "preset": "react-native",
        "moduleFileExtensions": [
          "ts",
          "tsx",
          "js",
          "jsx",
          "json",
          "node"
        ]
      }
    }
    
    opened by star-heng 10
  • [FEATURE REQUEST] Add simple pagination dot components.

    [FEATURE REQUEST] Add simple pagination dot components.

    The pagination dot styles are very various, So I'll implement a simple one, Just like image

    Features

    • Change styles.
      • active color
      • inactive color
    • Control the progress via reanimated values.

    Hmmm, Any other features you want?

    enhancement 
    opened by dohooo 2
  • scrollTo has incorrect type and is possibly also not working

    scrollTo has incorrect type and is possibly also not working

    Describe the bug ICarouselInstance.scrollTo has a TS declaration which doesn't seem to match the documentation. According to TypeScript, scrollTo accepts a TCarouselActionOptions, but according to the documentation, it expects a number:

        /**
         * Use value to scroll to a position where relative to the current position,
         * scrollTo(-2) is equivalent to prev(2), scrollTo(2) is equivalent to next(2)
         */
        scrollTo: (opts?: TCarouselActionOptions) => void;
    

    I've tried using a number, and that didn't work as expected. I've also tried passing an object with an index, { index: 1 } (or equivalent). But neither works as expected.

    Expected behavior I expect scrollTo to take a number as parameter as described in the JS comment.

    Versions (please complete the following information):

    • react: v17.0.2
    • react-native: v0.68.1
    • react-native-reanimated: v2.10.0
    • react-native-reanimated-carousel: v3.0.4
    • react-native-gesture-handler: v2.6.0
    bug 
    opened by AdamGerthel 1
  • Cannot override the carousel's overflow style

    Cannot override the carousel's overflow style

    Describe the bug I want to see the carousel items that are outside of the carousel view. I've added overflow: visible to the carousel style, but it seems to have no effect.

    To Reproduce See example repository here: https://github.com/AdamGerthel/reanimated-carousel-bug

    Expected behavior I expect to be able to see the slides even though they are outside the carousel, since I'm overriding the default overflow: hidden value.

    Screenshots Simulator Screen Shot - iPhone 13 - 2022-09-08 at 10 05 16

    Versions (please complete the following information): See https://github.com/AdamGerthel/reanimated-carousel-bug/blob/master/package.json

    Smartphone (please complete the following information): Android + iOS

    bug 
    opened by AdamGerthel 0
  • Laggy performance with large data object (1000 items)

    Laggy performance with large data object (1000 items)

    Describe the bug Finding that performance on an Android is very slow for parallax Carousel with 1000 items. Is there some config that needs to be set to handle a large data source, or is this expected? Attaching an example below (mostly modified https://github.com/dohooo/react-native-reanimated-carousel/blob/66b2d23b78d09fc15f300ba43e31ca94a13be689/exampleExpo/src/complex/index.tsx by stripping out stuff). Saw there was a similar issue raised but I'm not sure this provided a solution, as I've tried setting windowSize=3 and still seeing significant lag https://github.com/dohooo/react-native-reanimated-carousel/issues/207

    To Reproduce

    import * as React from 'react';
    import { ScrollView, Text, View, Dimensions } from 'react-native';
    import Carousel from 'react-native-reanimated-carousel';
    import SButton from '@components/SButton';
    
    const PAGE_WIDTH = Dimensions.get('window').width;
    
    function Index() {
        const r = React.useRef(null);
    
        return (
            <View
                style={{
                    flex: 1,
                    backgroundColor: '#f1f1f1',
                    paddingTop: 100,
                }}
            >
                <View style={{ width: PAGE_WIDTH, height: 240 }}>
                    <Carousel
                        defaultIndex={0}
                        ref={r}
                        width={PAGE_WIDTH}
                        data={[...new Array(1000).keys()]}
                        mode="parallax"
                        windowSize={3}
                        renderItem={({ index }) => (
                            <View
                                key={index}
                                style={{
                                    flex: 1,
                                    justifyContent: 'center',
                                    alignItems: 'center',
                                    backgroundColor: '#ff7a45',
                                    padding: 16,
                                }}
                            >
                                <Text style={{ color: 'white', fontSize: 30 }}>
                                    {`index:${index}`}
                                </Text>
                            </View>
                        )}
                    />
                </View>
                <View
                    style={{
                        marginTop: 24,
                        flexDirection: 'row',
                        justifyContent: 'space-evenly',
                    }}
                >
                    <SButton onPress={() => r.current?.prev()}>{'Prev'}</SButton>
                    <SButton onPress={() => r.current?.next()}>{'Next'}</SButton>
                </View>
            </View>
        );
    }
    
    export default Index;
    

    Expected behavior Unfortunately all the examples I've seen have a small number of objects in data, but I expected scrolling behavior to be as smooth for 1000 items as 5 items.

    Versions (please complete the following information):

    • "react": "18.0.0"
    • "react-native": "0.69.5"
    • "react-native-reanimated": "~2.9.1"
    • "react-native-reanimated-carousel": "^3.0.4"
    • "react-native-gesture-handler": "~2.5.0"
    • "expo": "^46.0.0"

    Smartphone (please complete the following information):

    • Device: Pixel 6
    • OS: Android
    • Version 13
    bug 
    opened by michaelshum 0
  • Forward ref for explicit scrolling/pagination

    Forward ref for explicit scrolling/pagination

    A common case is to allow explicit scroll/pagination by forwarding ref and having imperative handles.

    Is your feature request related to a problem? Please describe. After spending an hour installing and customizing animation, I realized I can't control the scrolling through ref!

    Describe the solution you'd like Up to you, maybe forward a ref with a scrollTo method?

    Describe alternatives you've considered react-native-snap-carousel has that enabled.

    Additional context N/A

    enhancement 
    opened by adamsolomon1986 0
Releases(v3.0.5)
Owner
赵東澔
FE developer. 🦸‍♂️
赵東澔
A android like toast for android and ios, android use native toast, ios use UIView+Toast

React Native Toast (remobile) A android like toast for react-native support for ios and android Installation npm install @remobile/react-native-toast

YunJiang.Fang 346 Jul 30, 2022
A react native modals library. Swipeable. Highly customizable. Support multi modals & Support custom animation. For IOS & Android.

React Native Modals React Native Modals Library for iOS & Android. How to thank me ? Just click on ⭐️ button ?? Try it with Exponent BREAKING CHANGE A

Jack Lam 2.1k Sep 22, 2022
Swiper/carousel component for React Native featuring previews, multiple layouts, parallax images, performant handling of huge numbers of items, and more. Compatible with Android & iOS.

react-native-snap-carousel ✨ Some great news for you, fellow plugin user! ?? Head over there now to learn more about all the goodness that's coming yo

Meliorence 9.7k Oct 1, 2022
Simple screens' swiper library with scrollable or static tab navigation. Fully supported on iOS and Android.

react-native-screens-swiper Simple screens' swiper library with scrollable or static tab navigation. Fully supported on iOS and Android. Scrollable Pi

Mutovkin Yurii 16 Mar 28, 2022
🌲☀️ Customizable, lightweight React Native carousel component with accessibility support.

Customizable, lightweight React Native carousel component with accessibility support. Pinar is a lightweight and customizable React Native carousel co

Krister Kari 216 Sep 22, 2022
iOS/Android image picker with support for camera, video, configurable compression, multiple images and cropping

react-native-image-crop-picker iOS/Android image picker with support for camera, video, configurable compression, multiple images and cropping Result

Ivan Pusic 5.6k Sep 23, 2022
React Native ActionSheet for Android & IOS (IOS is using ActionSheetIOS)

React Native ActionSheet This package will help you to using ActionSheetIOS(IOS) and BottomSheetDialog(Android). Usage of this package same as for IOS

Talut TASGIRAN 26 May 23, 2021
💃🏻 Display Animated WebP images in React Native the hacky way, support for Android & iOS both

???? react-native-animated-webp Display and control Animated WebP images in React Native the hacky way ?? Installation ?? PeerDependencies first This

Junho Yeo 12 Jul 1, 2022
Image carousel with support for fullscreen mode with swiping and pinch-to-zoom.

react-native-image-carousel Image carousel with support for heading, captions, fullscreen mode, image swiping and pinch-to-zoom in fullscreen mode. Su

Anvilabs 212 Jun 10, 2022
A react native module to show toast like android, it works on iOS and Android.

react-native-easy-toast A react native module to show toast like android, it works on iOS and Android. Content Installation Demo Getting started API C

Devio.org 1.1k Sep 28, 2022
A performant bottom modal that works using React Native Reanimated 2

react-native-lightning-modal A fast bottom modal that works with React Native Reanimated 2! Prerequisites This module needs React Native Reanimated 2

Burak Güner 22 Sep 25, 2022
A FAB button component for Android and iOS, customizable, simple and as per material design specs.

react-native-fab A FAB button component for Android and iOS, customizable, simple and as per material design specs. See Google Material Design for mor

Swapnil Devesh 74 Jun 22, 2022
🏀 Native bounceable effect for any React Native component. Built with Reanimated 2. Compatible with Expo.

Quick start > yarn add rn-bounceable Make sure you have react-native-reanimated and react-native-gesture-handler installed in your project. Usage impo

Batyr 30 Sep 6, 2022
Animated collapsible component for React Native, good for accordions (reanimated v2), toggles 🧬

React Native Accordion (Reanimated 2) On the basis of react-native-maps I provide API for drawing polygons. Made with ❤️ by developer for developers T

Aliaksei Petrusevich 51 Sep 10, 2022
Animated ToDo app built with React Native and Reanimated v2

Smoothly Animated ToDo App built with React Native Try the demo on The animated checkbox component has been published as an NPM module react-native-ch

Takuya Matsuyama 333 Sep 20, 2022
BottomSheet created with reanimated and react-native-redash

BottomSheet with react-native-reanimated, react-native-gesture-handler and react-native-redash This library provide multiple components but most impor

null 3 Mar 22, 2022
Animated Todo application created with React Native, Typescript, Native Base and Reanimated v2

Animated Todo Application Created with ❤️ with [] Credits Inspired from the developer Takuya Matsuyama with his wonderful tutorial : Stack React Nativ

Maxime Beneteau 1 Dec 29, 2021
react-native-wheel-picker-android ★186 - Simple and flexible React native wheel picker for Android, including DatePicker and TimePicker.

React native wheel picker V2 A simple Wheel Picker for Android (For IOs is using Picker from react-native) Example You can clone the repo and run exam

Kalon.Tech 330 Sep 22, 2022
The Beautiful Image component that supports fadeIn animation and shows placeholderSource if the main source can't be loaded. More will be implemented.

react-native-beautiful-image The Image component that supports fadeIn animation and shows placeholderSource if the main source can't be loaded. More w

Hau Vo 59 Feb 26, 2022