Skip to content

Commit fcbe961

Browse files
committed
fix UnreportedExpenseListItem style
1 parent 4f305ce commit fcbe961

1 file changed

Lines changed: 40 additions & 28 deletions

File tree

src/pages/UnreportedExpenseListItem.tsx

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,65 @@
1-
import React, {useState} from 'react';
2-
import {View} from 'react-native';
3-
import BaseListItem from '@components/SelectionList/BaseListItem';
1+
import React, {useRef, useState} from 'react';
2+
import type {View} from 'react-native';
3+
import {getButtonRole} from '@components/Button/utils';
4+
import OfflineWithFeedback from '@components/OfflineWithFeedback';
5+
import {PressableWithFeedback} from '@components/Pressable';
46
import type {ListItem, ListItemProps, TransactionListItemType} from '@components/SelectionList/types';
57
import TransactionItemRow from '@components/TransactionItemRow';
68
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
9+
import useStyleUtils from '@hooks/useStyleUtils';
10+
import useSyncFocus from '@hooks/useSyncFocus';
711
import useTheme from '@hooks/useTheme';
812
import useThemeStyles from '@hooks/useThemeStyles';
913
import variables from '@styles/variables';
1014
import CONST from '@src/CONST';
1115

12-
function UnreportedExpenseListItem<TItem extends ListItem>({item, isFocused, showTooltip, isDisabled, canSelectMultiple, onFocus, shouldSyncFocus, onSelectRow}: ListItemProps<TItem>) {
16+
function UnreportedExpenseListItem<TItem extends ListItem>({item, isFocused, showTooltip, isDisabled, onFocus, shouldSyncFocus, onSelectRow}: ListItemProps<TItem>) {
1317
const styles = useThemeStyles();
1418
const transactionItem = item as unknown as TransactionListItemType;
1519
const [isSelected, setIsSelected] = useState<boolean>(false);
1620
const theme = useTheme();
17-
const backgroundColor = isSelected ? styles.buttonDefaultBG : styles.highlightBG;
1821

19-
const hoveredTransactionStyles = useAnimatedHighlightStyle({
22+
const pressableStyle = [styles.transactionListItemStyle, item.isSelected && styles.activeComponentBG];
23+
24+
const animatedHighlightStyle = useAnimatedHighlightStyle({
2025
borderRadius: variables.componentBorderRadius,
2126
shouldHighlight: item?.shouldAnimateInHighlight ?? false,
2227
highlightColor: theme.messageHighlightBG,
2328
backgroundColor: theme.highlightBG,
2429
});
30+
const StyleUtils = useStyleUtils();
31+
const pressableRef = useRef<View>(null);
32+
33+
useSyncFocus(pressableRef, !!isFocused, shouldSyncFocus);
2534

2635
return (
27-
<BaseListItem
28-
item={item}
29-
isFocused={isFocused}
30-
isDisabled={isDisabled}
31-
showTooltip={showTooltip}
32-
canSelectMultiple={canSelectMultiple}
33-
pendingAction={item.pendingAction}
34-
keyForList={item.keyForList}
35-
onFocus={onFocus}
36-
shouldSyncFocus={shouldSyncFocus}
37-
pressableWrapperStyle={[hoveredTransactionStyles, backgroundColor]}
38-
onSelectRow={() => {
39-
onSelectRow(item);
40-
setIsSelected((val) => !val);
41-
}}
42-
containerStyle={[styles.p3, styles.mbn4, styles.expenseWidgetRadius]}
43-
hoverStyle={[styles.borderRadiusComponentNormal]}
44-
>
45-
<View style={[styles.flexRow, styles.alignItemsCenter, styles.justifyContentBetween]}>
36+
<OfflineWithFeedback pendingAction={item.pendingAction}>
37+
<PressableWithFeedback
38+
ref={pressableRef}
39+
onPress={() => {
40+
onSelectRow(item);
41+
setIsSelected((val) => !val);
42+
}}
43+
disabled={isDisabled && !item.isSelected}
44+
accessibilityLabel={item.text ?? ''}
45+
role={getButtonRole(true)}
46+
isNested
47+
onMouseDown={(e) => e.preventDefault()}
48+
hoverStyle={[!item.isDisabled && styles.hoveredComponentBG, item.isSelected && styles.activeComponentBG]}
49+
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true, [CONST.INNER_BOX_SHADOW_ELEMENT]: false}}
50+
id={item.keyForList ?? ''}
51+
style={[
52+
pressableStyle,
53+
isFocused && StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, !!isFocused, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG),
54+
]}
55+
onFocus={onFocus}
56+
wrapperStyle={[styles.mb2, styles.mh5, styles.flex1, animatedHighlightStyle, styles.userSelectNone]}
57+
>
4658
<TransactionItemRow
4759
transactionItem={transactionItem}
4860
shouldUseNarrowLayout
4961
isSelected={isSelected}
50-
shouldShowTooltip={false}
62+
shouldShowTooltip={showTooltip}
5163
dateColumnSize={CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL}
5264
amountColumnSize={CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL}
5365
taxAmountColumnSize={CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL}
@@ -57,8 +69,8 @@ function UnreportedExpenseListItem<TItem extends ListItem>({item, isFocused, sho
5769
}}
5870
shouldShowCheckbox
5971
/>
60-
</View>
61-
</BaseListItem>
72+
</PressableWithFeedback>
73+
</OfflineWithFeedback>
6274
);
6375
}
6476

0 commit comments

Comments
 (0)