1
1
import type { ForwardedRef } from 'react' ;
2
- import React , { forwardRef , useEffect , useRef , useState } from 'react' ;
2
+ import React , { forwardRef , useEffect , useState } from 'react' ;
3
3
import * as Expensicons from '@components/Icon/Expensicons' ;
4
4
import MenuItem from '@components/MenuItem' ;
5
5
import Modal from '@components/Modal' ;
@@ -14,12 +14,10 @@ import CONST from '@src/CONST';
14
14
type SelectionListWithModalProps < TItem extends ListItem > = BaseSelectionListProps < TItem > & {
15
15
turnOnSelectionModeOnLongPress ?: boolean ;
16
16
onTurnOnSelectionMode ?: ( item : TItem | null ) => void ;
17
- shouldAutoTurnOff ?: boolean ;
18
- isSelected ?: ( item : TItem ) => boolean ;
19
17
} ;
20
18
21
19
function SelectionListWithModal < TItem extends ListItem > (
22
- { turnOnSelectionModeOnLongPress, onTurnOnSelectionMode, onLongPressRow, sections, shouldAutoTurnOff , isSelected , ...rest } : SelectionListWithModalProps < TItem > ,
20
+ { turnOnSelectionModeOnLongPress, onTurnOnSelectionMode, onLongPressRow, sections, ...rest } : SelectionListWithModalProps < TItem > ,
23
21
ref : ForwardedRef < SelectionListHandle > ,
24
22
) {
25
23
const [ isModalVisible , setIsModalVisible ] = useState ( false ) ;
@@ -28,47 +26,21 @@ function SelectionListWithModal<TItem extends ListItem>(
28
26
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout here because there is a race condition that causes shouldUseNarrowLayout to change indefinitely in this component
29
27
// See https://github.com/Expensify/App/issues/48675 for more details
30
28
const { isSmallScreenWidth} = useResponsiveLayout ( ) ;
31
- const { selectionMode} = useMobileSelectionMode ( shouldAutoTurnOff ) ;
32
- // Check if selection should be on when the modal is opened
33
- const wasSelectionOnRef = useRef ( false ) ;
34
- // Keep track of the number of selected items to determine if we should turn off selection mode
35
- const selectionRef = useRef ( 0 ) ;
29
+ const { selectionMode} = useMobileSelectionMode ( true ) ;
36
30
37
31
useEffect ( ( ) => {
38
32
// We can access 0 index safely as we are not displaying multiple sections in table view
39
- const selectedItems = sections [ 0 ] . data . filter ( ( item ) => {
40
- if ( isSelected ) {
41
- return isSelected ( item ) ;
42
- }
43
- return ! ! item . isSelected ;
44
- } ) ;
45
- selectionRef . current = selectedItems . length ;
46
-
33
+ const selectedItems = sections [ 0 ] . data . filter ( ( item ) => item . isSelected ) ;
47
34
if ( ! isSmallScreenWidth ) {
48
35
if ( selectedItems . length === 0 ) {
49
36
turnOffMobileSelectionMode ( ) ;
50
37
}
51
38
return ;
52
39
}
53
- if ( ! wasSelectionOnRef . current && selectedItems . length > 0 ) {
54
- wasSelectionOnRef . current = true ;
55
- }
56
40
if ( selectedItems . length > 0 && ! selectionMode ?. isEnabled ) {
57
41
turnOnMobileSelectionMode ( ) ;
58
- } else if ( selectedItems . length === 0 && selectionMode ?. isEnabled && ! wasSelectionOnRef . current ) {
59
- turnOffMobileSelectionMode ( ) ;
60
42
}
61
- } , [ sections , selectionMode , isSmallScreenWidth , isSelected ] ) ;
62
-
63
- useEffect (
64
- ( ) => ( ) => {
65
- if ( selectionRef . current !== 0 ) {
66
- return ;
67
- }
68
- turnOffMobileSelectionMode ( ) ;
69
- } ,
70
- [ ] ,
71
- ) ;
43
+ } , [ sections , selectionMode , isSmallScreenWidth ] ) ;
72
44
73
45
const handleLongPressRow = ( item : TItem ) => {
74
46
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
0 commit comments