1
1
import { useIsFocused } from '@react-navigation/native' ;
2
- import type { ContentStyle , FlashListProps , ListRenderItemInfo } from '@shopify/flash-list' ;
3
- import { FlashList } from '@shopify/flash-list' ;
4
2
import React , { forwardRef , useCallback , useEffect , useImperativeHandle , useRef , useState } from 'react' ;
5
3
import type { ForwardedRef } from 'react' ;
6
- import { StyleSheet , View } from 'react-native' ;
7
- import type { NativeScrollEvent , NativeSyntheticEvent , StyleProp , ViewStyle } from 'react-native' ;
4
+ import { View } from 'react-native' ;
5
+ import type { FlatList , ListRenderItemInfo , NativeScrollEvent , NativeSyntheticEvent , StyleProp , ViewStyle } from 'react-native' ;
8
6
import Animated from 'react-native-reanimated' ;
9
7
import Checkbox from '@components/Checkbox' ;
10
8
import * as Expensicons from '@components/Icon/Expensicons' ;
@@ -30,7 +28,7 @@ import {addKeyDownPressListener, removeKeyDownPressListener} from '@libs/Keyboar
30
28
import variables from '@styles/variables' ;
31
29
import CONST from '@src/CONST' ;
32
30
33
- const AnimatedFlashList = Animated . createAnimatedComponent < FlashListProps < SearchListItem > > ( FlashList < SearchListItem > ) ;
31
+ // const AnimatedFlashList = Animated.createAnimatedComponent<FlatListProps<any, any >>(FlatList );
34
32
type SearchListItem = TransactionListItemType | ReportListItemType | ReportActionListItemType ;
35
33
type SearchListItemComponentType = typeof TransactionListItem | typeof ChatListItem | typeof ReportListItem ;
36
34
@@ -63,7 +61,7 @@ type SearchListProps = {
63
61
onScroll ?: ( event : NativeSyntheticEvent < NativeScrollEvent > ) => void ;
64
62
65
63
/** Additional styles to apply to scrollable content */
66
- contentContainerStyle ?: StyleProp < ContentStyle > ;
64
+ contentContainerStyle ?: StyleProp < ViewStyle > ;
67
65
68
66
/**
69
67
* How far from the end (in units of visible length of the list) the bottom edge of the
@@ -106,26 +104,25 @@ function SearchList(
106
104
ref : ForwardedRef < SearchListHandle > ,
107
105
) {
108
106
const styles = useThemeStyles ( ) ;
109
- const selectedItemsLength = data . reduce ( ( acc , item ) => ( item . isSelected ? acc + 1 : acc ) , 0 ) ;
107
+ const selectedItemsLength = data . reduce ( ( acc , item ) => {
108
+ return item . isSelected ? acc + 1 : acc ;
109
+ } , 0 ) ;
110
110
const { translate} = useLocalize ( ) ;
111
111
const isFocused = useIsFocused ( ) ;
112
- const listRef = useRef < FlashList < SearchListItem > > ( null ) ;
112
+ const listRef = useRef < FlatList < SearchListItem > > ( null ) ;
113
113
const hasKeyBeenPressed = useRef ( false ) ;
114
114
const [ itemsToHighlight , setItemsToHighlight ] = useState < Set < string > | null > ( null ) ;
115
115
const itemFocusTimeoutRef = useRef < NodeJS . Timeout | null > ( null ) ;
116
-
117
116
const { isKeyboardShown} = useKeyboardState ( ) ;
118
117
const { safeAreaPaddingBottomStyle} = useStyledSafeAreaInsets ( ) ;
119
-
120
- // _______________________________________ selection modal logic _______________________________________
121
- const [ isModalVisible , setIsModalVisible ] = useState ( false ) ;
122
- const [ longPressedItem , setLongPressedItem ] = useState < SearchListItem > ( ) ;
123
118
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout here because there is a race condition that causes shouldUseNarrowLayout to change indefinitely in this component
124
119
// See https://github.com/Expensify/App/issues/48675 for more details
125
120
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
126
121
const { isSmallScreenWidth} = useResponsiveLayout ( ) ;
127
122
123
+ const [ isModalVisible , setIsModalVisible ] = useState ( false ) ;
128
124
const { selectionMode} = useMobileSelectionMode ( ) ;
125
+ const [ longPressedItem , setLongPressedItem ] = useState < SearchListItem > ( ) ;
129
126
// Check if selection should be on when the modal is opened
130
127
const wasSelectionOnRef = useRef ( false ) ;
131
128
// Keep track of the number of selected items to determine if we should turn off selection mode
@@ -184,9 +181,6 @@ function SearchList(
184
181
onCheckboxPress ?.( longPressedItem ) ;
185
182
}
186
183
} ;
187
- // _______________________________________ selection modal logic _______________________________________
188
-
189
- // _______________________________________ arrow navigation logic _______________________________________
190
184
191
185
/**
192
186
* Scrolls to the desired item index in the section list
@@ -252,10 +246,6 @@ function SearchList(
252
246
return ( ) => removeKeyDownPressListener ( setHasKeyBeenPressed ) ;
253
247
} , [ setHasKeyBeenPressed ] ) ;
254
248
255
- // _______________________________________ arrow navigation logic _______________________________________
256
-
257
- // _______________________________________ arrow navigation logic _______________________________________
258
-
259
249
/**
260
250
* Highlights the items and scrolls to the first item present in the items list.
261
251
*
@@ -292,8 +282,6 @@ function SearchList(
292
282
293
283
useImperativeHandle ( ref , ( ) => ( { scrollAndHighlightItem, scrollToIndex} ) , [ scrollAndHighlightItem , scrollToIndex ] ) ;
294
284
295
- // _______________________________________ arrow navigation logic _______________________________________
296
-
297
285
const renderItem = useCallback (
298
286
( { item, index} : ListRenderItemInfo < SearchListItem > ) => {
299
287
const isItemFocused = focusedIndex === index ;
@@ -328,9 +316,9 @@ function SearchList(
328
316
return (
329
317
< View style = { [ styles . flex1 , ! isKeyboardShown && safeAreaPaddingBottomStyle , containerStyle ] } >
330
318
{ canSelectMultiple && (
331
- < View style = { [ styles . userSelectNone , styles . peopleRow , styles . ph5 , styles . pb3 , styles . ph8 , styles . pt3 , styles . selectionListStickyHeader , styles . justifyContentStart ] } >
319
+ < View style = { [ styles . searchListHeaderContainerStyle ] } >
332
320
< Checkbox
333
- accessibilityLabel = "TODO"
321
+ accessibilityLabel = { translate ( 'workspace.people.selectAll' ) }
334
322
isChecked = { selectedItemsLength === data . length }
335
323
onPress = { ( ) => {
336
324
listRef . current ?. scrollToIndex ( { index : 0 , animated : true } ) ;
@@ -350,20 +338,19 @@ function SearchList(
350
338
) }
351
339
</ View >
352
340
) }
353
- < AnimatedFlashList
341
+ < Animated . FlatList
354
342
data = { data }
355
343
renderItem = { renderItem }
356
344
keyExtractor = { ( item , index ) => item . keyForList ?? `${ index } ` }
357
- estimatedItemSize = { 108 }
358
345
onScroll = { onScroll }
359
- contentContainerStyle = { StyleSheet . flatten ( contentContainerStyle ) } // We have to use flatten, because FlashList doesn't handle array styles
346
+ contentContainerStyle = { contentContainerStyle }
360
347
showsVerticalScrollIndicator = { false }
361
348
ref = { listRef }
362
349
extraData = { focusedIndex }
363
350
onEndReached = { onEndReached }
364
351
onEndReachedThreshold = { onEndReachedThreshold }
365
352
ListFooterComponent = { ListFooterComponent }
366
- removeClippedSubviews // TODO measure how it helps performance
353
+ removeClippedSubviews
367
354
/>
368
355
< Modal
369
356
isVisible = { isModalVisible }
@@ -382,4 +369,3 @@ function SearchList(
382
369
}
383
370
384
371
export default forwardRef ( SearchList ) ;
385
- // TODO fix styles in Header VIew
0 commit comments