0.1.9 • Published 10 months ago

react-native-flatlist-withindicator v0.1.9

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

react-native-flatlist-withindicator

npm npm

Description

react-native-flatlist-withindicator is a package that extends the functionality of the original React Native FlatList component. It provides customizable indicators to display the current active item in a horizontal list.

Features

  • Customize indicators to show the current active item
  • Enhance user experience with visual indicators
  • Built on top of the original React Native FlatList component

Installation

To install the package, run the following command:

official documentation on how to Installation - React Native Reanimated

npm install react-native-flatlist-withindicator

or

yarn add react-native-flatlist-withindicator

Usage

import * as React from 'react';
import { StyleSheet, View, Text, ScrollView } from 'react-native';
import {
  FlatListWithCircularIndicator,
  FlatListWithRectangleIndicator,
} from 'react-native-flatlist-withindicator';

const marginValue = 10;
const cardWidth = 200;

const Card = ({ item }) => {
  return (
    <View
      style={[
        { marginRight: marginValue, width: cardWidth },
        styles.cardContainer,
      ]}
    >
      <Text style={styles.cardText}>{item}</Text>
    </View>
  );
};

export default function App() {
  const data = [1, 2, 3];
  return (
    <ScrollView style={styles.container}>
      <View style={styles.flatListContainer}>
        <FlatListWithRectangleIndicator
          renderItem={({ item }) => <Card item={item} />}
          data={data}
          cardWidthPlusMarginValue={cardWidth + marginValue}
          keyExtractor={(_, index) => index.toString()}
        />
      </View>
      <View style={styles.flatListContainer}>
        <FlatListWithRectangleIndicator
          renderItem={({ item }) => <Card item={item} />}
          data={data}
          cardWidthPlusMarginValue={cardWidth + marginValue}
          keyExtractor={(_, index) => index.toString()}
          animationScaleFactor={0.57}
        />
      </View>
      <View style={styles.flatListContainer}>
        <FlatListWithCircularIndicator
          renderItem={({ item }) => <Card item={item} />}
          data={data}
          cardWidthPlusMarginValue={cardWidth + marginValue}
          keyExtractor={(_, index) => index.toString()}
          animationScaleFactor={0.57}
        />
      </View>
    </ScrollView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  cardContainer: {
    alignItems: 'center',
    justifyContent: 'center',
    alignContent: 'center',
    backgroundColor: 'lightblue',
    height: 200,
    borderRadius: 10,
  },
  flatListContainer: { marginTop: 30 },
  text: { marginLeft: 10, fontSize: 14, fontWeight: '500' },
  cardText: { fontSize: 20, fontWeight: '800' },
});

Shared Props

Shared Props Table:

NameTypeRequired/OptionalDescription
activeIndicatorColorstringOptionalThe color of the active indicator.
inActiveIndicatorColorstringOptionalThe color of the inactive indicators.
dataArray<any>RequiredAn array of data items to be rendered in the list.
cardWidthPlusMarginValuenumberRequiredThe width of each list item plus any margin or padding.
animationScaleFactornumberOptionalThe scaling and animation factor for the indicators. Default value is 1.
containerStyleViewStyleOptionalAdditional styles to be applied to the container view.
indicatorContainerStyleViewStyleOptionalAdditional styles to be applied to the indicator container view.
customsIndicatorStyleViewStyleOptionalAdditional styles to be applied to the custom indicators.
isRTLbooleanOptionalDetermines if the layout is right-to-left. Default value is based on the device's language settings.
passOnScrollEvent(event) => voidOptionalPasses the onScroll event from the parent component to the child component.

Note: Any other props accepted by the React Native FlatList component can also be used with react-native-flatlist-withindicator. However, please be aware that the following props are excluded from the standard FlatList component:

  • horizontal: This prop is not applicable since it is designed to display a horizontal list.

  • showsHorizontalScrollIndicator: This prop is not applicable since it handles its own indicator display.

  • The onScroll prop is not applicable . Instead, you can use the passOnScrollEvent prop to achieve the onScroll functionality.

FlatList With Rectangle Indicator Props (Extends Shared Props):

NameTypeRequired/OptionalDescription
activeIndicatorWidthnumberOptionalThe width of the active indicator. Default value is 32
inactiveIndicatorWidthnumberOptionalThe width of the inactive indicator.Default value is 12

FlatList With Circular Indicator Props (Extends Shared Props):

NameTypeRequired/OptionalDescription
circleRadiusnumberOptionalThe radius of the circular indicator.Default value is 10

animationScaleFactor Prop

The animationScaleFactor prop is an optional number prop that determines the scaling and animation factor for the indicators. The default value is 1, It controls the scale and intensity of the animation applied to the indicators as the user scrolls through the list.

RTL Support

This package provides support for RTL (Right-to-Left) systems

Contributing

Contributions are welcome! If you have any suggestions or find a bug, please open an issue or submit a pull request.

0.1.9

10 months ago

0.1.8

10 months ago

0.1.7

10 months ago

0.1.6

10 months ago

0.1.5

10 months ago

0.1.4

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago