@@ -88,30 +88,6 @@ function flatColumns<RecordType>(
88
88
} , [ ] ) ;
89
89
}
90
90
91
- function warningFixed ( flattenColumns : readonly { fixed ?: FixedType } [ ] ) {
92
- let allFixLeft = true ;
93
- for ( let i = 0 ; i < flattenColumns . length ; i += 1 ) {
94
- const col = flattenColumns [ i ] ;
95
- if ( allFixLeft && col . fixed !== 'left' ) {
96
- allFixLeft = false ;
97
- } else if ( ! allFixLeft && col . fixed === 'left' ) {
98
- warning ( false , `Index ${ i - 1 } of \`columns\` missing \`fixed='left'\` prop.` ) ;
99
- break ;
100
- }
101
- }
102
-
103
- let allFixRight = true ;
104
- for ( let i = flattenColumns . length - 1 ; i >= 0 ; i -= 1 ) {
105
- const col = flattenColumns [ i ] ;
106
- if ( allFixRight && col . fixed !== 'right' ) {
107
- allFixRight = false ;
108
- } else if ( ! allFixRight && col . fixed === 'right' ) {
109
- warning ( false , `Index ${ i + 1 } of \`columns\` missing \`fixed='right'\` prop.` ) ;
110
- break ;
111
- }
112
- }
113
- }
114
-
115
91
function revertForRtl < RecordType > ( columns : ColumnsType < RecordType > ) : ColumnsType < RecordType > {
116
92
return columns . map ( column => {
117
93
const { fixed, ...restProps } = column ;
@@ -176,6 +152,7 @@ function useColumns<RecordType>(
176
152
columns : ColumnsType < RecordType > ,
177
153
flattenColumns : readonly ColumnType < RecordType > [ ] ,
178
154
realScrollWidth : undefined | number ,
155
+ hasGapFixed : boolean ,
179
156
] {
180
157
const baseColumns = React . useMemo < ColumnsType < RecordType > > ( ( ) => {
181
158
const newColumns = columns || convertChildrenToColumns ( children ) || [ ] ;
@@ -294,10 +271,40 @@ function useColumns<RecordType>(
294
271
return flatColumns ( mergedColumns ) ;
295
272
} , [ mergedColumns , direction , scrollWidth ] ) ;
296
273
297
- // Only check out of production since it's waste for each render
298
- if ( process . env . NODE_ENV !== 'production' ) {
299
- warningFixed ( direction === 'rtl' ? flattenColumns . slice ( ) . reverse ( ) : flattenColumns ) ;
300
- }
274
+ // ========================= Gap Fixed ========================
275
+ const hasGapFixed = React . useMemo ( ( ) => {
276
+ // Fixed: left, since old browser not support `findLastIndex`, we should use reverse loop
277
+ let lastLeftIndex = - 1 ;
278
+ for ( let i = flattenColumns . length - 1 ; i >= 0 ; i -= 1 ) {
279
+ const colFixed = flattenColumns [ i ] . fixed ;
280
+ if ( colFixed === 'left' || colFixed === true ) {
281
+ lastLeftIndex = i ;
282
+ break ;
283
+ }
284
+ }
285
+
286
+ if ( lastLeftIndex >= 0 ) {
287
+ for ( let i = 0 ; i <= lastLeftIndex ; i += 1 ) {
288
+ const colFixed = flattenColumns [ i ] . fixed ;
289
+ if ( colFixed !== 'left' && colFixed !== true ) {
290
+ return true ;
291
+ }
292
+ }
293
+ }
294
+
295
+ // Fixed: right
296
+ const firstRightIndex = flattenColumns . findIndex ( ( { fixed : colFixed } ) => colFixed === 'right' ) ;
297
+ if ( firstRightIndex >= 0 ) {
298
+ for ( let i = firstRightIndex ; i < flattenColumns . length ; i += 1 ) {
299
+ const colFixed = flattenColumns [ i ] . fixed ;
300
+ if ( colFixed !== 'right' ) {
301
+ return true ;
302
+ }
303
+ }
304
+ }
305
+
306
+ return false ;
307
+ } , [ flattenColumns ] ) ;
301
308
302
309
// ========================= FillWidth ========================
303
310
const [ filledColumns , realScrollWidth ] = useWidthColumns (
@@ -306,7 +313,7 @@ function useColumns<RecordType>(
306
313
clientWidth ,
307
314
) ;
308
315
309
- return [ mergedColumns , filledColumns , realScrollWidth ] ;
316
+ return [ mergedColumns , filledColumns , realScrollWidth , hasGapFixed ] ;
310
317
}
311
318
312
319
export default useColumns ;
0 commit comments