1.0.9 • Published 5 years ago

react-native-multichoice-flatlist v1.0.9

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

Multiple / Single Choice Flatlist

Advantages :

  • Completely customizable
  • Supports all FlatList props
  • Supports both multiple mode and single mode

Version 1.0.9

  • bug fixed

1. Install

npm install --save react-native-multichoice-flatlist

2. Usage

import {MultiChoiceFlatList} from "react-native-multichoice-flatlist";

...

<MultiChoiceFlatList
    ref={"mc"}
    data={[
        {id: 1, title: "First Item" , anotherProp:"the other prop" },
        {id: 2, title: "Second Item" , anotherProp:"the other prop" },
        {id: 3, title: "Third Item" , anotherProp:"the other prop" },
        {id: 4, title: "Fourth Item" , anotherProp:"the other prop" },
        {id: 5, title: "Fifth Item" , anotherProp:"the other prop" },
    ]}
    renderItem={(item, index) => {
        return (
            <View>
                <Text style={{backgroundColor:'green'}}>
                    {item.title}
                </Text>
            </View>
        )
    }}

    renderSelectedItem={(item, index) => {
       return (
           <View>
                <Text>
                    {item.title}
                </Text>
            </View>
        )
    }}

    onSelectedIndexesChange={(item, index, selected) => {
        console.log("item ", item);
        console.log("index ", index);
        console.log("is selected ", selected);
    }}

    singleMode={false}
    selectedIndexes={[2,3]}
    keyExtractor={(item, index) => item.id}

/>

...

Props

PropTypeDefaultDescription
dataarray[]the data to be shown (as orginal flatlist)
renderItemfunction-renders non selected item
renderSelectedItemfunction-renders selected item
singleModebooleantrueif 'true' just one item can be selected, if 'false' it's multichoice
selectedIndexint0( ONLY WHEN 'singleMode=true' ) default selected item
selectedIndexesarray of int[]( ONLY WHEN 'singleMode=false' ) default selected items
onSelectedIndexesChangefunction-listener function for item selection which provides touched item , index of touched item, a boolean which shows if the item is selected or not
keyExtractorfunction-is required for rerendering the flatlist when data changes.

Methods

MethodReturn TypeDescription
getSelectedItemsarrayreturns an array containing selected items
getNonSelectedItemsarrayreturns an array containing non selected items

Screenshots

Screenshots
ios