1- import React , { useMemo } from 'react' ;
1+ import React , { useCallback , useMemo , useRef } from 'react' ;
22import { View } from 'react-native' ;
33import type { ValueOf } from 'type-fest' ;
4+ import { getButtonRole } from '@components/Button/utils' ;
5+ import OfflineWithFeedback from '@components/OfflineWithFeedback' ;
6+ import { PressableWithFeedback } from '@components/Pressable' ;
47import type { SearchGroupBy } from '@components/Search/types' ;
5- import BaseListItem from '@components/SelectionList/BaseListItem' ;
68import type {
79 ListItem ,
810 TransactionCardGroupListItemType ,
@@ -15,8 +17,11 @@ import type {
1517import Text from '@components/Text' ;
1618import TransactionItemRow from '@components/TransactionItemRow' ;
1719import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle' ;
20+ import useHover from '@hooks/useHover' ;
1821import useLocalize from '@hooks/useLocalize' ;
1922import useResponsiveLayout from '@hooks/useResponsiveLayout' ;
23+ import useStyleUtils from '@hooks/useStyleUtils' ;
24+ import useSyncFocus from '@hooks/useSyncFocus' ;
2025import useTheme from '@hooks/useTheme' ;
2126import useThemeStyles from '@hooks/useThemeStyles' ;
2227import { getReportIDForTransaction } from '@libs/MoneyRequestReportUtils' ;
@@ -71,16 +76,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
7176 backgroundColor : theme . highlightBG ,
7277 } ) ;
7378
74- const listItemPressableStyle = [
75- styles . selectionListPressableItemWrapper ,
76- styles . pv2 ,
77- styles . ph0 ,
78- styles . overflowHidden ,
79- // Removing background style because they are added to the parent OpacityView via animatedHighlightStyle
80- styles . bgTransparent ,
81- item . isSelected && styles . activeComponentBG ,
82- styles . mh0 ,
83- ] ;
79+ const pressableStyle = [ styles . transactionGroupListItemStyle , item . isSelected && styles . activeComponentBG ] ;
8480
8581 const openReportInRHP = ( transactionItem : TransactionListItemType ) => {
8682 const backTo = Navigation . getActiveRoute ( ) ;
@@ -112,7 +108,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
112108 COLUMNS . ACTION ,
113109 ] satisfies Array < ValueOf < typeof COLUMNS > > ;
114110
115- const getHeader = ( isHovered : boolean ) => {
111+ const getHeader = useMemo ( ( ) => {
116112 const headers : Record < SearchGroupBy , React . JSX . Element > = {
117113 [ CONST . SEARCH . GROUP_BY . REPORTS ] : (
118114 < ReportListItemHeader
@@ -121,7 +117,6 @@ function TransactionGroupListItem<TItem extends ListItem>({
121117 onSelectRow = { onSelectRow }
122118 onCheckboxPress = { onCheckboxPress }
123119 isDisabled = { isDisabledOrEmpty }
124- isHovered = { isHovered }
125120 isFocused = { isFocused }
126121 canSelectMultiple = { canSelectMultiple }
127122 />
@@ -139,7 +134,6 @@ function TransactionGroupListItem<TItem extends ListItem>({
139134 card = { groupItem as TransactionCardGroupListItemType }
140135 onCheckboxPress = { onCheckboxPress }
141136 isDisabled = { isDisabledOrEmpty }
142- isHovered = { isHovered }
143137 isFocused = { isFocused }
144138 canSelectMultiple = { canSelectMultiple }
145139 />
@@ -151,31 +145,47 @@ function TransactionGroupListItem<TItem extends ListItem>({
151145 }
152146
153147 return headers [ groupBy ] ;
154- } ;
148+ } , [ groupItem , policy , onSelectRow , onCheckboxPress , isDisabledOrEmpty , isFocused , canSelectMultiple , groupBy ] ) ;
149+
150+ const StyleUtils = useStyleUtils ( ) ;
151+ const { hovered, bind} = useHover ( ) ;
152+ const pressableRef = useRef < View > ( null ) ;
153+
154+ const onPress = useCallback ( ( ) => {
155+ onSelectRow ( item ) ;
156+ } , [ item , onSelectRow ] ) ;
157+
158+ const onLongPress = useCallback ( ( ) => {
159+ onLongPressRow ?.( item ) ;
160+ } , [ item , onLongPressRow ] ) ;
161+
162+ useSyncFocus ( pressableRef , ! ! isFocused , shouldSyncFocus ) ;
155163
156164 return (
157- < BaseListItem
158- item = { item }
159- pressableStyle = { listItemPressableStyle }
160- wrapperStyle = { [ styles . flexRow , styles . flex1 , styles . justifyContentBetween , styles . userSelectNone , styles . alignItemsCenter ] }
161- containerStyle = { [ styles . mb2 ] }
162- isFocused = { isFocused }
163- isDisabled = { isDisabled }
164- showTooltip = { showTooltip }
165- canSelectMultiple = { canSelectMultiple }
166- onSelectRow = { onSelectRow }
167- onLongPressRow = { onLongPressRow }
168- pendingAction = { item . pendingAction }
169- keyForList = { item . keyForList }
170- onFocus = { onFocus }
171- shouldShowBlueBorderOnFocus
172- shouldSyncFocus = { shouldSyncFocus }
173- hoverStyle = { item . isSelected && styles . activeComponentBG }
174- pressableWrapperStyle = { [ styles . mh5 , animatedHighlightStyle ] }
175- >
176- { ( hovered ) => (
177- < View style = { [ styles . flex1 ] } >
178- { getHeader ( hovered ) }
165+ < OfflineWithFeedback pendingAction = { item . pendingAction } >
166+ < PressableWithFeedback
167+ onMouseEnter = { bind . onMouseEnter }
168+ onMouseLeave = { bind . onMouseLeave }
169+ ref = { pressableRef }
170+ onLongPress = { onLongPress }
171+ onPress = { onPress }
172+ disabled = { isDisabled && ! item . isSelected }
173+ accessibilityLabel = { item . text ?? '' }
174+ role = { getButtonRole ( true ) }
175+ isNested
176+ hoverStyle = { [ ! item . isDisabled && styles . hoveredComponentBG , item . isSelected && styles . activeComponentBG ] }
177+ dataSet = { { [ CONST . SELECTION_SCRAPER_HIDDEN_ELEMENT ] : true , [ CONST . INNER_BOX_SHADOW_ELEMENT ] : false } }
178+ onMouseDown = { ( e ) => e . preventDefault ( ) }
179+ id = { item . keyForList ?? '' }
180+ style = { [
181+ pressableStyle ,
182+ isFocused && StyleUtils . getItemBackgroundColorStyle ( ! ! item . isSelected , ! ! isFocused , ! ! item . isDisabled , theme . activeComponentBG , theme . hoverComponentBG ) ,
183+ ] }
184+ onFocus = { onFocus }
185+ wrapperStyle = { [ styles . mb2 , styles . mh5 , animatedHighlightStyle , styles . userSelectNone ] }
186+ >
187+ < View style = { styles . flex1 } >
188+ { getHeader }
179189 { isEmpty ? (
180190 < View style = { [ styles . alignItemsCenter , styles . justifyContentCenter , styles . mnh13 ] } >
181191 < Text
@@ -187,32 +197,31 @@ function TransactionGroupListItem<TItem extends ListItem>({
187197 </ View >
188198 ) : (
189199 groupItem . transactions . map ( ( transaction ) => (
190- < View key = { transaction . transactionID } >
191- < TransactionItemRow
192- transactionItem = { transaction }
193- isSelected = { ! ! transaction . isSelected }
194- dateColumnSize = { dateColumnSize }
195- amountColumnSize = { amountColumnSize }
196- taxAmountColumnSize = { taxAmountColumnSize }
197- shouldShowTooltip = { showTooltip }
198- shouldUseNarrowLayout = { ! isLargeScreenWidth }
199- shouldShowCheckbox = { ! ! canSelectMultiple }
200- onCheckboxPress = { ( ) => onCheckboxPress ?.( transaction as unknown as TItem ) }
201- columns = { columns }
202- onButtonPress = { ( ) => {
203- openReportInRHP ( transaction ) ;
204- } }
205- isParentHovered = { hovered }
206- columnWrapperStyles = { [ styles . ph3 , styles . pv1Half ] }
207- isReportItemChild
208- isInSingleTransactionReport = { groupItem . transactions . length === 1 }
209- />
210- </ View >
200+ < TransactionItemRow
201+ key = { transaction . transactionID }
202+ transactionItem = { transaction }
203+ isSelected = { ! ! transaction . isSelected }
204+ dateColumnSize = { dateColumnSize }
205+ amountColumnSize = { amountColumnSize }
206+ taxAmountColumnSize = { taxAmountColumnSize }
207+ shouldShowTooltip = { showTooltip }
208+ shouldUseNarrowLayout = { ! isLargeScreenWidth }
209+ shouldShowCheckbox = { ! ! canSelectMultiple }
210+ onCheckboxPress = { ( ) => onCheckboxPress ?.( transaction as unknown as TItem ) }
211+ columns = { columns }
212+ onButtonPress = { ( ) => {
213+ openReportInRHP ( transaction ) ;
214+ } }
215+ isParentHovered = { hovered }
216+ columnWrapperStyles = { [ styles . ph3 , styles . pv1Half ] }
217+ isReportItemChild
218+ isInSingleTransactionReport = { groupItem . transactions . length === 1 }
219+ />
211220 ) )
212221 ) }
213222 </ View >
214- ) }
215- </ BaseListItem >
223+ </ PressableWithFeedback >
224+ </ OfflineWithFeedback >
216225 ) ;
217226}
218227
0 commit comments