Skip to content

Commit 4d3496f

Browse files
committed
clean up code
1 parent 84c3f69 commit 4d3496f

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

src/components/Search/SearchList.tsx

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import {useIsFocused} from '@react-navigation/native';
2-
import type {ContentStyle, FlashListProps, ListRenderItemInfo} from '@shopify/flash-list';
3-
import {FlashList} from '@shopify/flash-list';
42
import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react';
53
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';
86
import Animated from 'react-native-reanimated';
97
import Checkbox from '@components/Checkbox';
108
import * as Expensicons from '@components/Icon/Expensicons';
@@ -30,7 +28,7 @@ import {addKeyDownPressListener, removeKeyDownPressListener} from '@libs/Keyboar
3028
import variables from '@styles/variables';
3129
import CONST from '@src/CONST';
3230

33-
const AnimatedFlashList = Animated.createAnimatedComponent<FlashListProps<SearchListItem>>(FlashList<SearchListItem>);
31+
// const AnimatedFlashList = Animated.createAnimatedComponent<FlatListProps<any, any>>(FlatList);
3432
type SearchListItem = TransactionListItemType | ReportListItemType | ReportActionListItemType;
3533
type SearchListItemComponentType = typeof TransactionListItem | typeof ChatListItem | typeof ReportListItem;
3634

@@ -63,7 +61,7 @@ type SearchListProps = {
6361
onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
6462

6563
/** Additional styles to apply to scrollable content */
66-
contentContainerStyle?: StyleProp<ContentStyle>;
64+
contentContainerStyle?: StyleProp<ViewStyle>;
6765

6866
/**
6967
* How far from the end (in units of visible length of the list) the bottom edge of the
@@ -106,26 +104,25 @@ function SearchList(
106104
ref: ForwardedRef<SearchListHandle>,
107105
) {
108106
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);
110110
const {translate} = useLocalize();
111111
const isFocused = useIsFocused();
112-
const listRef = useRef<FlashList<SearchListItem>>(null);
112+
const listRef = useRef<FlatList<SearchListItem>>(null);
113113
const hasKeyBeenPressed = useRef(false);
114114
const [itemsToHighlight, setItemsToHighlight] = useState<Set<string> | null>(null);
115115
const itemFocusTimeoutRef = useRef<NodeJS.Timeout | null>(null);
116-
117116
const {isKeyboardShown} = useKeyboardState();
118117
const {safeAreaPaddingBottomStyle} = useStyledSafeAreaInsets();
119-
120-
// _______________________________________ selection modal logic _______________________________________
121-
const [isModalVisible, setIsModalVisible] = useState(false);
122-
const [longPressedItem, setLongPressedItem] = useState<SearchListItem>();
123118
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout here because there is a race condition that causes shouldUseNarrowLayout to change indefinitely in this component
124119
// See https://github.com/Expensify/App/issues/48675 for more details
125120
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
126121
const {isSmallScreenWidth} = useResponsiveLayout();
127122

123+
const [isModalVisible, setIsModalVisible] = useState(false);
128124
const {selectionMode} = useMobileSelectionMode();
125+
const [longPressedItem, setLongPressedItem] = useState<SearchListItem>();
129126
// Check if selection should be on when the modal is opened
130127
const wasSelectionOnRef = useRef(false);
131128
// Keep track of the number of selected items to determine if we should turn off selection mode
@@ -184,9 +181,6 @@ function SearchList(
184181
onCheckboxPress?.(longPressedItem);
185182
}
186183
};
187-
// _______________________________________ selection modal logic _______________________________________
188-
189-
// _______________________________________ arrow navigation logic _______________________________________
190184

191185
/**
192186
* Scrolls to the desired item index in the section list
@@ -252,10 +246,6 @@ function SearchList(
252246
return () => removeKeyDownPressListener(setHasKeyBeenPressed);
253247
}, [setHasKeyBeenPressed]);
254248

255-
// _______________________________________ arrow navigation logic _______________________________________
256-
257-
// _______________________________________ arrow navigation logic _______________________________________
258-
259249
/**
260250
* Highlights the items and scrolls to the first item present in the items list.
261251
*
@@ -292,8 +282,6 @@ function SearchList(
292282

293283
useImperativeHandle(ref, () => ({scrollAndHighlightItem, scrollToIndex}), [scrollAndHighlightItem, scrollToIndex]);
294284

295-
// _______________________________________ arrow navigation logic _______________________________________
296-
297285
const renderItem = useCallback(
298286
({item, index}: ListRenderItemInfo<SearchListItem>) => {
299287
const isItemFocused = focusedIndex === index;
@@ -328,9 +316,9 @@ function SearchList(
328316
return (
329317
<View style={[styles.flex1, !isKeyboardShown && safeAreaPaddingBottomStyle, containerStyle]}>
330318
{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]}>
332320
<Checkbox
333-
accessibilityLabel="TODO"
321+
accessibilityLabel={translate('workspace.people.selectAll')}
334322
isChecked={selectedItemsLength === data.length}
335323
onPress={() => {
336324
listRef.current?.scrollToIndex({index: 0, animated: true});
@@ -350,20 +338,19 @@ function SearchList(
350338
)}
351339
</View>
352340
)}
353-
<AnimatedFlashList
341+
<Animated.FlatList
354342
data={data}
355343
renderItem={renderItem}
356344
keyExtractor={(item, index) => item.keyForList ?? `${index}`}
357-
estimatedItemSize={108}
358345
onScroll={onScroll}
359-
contentContainerStyle={StyleSheet.flatten(contentContainerStyle)} // We have to use flatten, because FlashList doesn't handle array styles
346+
contentContainerStyle={contentContainerStyle}
360347
showsVerticalScrollIndicator={false}
361348
ref={listRef}
362349
extraData={focusedIndex}
363350
onEndReached={onEndReached}
364351
onEndReachedThreshold={onEndReachedThreshold}
365352
ListFooterComponent={ListFooterComponent}
366-
removeClippedSubviews // TODO measure how it helps performance
353+
removeClippedSubviews
367354
/>
368355
<Modal
369356
isVisible={isModalVisible}
@@ -382,4 +369,3 @@ function SearchList(
382369
}
383370

384371
export default forwardRef(SearchList);
385-
// TODO fix styles in Header VIew

src/styles/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3753,11 +3753,22 @@ const styles = (theme: ThemeColors) =>
37533753
paddingTop: variables.searchListContentMarginTop,
37543754
},
37553755

3756+
searchListHeaderContainerStyle: {
3757+
width: '100%',
3758+
flexDirection: 'row',
3759+
alignItems: 'center',
3760+
...userSelect.userSelectNone,
3761+
paddingBottom: 12,
3762+
paddingHorizontal: 32,
3763+
paddingTop: 12,
3764+
backgroundColor: theme.appBG,
3765+
justifyContent: 'flex-start',
3766+
},
3767+
37563768
narrowSearchHeaderStyle: {
37573769
flex: 1,
37583770
paddingTop: 12,
37593771
backgroundColor: theme.appBG,
3760-
flex: 1,
37613772
},
37623773

37633774
narrowSearchRouterInactiveStyle: {

0 commit comments

Comments
 (0)