1.0.1 • Published 7 months ago

react-native-alphabet-slider v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

Alphabet Slider

An alphabetic slider component that will move the scroll position of an alphabetically-ordered FlatList to the poisition of the letter pressed on the slider.

alphabet-slider

Installation

npm i alphabet-slider-react-native

or

yarn add alphabet-slider-react-native

Usage

This package is meant to be used alongside a FlatList. The AlphabetSlider component requires 3 props to work: flatListRef, data, and path. The flatListRef is a ref passed to the FlatList component, data is the data passed to the FlatList component, and path is the path into the title of the data item.

In use it would look something like this:

import React, { useRef } from 'react';
import {View, FlatList} from 'react-native';
import AlphabetSlider from 'react-native-alphabet-slider';

const App = () => {
    const flatListRef = useRef<FlatList>(null);

    const DATA = [
        {
            id: 'bd7acbea-c1b1-46c2-aed5-3ad53abb28ba',
            title: 'First Item',
        },
        {
            id: '3ac68afc-c605-48d3-a4f8-fbd91aa97f63',
            title: 'Second Item',
        },
        {
            id: '58694a0f-3da1-471f-bd96-145571e29d72',
            title: 'Third Item',
        },
    ];

    type ItemProps = {title: string};

    const Item = ({title}: ItemProps) => (
        <View style={styles.item}>
            <Text style={styles.title}>{title}</Text>
        </View>
    );

    return (
        <View>
        <FlatList
            data={DATA}
            renderItem={({item}) => <Item title={item.title} />}
            keyExtractor={item => item.id}
            ref={flatListRef}
        />
        <FlatList flatListRef={flatListRef} data={DATA} path="title" />
        </View>
    );
};

For a working example, please take a look at the example directory.

Properties

PropDescriptionTypeDefault
flatListRefref passed to the FlatList componentstringrequired
dataThe data passed to the FlatList componentstringrequired
pathThe path into the title of the data itemnumberrequired
itemHeightThe height of the View wrapping each letternumber20
containerStyleStyles passed to the View wrapping the entire componentViewStyleundefined
alphabetItemContainerStyleStyles passed to the View wrapping each letterViewStyleundefined
alphabetItemTextStyleStyles passed to the Text component for each letterViewStyleundefined
alphabetItemTextDisabledStyleStyles passed to the Text component for each letter while disabledViewStyleundefined

Contributing

You are welcome to contribute!

License

MIT