2.0.17 • Published 4 days ago

react-native-complete-flatlist v2.0.17

Weekly downloads
29
License
MIT
Repository
github
Last release
4 days ago

react-native-complete-flatlist

Extended version of react native flat list with many built in function such as search, pull to refresh, no data available message if empty row

ezgif-3-734272a58f

Caution:

renderItem props return item and index parameters item parameter returns a single element in item array. But if search text is not empty dan highlightColor props is set to any color, item parameter will return new structure of JSON object (in order to render highlighted text in jsx). This might break your logic. Therefore, if you want to access original structure of your data, it will be under item.cleanData. Remember, item.cleanData only exist if highlightColor props and search textfield is not empty (user is searching)

Usage :

import React, {useRef} from 'react';
import { Text, SafeAreaView, TouchableOpacity } from 'react-native';
import CompleteFlatList from 'react-native-complete-flatlist';

const list = [
  { name: 'Fattah', status: 'Active', time: '8:10 PM', date: '1 Jan 2018' },
  { name: 'Syah', status: 'Active', time: '9:14 PM', date: '1 Dec 2018' },
  { name: 'Izzat', status: 'Active', time: '8:15 PM', date: '1 Jan 2018' },
  { name: 'Ali', status: 'Active', time: '8:10 PM', date: '1 Jan 2018' },
  { name: 'Abu', status: 'Active', time: '8:11 PM', date: '1 Jan 2018' },
  { name: 'Fitri', status: 'Active', time: '8:20 PM', date: '1 Jan 2018' },
  { name: 'Armi', status: 'Active', time: '8:33 PM', date: '1 Jan 2018' },
  { name: 'Eidit', status: 'Active', time: '9:10 PM', date: '1 Jan 2018' },
  { name: 'Hamdan', status: 'Active', time: '10:10 PM', date: '1 Jan 2018' },
  {
    name: 'Muhyiddeen',
    status: 'Blocked',
    time: '10:10 PM',
    date: '9 Feb 2018',
  },
];

const App = () => {
  const ref = useRef();
  const renderItem = ({item, index}) => {
    const data = item.cleanData ? item.cleanData : item;

    console.log('item (if search bar is not empty and prop highlightColor is not empty, item will contains extra data to enable highlight feature)', item);
    console.log('cleanData (if search bar is not empty and prop highlightColor is not empty, cleanData will contain original data structure without extra data)', item.cleanData);


    console.log('this is index number : ' + index);

    console.log(data + ' this is original data');

    return <Text>{item.name}</Text>;
  };

  return (
    <SafeAreaView style={{ flex: 1 }}>
      <CompleteFlatList
        searchKey={['name', 'status', 'time', 'date']}
        pullToRefreshCallback={() => console.log('refreshing')}
        data={list}
        // renderSeparator={null}
        ref={ref}
        highlightColor="yellow"
        renderItem={renderItem}
      />
      <TouchableOpacity onPress={() => ref.current.clearSearch()} style={{ padding: 5 }}>
        <Text>Clear Search</Text>
      </TouchableOpacity>
    </SafeAreaView>
  );
};

export default App;

Upgrading from V 1.x.x to V 2.x.x

Change from renderItem={(data, index) => {} } to renderItem={({item, index, separators}) => {} } (similar like the on in Original Flatlist)

Properties

All FlatList props should work plus props mentioned below

PropTypeDescriptionDefaultRequired
showSearchbooleanIf true (and searchKey prop is defined), search bar will be shown.trueOptional
isJellybooleanIf true, when user scroll, the list will expand a lil bit, and when user stop drag, the list will back to original size (iMessage on iPhone style)falseOptional
slidestringAnimation how every items come into the list. Can be "none", "left" or "right"noneOptional
dataarray of objectsData to be rendered in the list[]Required (come on, ofcourse u need data for this)
backgroundStylesstyle objectStyle of the flatlist backgroundnullOptional
searchBarBackgroundStylesstyle objectStyle of the searchbar backgroundnullOptional
pullToRefreshCallbackfunctionCallback function when user pull to refreshnullOptional (Pull to refresh will not be available if this is not supplied
isLoadingbooleanif true, the loading will be shown on top of the list.falseOptional
renderItemfunction that return a JSX element (Just like RN's ListView and FlatList)Template of a row in the Flat Listnull (open for PR if anyone wish to make default template for this)Required (since I dont do default template yet)
renderSeparatorfunction that return a JSX element to be rendered between rows(Just like RN's ListView and FlatList)Template of separator in the Flat List() => <View style={{ height: 1, width: "80%", alignSelf: "center", backgroundColor: "#f2f2f2" }} />Optional
placeholderstringPlaceholder of search field"Search ..."Optional
searchTextInputStyleobject (style for React Native's TextInput component)style for search fieldnullOptional
highlightColorcolorcolor of higlighted words background when match search keyword. Please read the pre caution if using this prop on top of the readmeyellowOptional
searchKeyarray of stringThis should be name of keys available in data which will be use to search. If this prop is not supplied, search text input will not be rendered. **Warning: nested key not yet supported[]Optional (if not supplied, search field will not appear)
elementBetweenSearchAndListJSX elementWhat to render between searchbar and the listnullOptional
refreshOnLoadbooleanIf true, prop pullToRefreshCallback will be called if availabletrueOptional
onSearchfunction that will replace pullToRefreshCallbackIf exist, pullToRefreshCallback will be overrided. This will not triggered on key press, but on return key pressed. This props is introduced if search trigger result from API. If you just want local search (search from existing array), this props is not needed. onSearch will automatic get keyword parameter()=>nullOptional

Methods

If you have ref to the component,

const completeFlatList = useRef();
...
 <CompleteFlatList
   ...
    ref={completeFlatList}
   ...
 />

or in component based

<CompleteFlatList
   ...
   ref={c => this.completeFlatList = c}
   ...
/>

you can use any method(s) below: completeFlatList.current.methodName()

or in component based

this.completeFlatList.methodName()

MethodDescription
clearSearchClear search input programmatically
2.0.15

4 days ago

2.0.16

4 days ago

2.0.17

4 days ago

2.0.14

1 year ago

2.0.13

2 years ago

2.0.11

2 years ago

2.0.12

2 years ago

2.0.10

3 years ago

2.0.9

3 years ago

2.0.8

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.40

5 years ago

1.1.39

5 years ago

1.1.38

5 years ago

1.1.37

5 years ago

1.1.36

5 years ago

1.1.35

5 years ago

1.1.34

5 years ago

1.1.33

5 years ago

1.1.32

5 years ago

1.1.31

5 years ago

1.1.30

5 years ago

1.1.29

5 years ago

1.1.28

5 years ago

1.1.27

6 years ago

1.1.26

6 years ago

1.1.25

6 years ago

1.1.24

6 years ago

1.1.23

6 years ago

1.1.22

6 years ago

1.1.21

6 years ago

1.1.20

6 years ago

1.1.19

6 years ago

1.1.18

6 years ago

1.1.17

6 years ago

1.1.16

6 years ago

1.1.15

6 years ago

1.1.14

6 years ago

1.1.13

6 years ago

1.1.12

6 years ago

1.1.11

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago