@@ -21,7 +21,7 @@ There are available **shorthands props** just in case you want to make batch upd
2121- [ ` group ` ] ( https://github.com/beforesemicolon/flatlist-react/blob/master/documentation/Doc.md#grouping )
2222- [ ` sort ` ] ( https://github.com/beforesemicolon/flatlist-react/blob/master/documentation/Doc.md#sorting )
2323- [ ` search ` ] ( https://github.com/beforesemicolon/flatlist-react/blob/master/documentation/Doc.md#searching )
24- - [ ` paginate ` ] ( https://github.com/beforesemicolon/flatlist-react/blob/master/documentation/Doc.md#pagination )
24+ - [ ` pagination ` ] ( https://github.com/beforesemicolon/flatlist-react/blob/master/documentation/Doc.md#pagination )
2525- [ ` scrollToTop ` ] ( https://github.com/beforesemicolon/flatlist-react/blob/master/documentation/Doc.md#scrolltotop )
2626- [ ` display ` ] ( https://github.com/beforesemicolon/flatlist-react/blob/master/documentation/Doc.md#styling ) .
2727
@@ -338,21 +338,42 @@ It is also good to use on lists which user normally dont reach the end anyways s
338338```
339339
340340## Pagination
341- FlatList comes with pagination out of the box. This is specially great for when fetching all the items from api would take long
341+ FlatList comes with pagination out of the box. This is specially great for when fetching all the items from api would take long,
342342so you start with fetching a small portion and then let the user scroll to the bottom, show the loading indicator while you
343343fetch some more.
344344
345345To make it work you need to render ` FlatList ` inside of a scrolling container with "` overflow: auto ` " or "` overflow: scroll ` ".
346- If the container wrapping flatlist does not scroll it miss the point of infinite scrolling.
346+ If the container wrapping FlatList does not scroll it misses the point of infinite scrolling.
347347
348- Pagination props will not work while ` renderOnScroll ` is being used.
348+ ``` jsx
349+ < div style= {{overflow: " auto" , height: " 300px" }}>
350+ < FlatList
351+ list= {this .props .people }
352+ renderItem= {this .renderPerson }
353+ renderWhenEmpty= {this .showBlank }
354+ / >
355+ < / div>
356+
357+ // --- OR ---
358+
359+ < FlatList
360+ list= {this .props .people }
361+ renderItem= {this .renderPerson }
362+ renderWhenEmpty= {this .showBlank }
363+ wrapperHtmlTag= " div"
364+ style= {{overflow: " auto" , height: " 300px" }}
365+ / >
366+ ```
367+
368+ Pagination props will not work while ` renderOnScroll ` is being used. Pagination already renders on scroll.
349369
350370### hasMoreItems
351371###### boolean
352372You start by telling FlatList if there are more items to come with ` hasMoreItems ` prop. It will then start monitor scrolling
353- and show loading indicator when the user reaches the end of the list.
373+ activities and the list size to show loading indicator when the user reaches the end of the list and fetching begins .
354374
355- When you are done fetching the whole list you can set this to "false" and FlatList will know you have the whole list.
375+ When you are done fetching the whole list you can set this to "false" and FlatList will know you have the whole list
376+ and stop monitoring scrolling and list size.
356377
357378### loadMoreItems
358379###### () => void
@@ -412,7 +433,7 @@ fetchData = () => {
412433 list= {this .props .people }
413434 renderItem= {this .renderPerson }
414435 renderWhenEmpty= {this .showBlank } // let user know if initial data is loading or there is no data to show
415- paginate = {{
436+ pagination = {{
416437 hasMore: this .state .hasMoreItems ,
417438 loadMore: this .fetchData
418439 }}
@@ -441,7 +462,7 @@ to show while items are being fetched.
441462 list= {this .props .people }
442463 renderItem= {this .renderPerson }
443464 renderWhenEmpty= {this .showBlank } // let user know if initial data is loading or there is no data to show
444- paginate = {{
465+ pagination = {{
445466 hasMore: this .state .hasMoreItems ,
446467 loadMore: this .fetchData ,
447468 loadingIndicator: < div style= {{background: ' #090' }}> Getting more items... < / div>
@@ -470,7 +491,7 @@ you can also specify **"center"** or **"right"**.
470491 list= {this .props .people }
471492 renderItem= {this .renderPerson }
472493 renderWhenEmpty= {this .showBlank } // let user know if initial data is loading or there is no data to show
473- paginate = {{
494+ pagination = {{
474495 hasMore: this .state .hasMoreItems ,
475496 loadMore: this .fetchData ,
476497 loadingIndicator: < div style= {{background: ' #090' }}> Getting more items... < / div> ,
@@ -1456,6 +1477,109 @@ The position is where you want the button to be placed. The default is **"bottom
14561477 / >
14571478```
14581479
1480+ ## Utilities
1481+ You may also use the internal utility functions FlatList uses to do all the amazing thing without rendering
1482+ anything or be in React. You may use these to craft your own FlatList alternative, custom to you.
1483+
1484+ ### sortList
1485+ ###### <T >(list: T[ ] , options?: SortOptionsInterface) => T[ ]
1486+
1487+ ``` ts
1488+ import {sortList } from " flatlist-react" ;
1489+
1490+ const list = [2 , 4 , 1 , 9 ]
1491+
1492+ sortList (list );
1493+ sortList (list , {descending: true , caseInsensitive: true });
1494+
1495+ const objectArray = [
1496+ {name: ' Last' , other: ' Zer' , age: 2 },
1497+ {name: ' First' , other: ' Last' , age: 8 },
1498+ {name: ' Middle' , other: ' Zer' , age: 1 },
1499+ {name: ' First' , other: ' Middle' , age: 8 },
1500+ {name: ' Last' , other: ' Abo' , age: 2 }
1501+ ];
1502+
1503+ sortList (objectArray , {descending: true , caseInsensitive: true , by: ' name' });
1504+ sortList (objectArray , {descending: false , caseInsensitive: true , by: [' name' , {key: ' age' , descending: true }]});
1505+ ```
1506+
1507+ ### searchList
1508+ ###### <T >(list: T[ ] , options: SearchOptionsInterface) => T[ ]
1509+
1510+ ``` ts
1511+ import {searchList } from " flatlist-react" ;
1512+
1513+ const objectArray = [
1514+ {name: ' Last' , other: ' Zer' , age: 2 },
1515+ {name: ' First' , other: ' Last' , age: 8 },
1516+ {name: ' Middle' , other: ' Zer' , age: 1 },
1517+ {name: ' First' , other: ' Middle' , age: 8 },
1518+ {name: ' Last' , other: ' Abo' , age: 2 }
1519+ ];
1520+
1521+ searchList (objectArray , {
1522+ by: [' name' , ' other' ],
1523+ term: ' Last' , // <- search term
1524+ everyWord: false ,
1525+ caseInsensitive: true
1526+ })
1527+ ```
1528+
1529+ ### filterList
1530+ ###### <T >(list: T[ ] , by?: ((item: T, idx: number) => boolean) | string) => T[ ]
1531+
1532+ ``` ts
1533+ import {filterList } from " flatlist-react" ;
1534+
1535+ const objectList = [
1536+ {name: ' Last' , other: ' Zer' , age: 2 },
1537+ {name: ' First' , other: ' Last' , age: 8 },
1538+ {name: ' Middle' , other: ' Zer' , age: 1 },
1539+ {name: ' First' , other: ' Middle' , age: 8 },
1540+ {name: ' Last' , other: ' Abo' , age: 2 }
1541+ ];
1542+
1543+ filterList (objectList , (item : any ) => item .age && item .age > 10 );
1544+ filterList (objectList , ' age' )
1545+ ```
1546+
1547+ ### groupList
1548+ ###### <T >(list: T[ ] , options?: GroupOptionsInterface) => {groupLabels: string[ ] , groupLists: T[ ] }
1549+
1550+ ``` ts
1551+ import {groupList } from " flatlist-react" ;
1552+
1553+ const objectList = [
1554+ {name: ' Last' , other: ' Zer' , age: 2 },
1555+ {name: ' First' , other: ' Last' , age: 8 },
1556+ {name: ' Middle' , other: ' Zer' , age: 1 },
1557+ {name: ' First' , other: ' Middle' , age: 7 },
1558+ {name: ' Last' , other: ' Abo' , age: 3 }
1559+ ];
1560+
1561+ groupList (objectList , {limit: 2 });
1562+
1563+ const groupBy: (item : any , idx : number ) => string | number = (item : any ) => {
1564+ return item .age % 2 === 0 ? ' divided by 2' : ' not divided by 2' ;
1565+ };
1566+
1567+ groupList (list , {by: groupBy });
1568+ ```
1569+
1570+ ### limitList
1571+ ###### <T >(list: T[ ] , limit?: string | number, to?: string | number) => T[ ]
1572+
1573+ ``` ts
1574+ import {limitList } from " flatlist-react" ;
1575+
1576+ const list = [2 , 4 , 1 , 9 , 89 , 1 , 33 ]
1577+
1578+ limitList (list , 5 ) // [2, 4, 1, 9, 89]
1579+ limitList (list , 2 , 4 ) // [3, 4]
1580+ limitList (list , 2 , - 2 ) // [3]
1581+ ```
1582+
14591583### Thank You
14601584Please show your support, help make this better, suggest features, report bugs and even contribute to this
14611585project.
0 commit comments