Skip to content

Commit e350b5b

Browse files
committed
Extract getSelectedBorderBottomStyle to deduplicate border color logic
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
1 parent bbe1f57 commit e350b5b

8 files changed

Lines changed: 18 additions & 23 deletions

File tree

src/components/MoneyRequestReportView/MoneyRequestReportTransactionItem.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
1010
import useLocalize from '@hooks/useLocalize';
1111
import useResponsiveLayout from '@hooks/useResponsiveLayout';
1212
import useResponsiveLayoutOnWideRHP from '@hooks/useResponsiveLayoutOnWideRHP';
13+
import useStyleUtils from '@hooks/useStyleUtils';
1314
import useTheme from '@hooks/useTheme';
1415
import useThemeStyles from '@hooks/useThemeStyles';
1516
import useTransactionViolations from '@hooks/useTransactionViolations';
@@ -98,6 +99,7 @@ function MoneyRequestReportTransactionItem({
9899
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
99100
const {isSmallScreenWidth, isMediumScreenWidth} = useResponsiveLayout();
100101
const {shouldUseNarrowLayout} = useResponsiveLayoutOnWideRHP();
102+
const StyleUtils = useStyleUtils();
101103
const theme = useTheme();
102104
const isPendingDelete = isTransactionPendingDelete(transaction);
103105
const pendingAction = getTransactionPendingAction(transaction);
@@ -146,11 +148,7 @@ function MoneyRequestReportTransactionItem({
146148
}}
147149
disabled={isTransactionPendingDelete(transaction)}
148150
ref={viewRef}
149-
wrapperStyle={[
150-
animatedHighlightStyle,
151-
styles.userSelectNone,
152-
shouldUseNarrowLayout && !isLastItem && {...styles.borderBottom, borderColor: isSelected ? theme.buttonHoveredBG : theme.border},
153-
]}
151+
wrapperStyle={[animatedHighlightStyle, styles.userSelectNone, shouldUseNarrowLayout && !isLastItem && StyleUtils.getSelectedBorderBottomStyle(isSelected)]}
154152
>
155153
{({hovered}) => (
156154
<TransactionItemRow

src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -671,17 +671,7 @@ function MoneyRequestReportTransactionList({
671671

672672
const tableHeaderContent = (
673673
<OfflineWithFeedback pendingAction={reportPendingAction}>
674-
<View
675-
style={[
676-
styles.dFlex,
677-
styles.flexRow,
678-
styles.pl5,
679-
styles.pr16,
680-
styles.alignItemsCenter,
681-
styles.borderBottom,
682-
selectedTransactionIDs.length > 0 && {borderColor: theme.buttonHoveredBG},
683-
]}
684-
>
674+
<View style={[styles.dFlex, styles.flexRow, styles.pl5, styles.pr16, styles.alignItemsCenter, StyleUtils.getSelectedBorderBottomStyle(selectedTransactionIDs.length > 0)]}>
685675
<View style={[styles.dFlex, styles.flexRow, styles.pv2, styles.pr4, StyleUtils.getPaddingLeft(variables.w12)]}>
686676
<Checkbox
687677
onPress={() => {

src/components/Search/SearchList/ListItem/ExpenseReportListItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ function ExpenseReportListItem<TItem extends ListItem>({
180180
styles.mh0,
181181
isPendingDelete && styles.cursorDisabled,
182182
isLargeScreenWidth ? StyleUtils.getSearchTableRowPressableStyle(!!isLastItem, item.isSelected, {vertical: variables.tableRowPaddingVertical}) : styles.noBorderRadius,
183-
!isLargeScreenWidth && !isLastItem && {...styles.borderBottom, borderColor: item.isSelected ? theme.buttonHoveredBG : theme.border},
183+
!isLargeScreenWidth && !isLastItem && StyleUtils.getSelectedBorderBottomStyle(item.isSelected),
184184
!isLargeScreenWidth && isFirstItem && [styles.searchTableTopRadius, styles.overflowHidden],
185185
!isLargeScreenWidth && isLastItem && [styles.searchTableBottomRadius, styles.overflowHidden],
186186
],
187-
[styles, item.isSelected, isLargeScreenWidth, isFirstItem, isLastItem, isPendingDelete, StyleUtils, theme.border, theme.buttonHoveredBG],
187+
[styles, item.isSelected, isLargeScreenWidth, isFirstItem, isLastItem, isPendingDelete, StyleUtils],
188188
);
189189

190190
const listItemWrapperStyle = useMemo(

src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
1414
import useLocalize from '@hooks/useLocalize';
1515
import useOnyx from '@hooks/useOnyx';
1616
import useResponsiveLayout from '@hooks/useResponsiveLayout';
17+
import useStyleUtils from '@hooks/useStyleUtils';
1718
import useTheme from '@hooks/useTheme';
1819
import useThemeStyles from '@hooks/useThemeStyles';
1920
import useWindowDimensions from '@hooks/useWindowDimensions';
@@ -92,6 +93,7 @@ function TransactionGroupListExpanded<TItem extends ListItem>({
9293
const shouldShowLoadingOnSearch = !!(!transactions?.length && transactionsSnapshotMetadata?.isLoading) || currentOffset > 0;
9394
const shouldDisplayLoadingIndicator = !isExpenseReportType && !!transactionsSnapshotMetadata?.isLoading && shouldShowLoadingOnSearch;
9495
const {isLargeScreenWidth} = useResponsiveLayout();
96+
const StyleUtils = useStyleUtils();
9597

9698
const isAmountColumnWide = transactions.some((transaction) => transaction.isAmountColumnWide);
9799
const isTaxAmountColumnWide = transactions.some((transaction) => transaction.isTaxAmountColumnWide);
@@ -224,7 +226,7 @@ function TransactionGroupListExpanded<TItem extends ListItem>({
224226
isActionColumnWide={isActionColumnWide}
225227
/>
226228
</View>
227-
<View style={[styles.borderBottom, styles.ml3, styles.mr3, visibleTransactions.at(0)?.isSelected && {borderColor: theme.buttonHoveredBG}]} />
229+
<View style={[StyleUtils.getSelectedBorderBottomStyle(visibleTransactions.at(0)?.isSelected), styles.ml3, styles.mr3]} />
228230
</>
229231
)}
230232
{visibleTransactions.map((transaction, index) => {

src/components/Search/SearchList/ListItem/TransactionGroupListItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
214214
...(isLastItem ? styles.searchTableBottomRadius : {}),
215215
},
216216
isItemSelected && styles.activeComponentBG,
217-
!isLargeScreenWidth && !isLastItem && {...styles.borderBottom, borderColor: isItemSelected ? theme.buttonHoveredBG : theme.border},
217+
!isLargeScreenWidth && !isLastItem && StyleUtils.getSelectedBorderBottomStyle(isItemSelected),
218218
];
219219
const pressableRef = useRef<View>(null);
220220

src/components/Search/SearchList/ListItem/TransactionListItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function TransactionListItem<TItem extends ListItem>({
122122
}
123123
: {...styles.flexColumn, ...styles.alignItemsStretch},
124124
isLargeScreenWidth && isLastItem && [styles.searchTableBottomRadius, styles.overflowHidden],
125-
!isLargeScreenWidth && !isLastItem && {...styles.borderBottom, borderColor: item.isSelected ? theme.buttonHoveredBG : theme.border},
125+
!isLargeScreenWidth && !isLastItem && StyleUtils.getSelectedBorderBottomStyle(item.isSelected),
126126
!isLargeScreenWidth && isFirstItem && [styles.searchTableTopRadius, styles.overflowHidden],
127127
!isLargeScreenWidth && isLastItem && [styles.searchTableBottomRadius, styles.overflowHidden],
128128
];

src/components/TransactionItemRow/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ function TransactionItemRow({
805805
{!!shouldShowBottomBorder && (
806806
<View style={bgActiveStyles}>
807807
<View style={styles.ph3}>
808-
<View style={[styles.borderBottom, isSelected && {borderColor: theme.buttonHoveredBG}]} />
808+
<View style={[StyleUtils.getSelectedBorderBottomStyle(isSelected)]} />
809809
</View>
810810
</View>
811811
)}
@@ -880,7 +880,7 @@ function TransactionItemRow({
880880
{!!shouldShowBottomBorder && (
881881
<View style={bgActiveStyles}>
882882
<View style={styles.ph3}>
883-
<View style={[styles.borderBottom, isSelected && {borderColor: theme.buttonHoveredBG}]} />
883+
<View style={[StyleUtils.getSelectedBorderBottomStyle(isSelected)]} />
884884
</View>
885885
</View>
886886
)}

src/styles/utils/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,11 @@ const createStyleUtils = (theme: ThemeColors, styles: ThemeStyles) => ({
18451845
...(padding?.horizontal !== undefined && {paddingHorizontal: padding.horizontal}),
18461846
}),
18471847

1848+
getSelectedBorderBottomStyle: (isSelected?: boolean): ViewStyle => ({
1849+
...styles.borderBottom,
1850+
borderColor: isSelected ? theme.buttonHoveredBG : theme.border,
1851+
}),
1852+
18481853
getSearchTableHighlightBorderRadius: (isLargeScreenWidth: boolean): number => (isLargeScreenWidth ? 0 : variables.componentBorderRadius),
18491854

18501855
getReportTableColumnStyles: (columnName: string, options: GetReportTableColumnStylesParams = {}): ViewStyle => {

0 commit comments

Comments
 (0)