1- import React , { forwardRef , Fragment , memo , useCallback , useMemo } from 'react' ;
1+ import React , {
2+ forwardRef ,
3+ Fragment ,
4+ memo ,
5+ useCallback ,
6+ useImperativeHandle ,
7+ useMemo ,
8+ } from 'react' ;
29import { FlatList , RefreshControl , Text , View } from 'react-native' ;
310
411import type { Column , TableFlatListProps , TableRef } from './Table.types' ;
@@ -19,42 +26,40 @@ const NoData = ({ message }: NoDataProps) => (
1926export const isNullOrUndefined = ( data ?: any ) : data is null | undefined =>
2027 data === null || data === undefined ;
2128
22- const RowItem = memo (
23- forwardRef ( ( { item, index, columns, rowStyle, layout } : any , ref ) => (
24- < View
25- style = { [
26- {
27- flex : layout === 'vertical' ? 1 : undefined ,
28- flexDirection : layout === 'horizontal' ? 'column' : 'row' ,
29- } ,
30- rowStyle
31- ? typeof rowStyle === 'function'
32- ? rowStyle ( item , index )
33- : rowStyle
34- : { } ,
35- ] }
36- >
37- { columns . map ( ( column : Column , cidx : React . Key | null | undefined ) => (
38- < View
39- key = { cidx }
40- style = { [ { flex : layout == 'horizontal' ? 0 : 1 } , column . style ] }
41- >
42- { column . render ? (
43- column . render ( item [ column . dataIndex ?? column . key ] , index )
44- ) : (
45- < Text > { item [ column . key ] } </ Text >
46- ) }
47- </ View >
48- ) ) }
49- </ View >
50- ) )
51- ) ;
29+ const RowItem = memo ( ( { item, index, columns, rowStyle, layout } : any ) => (
30+ < View
31+ style = { [
32+ {
33+ flex : layout === 'vertical' ? 1 : undefined ,
34+ flexDirection : layout === 'horizontal' ? 'column' : 'row' ,
35+ } ,
36+ rowStyle
37+ ? typeof rowStyle === 'function'
38+ ? rowStyle ( item , index )
39+ : rowStyle
40+ : { } ,
41+ ] }
42+ >
43+ { columns . map ( ( column : Column , cidx : React . Key | null | undefined ) => (
44+ < View
45+ key = { cidx }
46+ style = { [ { flex : layout == 'horizontal' ? 0 : 1 } , column . style ] }
47+ >
48+ { column . render ? (
49+ column . render ( item [ column . dataIndex ?? column . key ] , index )
50+ ) : (
51+ < Text > { item [ column . key ] } </ Text >
52+ ) }
53+ </ View >
54+ ) ) }
55+ </ View >
56+ ) ) ;
57+
5258const TableFlatlist = forwardRef (
5359 (
5460 {
5561 dataSource : originalDataSource ,
5662 columns,
57- groupBy,
5863 layout,
5964 renderHeader,
6065 headerStyle,
@@ -91,6 +96,10 @@ const TableFlatlist = forwardRef(
9196 delete flatListPropsInner . isRefreshing ;
9297 }
9398
99+ useImperativeHandle ( ref , ( ) => {
100+ return { } ;
101+ } ) ;
102+
94103 const renderNoDataItem = useCallback ( ( ) => {
95104 if (
96105 typeof noDataContent === 'string' ||
@@ -102,33 +111,36 @@ const TableFlatlist = forwardRef(
102111 return noDataContent ! ;
103112 } , [ noDataContent ] ) ;
104113
105- const renderItem = useCallback ( ( { item, index } : any ) => {
106- if ( renderRow ) {
107- return renderRow ( {
108- record : item ,
109- index,
110- children : (
111- < RowItem
112- index = { index }
113- item = { item }
114- columns = { columns }
115- rowStyle = { rowStyle }
116- layout = { layout }
117- />
118- ) ,
119- } ) ;
120- }
114+ const renderItem = useCallback (
115+ ( { item, index } : any ) => {
116+ if ( renderRow ) {
117+ return renderRow ( {
118+ record : item ,
119+ index,
120+ children : (
121+ < RowItem
122+ index = { index }
123+ item = { item }
124+ columns = { columns }
125+ rowStyle = { rowStyle }
126+ layout = { layout }
127+ />
128+ ) ,
129+ } ) ;
130+ }
121131
122- return (
123- < RowItem
124- index = { index }
125- item = { item }
126- columns = { columns }
127- rowStyle = { rowStyle }
128- layout = { layout }
129- />
130- ) ;
131- } , [ ] ) ;
132+ return (
133+ < RowItem
134+ index = { index }
135+ item = { item }
136+ columns = { columns }
137+ rowStyle = { rowStyle }
138+ layout = { layout }
139+ />
140+ ) ;
141+ } ,
142+ [ columns , layout , renderRow , rowStyle ]
143+ ) ;
132144
133145 const keyExtractor = useCallback ( ( item : any , index : any ) => {
134146 return rowKey
0 commit comments