@@ -20,12 +20,11 @@ import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
2020import useKeyboardShortcut from '@hooks/useKeyboardShortcut' ;
2121import useKeyboardState from '@hooks/useKeyboardState' ;
2222import useLocalize from '@hooks/useLocalize' ;
23- import useMobileSelectionMode from '@hooks/useMobileSelectionMode' ;
2423import useOnyx from '@hooks/useOnyx' ;
2524import useResponsiveLayout from '@hooks/useResponsiveLayout' ;
2625import useSafeAreaPaddings from '@hooks/useSafeAreaPaddings' ;
2726import useThemeStyles from '@hooks/useThemeStyles' ;
28- import { turnOffMobileSelectionMode , turnOnMobileSelectionMode } from '@libs/actions/MobileSelectionMode' ;
27+ import { turnOnMobileSelectionMode } from '@libs/actions/MobileSelectionMode' ;
2928import { isMobileChrome } from '@libs/Browser' ;
3029import { addKeyDownPressListener , removeKeyDownPressListener } from '@libs/KeyboardShortcut/KeyDownPressListener' ;
3130import variables from '@styles/variables' ;
@@ -78,6 +77,13 @@ type SearchListProps = Pick<FlatListPropsWithLayout<SearchListItem>, 'onScroll'
7877
7978 /** Invoked on mount and layout changes */
8079 onLayout ?: ( ) => void ;
80+
81+ /** Whether mobile selection mode is enabled */
82+ isMobileSelectionModeEnabled : boolean ;
83+ } ;
84+
85+ const keyExtractor = ( item : SearchListItem , index : number ) => {
86+ return item . keyForList ?? `${ index } ` ;
8187} ;
8288
8389const onScrollToIndexFailed = ( ) => { } ;
@@ -102,6 +108,7 @@ function SearchList(
102108 queryJSON,
103109 onViewableItemsChanged,
104110 onLayout,
111+ isMobileSelectionModeEnabled,
105112 } : SearchListProps ,
106113 ref : ForwardedRef < SearchListHandle > ,
107114) {
@@ -126,51 +133,14 @@ function SearchList(
126133 const { isSmallScreenWidth} = useResponsiveLayout ( ) ;
127134
128135 const [ isModalVisible , setIsModalVisible ] = useState ( false ) ;
129- const { selectionMode} = useMobileSelectionMode ( ) ;
130136 const [ longPressedItem , setLongPressedItem ] = useState < SearchListItem > ( ) ;
131- // Check if selection should be on when the modal is opened
132- const wasSelectionOnRef = useRef ( false ) ;
133- // Keep track of the number of selected items to determine if we should turn off selection mode
134- const selectionRef = useRef ( 0 ) ;
135137
136138 const [ policies ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY , {
137139 canBeMissing : true ,
138140 } ) ;
139141
140142 const [ allReports ] = useOnyx ( ONYXKEYS . COLLECTION . REPORT , { canBeMissing : false } ) ;
141143
142- useEffect ( ( ) => {
143- selectionRef . current = selectedItemsLength ;
144-
145- if ( ! isSmallScreenWidth ) {
146- if ( selectedItemsLength === 0 ) {
147- turnOffMobileSelectionMode ( ) ;
148- }
149- return ;
150- }
151- if ( ! isFocused ) {
152- return ;
153- }
154- if ( ! wasSelectionOnRef . current && selectedItemsLength > 0 ) {
155- wasSelectionOnRef . current = true ;
156- }
157- if ( selectedItemsLength > 0 && ! selectionMode ?. isEnabled ) {
158- turnOnMobileSelectionMode ( ) ;
159- } else if ( selectedItemsLength === 0 && selectionMode ?. isEnabled && ! wasSelectionOnRef . current ) {
160- turnOffMobileSelectionMode ( ) ;
161- }
162- } , [ selectionMode , isSmallScreenWidth , isFocused , selectedItemsLength ] ) ;
163-
164- useEffect (
165- ( ) => ( ) => {
166- if ( selectionRef . current !== 0 ) {
167- return ;
168- }
169- turnOffMobileSelectionMode ( ) ;
170- } ,
171- [ ] ,
172- ) ;
173-
174144 const handleLongPressRow = useCallback (
175145 ( item : SearchListItem ) => {
176146 // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
@@ -181,14 +151,14 @@ function SearchList(
181151 if ( 'transactions' in item && item . transactions . length === 0 ) {
182152 return ;
183153 }
184- if ( selectionMode ?. isEnabled ) {
154+ if ( isMobileSelectionModeEnabled ) {
185155 onCheckboxPress ( item ) ;
186156 return ;
187157 }
188158 setLongPressedItem ( item ) ;
189159 setIsModalVisible ( true ) ;
190160 } ,
191- [ isFocused , isSmallScreenWidth , onCheckboxPress , selectionMode ?. isEnabled , shouldPreventLongPressRow ] ,
161+ [ isFocused , isSmallScreenWidth , onCheckboxPress , isMobileSelectionModeEnabled , shouldPreventLongPressRow ] ,
192162 ) ;
193163
194164 const turnOnSelectionMode = useCallback ( ( ) => {
@@ -398,7 +368,7 @@ function SearchList(
398368 < Animated . FlatList
399369 data = { data }
400370 renderItem = { renderItem }
401- keyExtractor = { ( item , index ) => item . keyForList ?? ` ${ index } ` }
371+ keyExtractor = { keyExtractor }
402372 onScroll = { onScroll }
403373 contentContainerStyle = { contentContainerStyle }
404374 showsVerticalScrollIndicator = { false }
0 commit comments