Coder Social home page Coder Social logo

felire / react-native-animated-dots-carousel Goto Github PK

View Code? Open in Web Editor NEW
52.0 2.0 11.0 635 KB

Package to configure your dots pagination carousel just like Instagram does

License: MIT License

JavaScript 4.97% Java 21.86% TypeScript 49.33% C 0.36% Objective-C 7.73% Swift 0.64% Ruby 15.11%
react native react-native animated dots carousel instagram animation interpolation react-native-animated-dots

react-native-animated-dots-carousel's Introduction

react-native-animated-dots-carousel

versión npm Download npm MIT License

Table of Contents

About The Project

Package to configure you dots pagination carousel just like Instagram does. With this package you could make whatever configuration you might need on your projects.

Examples

Example

Example

Example

Getting Started

Installation

Installation can be done through npm or yarn:

npm i react-native-animated-dots-carousel --save
yarn add react-native-animated-dots-carousel

Usage

import * as React from 'react';
import { StyleSheet, View, Text, TouchableOpacity } from 'react-native';
import AnimatedDotsCarousel from 'react-native-animated-dots-carousel';

const LENGTH = 10;
export default function App() {
  const [index, setIndex] = React.useState<number>(0);

  const increaseIndex = () => {
    setIndex(Math.min(index + 1, LENGTH - 1));
  };
  const decreaseIndex = () => {
    setIndex(Math.max(index - 1, 0));
  };

  return (
    <View style={styles.container}>
      <TouchableOpacity
        style={{ borderWidth: 1, marginTop: 20, backgroundColor: 'white' }}
        onPress={increaseIndex}
      >
        <Text>Increase</Text>
      </TouchableOpacity>
      <TouchableOpacity
        style={{ borderWidth: 1, marginTop: 20, backgroundColor: 'white' }}
        onPress={decreaseIndex}
      >
        <Text>Decrease</Text>
      </TouchableOpacity>

      <AnimatedDotsCarousel
        length={LENGTH}
        currentIndex={index}
        maxIndicators={4}
        interpolateOpacityAndColor={true}
        activeIndicatorConfig={{
          color: 'red',
          margin: 3,
          opacity: 1,
          size: 8,
        }}
        inactiveIndicatorConfig={{
          color: 'white',
          margin: 3,
          opacity: 0.5,
          size: 8,
        }}
        decreasingDots={[
          {
            config: { color: 'white', margin: 3, opacity: 0.5, size: 6 },
            quantity: 1,
          },
          {
            config: { color: 'white', margin: 3, opacity: 0.5, size: 4 },
            quantity: 1,
          },
        ]}
      />
    </View>
  );
}

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

Api Reference

DotConfig Interface

export interface DotConfig {
  size: number;
  opacity: number;
  color: string;
  margin: number;
  borderWidth?: number;
  borderColor?: string;
}

DecreasingDot Interface

export interface DecreasingDot {
  quantity: number;
  config: DotConfig;
}

Props

Prop Type Required(Default Value) Description
length number required Length of the list you want to associate with the carousel dots
currentIndex number required Current index of the list.
maxIndicators number required This number represents how many indicators you want to show, without decreasing size. Counting inactive indicators and the active indicator
activeIndicatorConfig DotConfig required This is an object with the configuration of the active indicator
inactiveIndicatorConfig DotConfig required This is an object with the configuration of the inactive indicator
decreasingDots DecreasingDot[] required This is a list where you have to define the quantiy per element and the dot config. The quantity represents how many dots with this config you want per side (simetrically). The size of this elements should be decreasing size if you want this to look nice.
verticalOrientation boolean false If you want this oriented vertically or horizontally. Default is horizontally
interpolateOpacityAndColor boolean true Default is true. With this setted to true you will be able to see an animation everytime the activeDot change.

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Project Link: https://github.com/felire/react-native-animated-dots-carousel

react-native-animated-dots-carousel's People

Contributors

chsdwn avatar felire avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-animated-dots-carousel's Issues

decreasingDots does not work correctly with dynamic data

I'm using react-native-animated-dots-carousel and set the config:
length: 8; maxIndicator: 5;
when I set currentIndex = 0 for render for the first time the decreasingDots worked correctly.
1

But if I update the length = 7; currentIndex = 6, it will render wrong
2

expectation:
3

maxIndicators Property Prevents Rendering in "react-native-animated-dots-carousel"

Hello,

I am currently utilizing the "react-native-animated-dots-carousel" in my React Native project and have stumbled upon an issue with the maxIndicators property.

Description of the Issue:

When the number of items in the data array exceeds the value set in the maxIndicators property, the dots fail to render. Conversely, when the maxIndicators property is set to a value greater than the number of items, it functions correctly.
Steps to Reproduce:

  1. Set the maxIndicators property to 3.
  2. Include 4 items in the data array.
  3. Observe that the dots does not render.

Expected Behavior:

I anticipated that setting a maxIndicators value less than the number of items would still allow the dots to function properly, with the additional items being accommodated.

Actual Behavior:

The dots fails to render when the maxIndicators value is less than the number of items in the data array.
Additional Information:

I find this behavior strange because, based on the examples provided in your GitHub repository, it seems like this functionality should work correctly. It appears that in your examples, the dots renders fine even when the maxIndicators is less than the number of items.
Environment:

  1. React Native version: 0.71.1
  2. OS : iOS

I would appreciate any guidance or updates that can address this issue. Thank you for your time and assistance.

Dots centered

Hey @felire , how i can always center dots, maybe you can help me with it?
Initially they not center:
image
I need something like that:
image

Add duration as prop

I think this is a pretty simple change, but could you add the animation duration to go from one dot to the next as a prop? In the code it looks like it's 300ms, and from my experience with it, it feels a little slow and 200ms would probably make it feel more like instagram and other apps.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.