-
Notifications
You must be signed in to change notification settings - Fork 3.9k
perf: Split TransactionItemRow into narrow and wide versions #89120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
luacmartins
merged 18 commits into
Expensify:main
from
software-mansion-labs:perf/split-transaction-item-row
May 13, 2026
Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
87efc50
Split TransactionItemRow into narrow and wide versions
jmusial 6bb3918
Merge branch 'main' into perf/split-transaction-item-row
jmusial 500f134
update structure
jmusial 6e0a385
useDefeerredValue
jmusial 7d8ee4f
fix lint
jmusial 6dc07ff
Bring back conditional styles.mlAuto
OlGierd03 11b6e5f
Add comments explaining why the rule is disabled
OlGierd03 82aaf30
Narrow TransactionItemRowNarrowProps type
OlGierd03 d674ba2
Merge main and resolve conflicts
OlGierd03 81571af
Pass isSelected to UserInfoAndActionButtonRow - omitted during the ma…
OlGierd03 1a177fb
Merge branch 'main' into perf/split-transaction-item-row
OlGierd03 f451903
Avoid layout shift on rows without RBR content
OlGierd03 4da0f5d
Merge branch 'main' into perf/split-transaction-item-row
jmusial f02178c
add merge changes
jmusial a7cba6e
change action cell deferring as per discussion in #89083
jmusial 082cbab
Merge branch 'main' into perf/split-transaction-item-row
jmusial e05d79b
fix copilot comments
jmusial c8fe540
Merge branch 'main' into perf/split-transaction-item-row
jmusial File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/components/Search/SearchList/ListItem/ActionCell/DeferredActionCell.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import React, {useDeferredValue} from 'react'; | ||
| import Button from '@components/Button'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import CONST from '@src/CONST'; | ||
| import ActionCell from '.'; | ||
| import type {ActionCellProps} from '.'; | ||
| import actionTranslationsMap from './actionTranslationsMap'; | ||
|
|
||
| function DeferredActionCell(actionCellProps: ActionCellProps) { | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const shouldRender = useDeferredValue(true, false); | ||
|
|
||
| if (!shouldRender) { | ||
| const action = actionCellProps.action ?? CONST.SEARCH.ACTION_TYPES.VIEW; | ||
| const shouldUseViewAction = action === CONST.SEARCH.ACTION_TYPES.VIEW || action === CONST.SEARCH.ACTION_TYPES.PAID || action === CONST.SEARCH.ACTION_TYPES.DONE; | ||
| const isSuccess = !shouldUseViewAction && action !== CONST.SEARCH.ACTION_TYPES.UNDELETE; | ||
| const text = shouldUseViewAction ? translate(actionTranslationsMap[CONST.SEARCH.ACTION_TYPES.VIEW]) : translate(actionTranslationsMap[action]); | ||
|
|
||
| return ( | ||
| <Button | ||
| text={text} | ||
| small={!actionCellProps.extraSmall} | ||
| extraSmall={actionCellProps.extraSmall} | ||
| style={[styles.w100, styles.pointerEventsNone]} | ||
| isDisabled | ||
| success={isSuccess} | ||
| isNested | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| // Deferred wrapper intentionally forwards all props to the underlying component | ||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| return <ActionCell {...actionCellProps} />; | ||
| } | ||
|
|
||
| export default DeferredActionCell; |
287 changes: 0 additions & 287 deletions
287
src/components/Search/SearchList/ListItem/TransactionListItem.tsx
This file was deleted.
Oops, something went wrong.
137 changes: 137 additions & 0 deletions
137
src/components/Search/SearchList/ListItem/TransactionListItem/TransactionListItemNarrow.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| import React, {useRef} from 'react'; | ||
| import type {View} from 'react-native'; | ||
| import {getButtonRole} from '@components/Button/utils'; | ||
| import OfflineWithFeedback from '@components/OfflineWithFeedback'; | ||
| import PressableWithFeedback from '@components/Pressable/PressableWithFeedback'; | ||
| import UserInfoAndActionButtonRow from '@components/Search/SearchList/ListItem/UserInfoAndActionButtonRow'; | ||
| import type {ListItem} from '@components/SelectionList/types'; | ||
| import TransactionItemRow from '@components/TransactionItemRow'; | ||
| import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle'; | ||
| import useStyleUtils from '@hooks/useStyleUtils'; | ||
| import useSyncFocus from '@hooks/useSyncFocus'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import CONST from '@src/CONST'; | ||
| import type {TransactionListItemNarrowProps} from './types'; | ||
|
|
||
| function TransactionListItemNarrow<TItem extends ListItem>({ | ||
| item, | ||
| transactionItem, | ||
| isDeletedTransaction, | ||
| isFocused, | ||
| showTooltip, | ||
| isDisabled, | ||
| canSelectMultiple, | ||
| onSelectRow, | ||
| onCheckboxPress, | ||
| onFocus, | ||
| onLongPressRow, | ||
| shouldSyncFocus, | ||
| columns, | ||
| isLoading, | ||
| isActionLoading, | ||
| isLastItem, | ||
| isFirstItem, | ||
| transactionViolations, | ||
| handleActionButtonPress, | ||
| transactionPreviewData, | ||
| exportedReportActions, | ||
| nonPersonalAndWorkspaceCards, | ||
| policyForMovingExpenses, | ||
| }: TransactionListItemNarrowProps<TItem>) { | ||
| const styles = useThemeStyles(); | ||
| const theme = useTheme(); | ||
| const StyleUtils = useStyleUtils(); | ||
| const pressableRef = useRef<View>(null); | ||
| useSyncFocus(pressableRef, !!isFocused, shouldSyncFocus); | ||
|
|
||
| const pressableStyle = [ | ||
| styles.transactionListItemStyle, | ||
| styles.p4, | ||
| styles.noBorderRadius, | ||
| item.isSelected && styles.activeComponentBG, | ||
| {...styles.flexColumn, ...styles.alignItemsStretch}, | ||
| ]; | ||
|
|
||
| const animatedHighlightStyle = useAnimatedHighlightStyle({ | ||
| borderRadius: 0, | ||
| shouldHighlight: item?.shouldAnimateInHighlight ?? false, | ||
| highlightColor: theme.messageHighlightBG, | ||
| backgroundColor: item.isSelected ? theme.activeComponentBG : theme.highlightBG, | ||
| shouldApplyOtherStyles: true, | ||
| }); | ||
|
|
||
| return ( | ||
| <OfflineWithFeedback pendingAction={item.pendingAction}> | ||
| <PressableWithFeedback | ||
| ref={pressableRef} | ||
| onLongPress={() => onLongPressRow?.(item)} | ||
| onPress={isDeletedTransaction && !canSelectMultiple ? undefined : () => onSelectRow(item, transactionPreviewData)} | ||
| disabled={isDisabled && !item.isSelected} | ||
| accessibilityLabel={item.text ?? ''} | ||
| role={!isDeletedTransaction ? getButtonRole(true) : 'none'} | ||
| isNested | ||
| onMouseDown={(e) => e.preventDefault()} | ||
| hoverStyle={[!item.isDisabled && styles.hoveredComponentBG, item.isSelected && styles.activeComponentBG]} | ||
| dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true, [CONST.INNER_BOX_SHADOW_ELEMENT]: false}} | ||
| id={item.keyForList ?? ''} | ||
| sentryLabel={CONST.SENTRY_LABEL.SEARCH.TRANSACTION_LIST_ITEM} | ||
| style={[ | ||
| pressableStyle, | ||
| isFocused && StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, !!isFocused, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG), | ||
| isDeletedTransaction && styles.cursorDefault, | ||
| ]} | ||
| onFocus={onFocus} | ||
| wrapperStyle={[ | ||
| styles.mh5, | ||
| styles.flex1, | ||
| animatedHighlightStyle, | ||
| styles.userSelectNone, | ||
| isFirstItem && [styles.searchTableTopRadius, styles.overflowHidden, styles.searchTableTopRadius], | ||
| isLastItem && [styles.searchTableBottomRadius, styles.overflowHidden, styles.searchTableBottomRadius], | ||
| !isLastItem && StyleUtils.getSelectedBorderBottomStyle(item.isSelected), | ||
| ]} | ||
| > | ||
| {() => ( | ||
| <> | ||
| <UserInfoAndActionButtonRow | ||
| item={transactionItem} | ||
| shouldShowUserInfo={!isDeletedTransaction && !!transactionItem?.from} | ||
| stateNum={transactionItem.report?.stateNum} | ||
| statusNum={transactionItem.report?.statusNum} | ||
| isSelected={!!transactionItem.isSelected} | ||
| /> | ||
| <TransactionItemRow | ||
| transactionItem={transactionItem} | ||
| report={transactionItem.report} | ||
| policy={transactionItem.policy} | ||
| shouldShowTooltip={showTooltip} | ||
| onButtonPress={handleActionButtonPress} | ||
| onCheckboxPress={() => onCheckboxPress?.(item)} | ||
| shouldUseNarrowLayout | ||
| isLargeScreenWidth={false} | ||
| columns={columns} | ||
| isActionLoading={isLoading ?? isActionLoading} | ||
| isSelected={!!transactionItem.isSelected} | ||
| isDisabled={!!isDisabled} | ||
| dateColumnSize={CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL} | ||
| amountColumnSize={CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL} | ||
| taxAmountColumnSize={CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL} | ||
| shouldShowCheckbox={!!canSelectMultiple} | ||
| checkboxSentryLabel={CONST.SENTRY_LABEL.SEARCH.TRANSACTION_LIST_ITEM_CHECKBOX} | ||
| style={[styles.p3, styles.pv2, styles.p0, styles.pt3, isLastItem ? styles.searchTableBottomRadius : styles.noBorderRadius]} | ||
| violations={transactionViolations} | ||
| onArrowRightPress={isDeletedTransaction ? undefined : () => onSelectRow(item, transactionPreviewData)} | ||
| isHover={false} | ||
| nonPersonalAndWorkspaceCards={nonPersonalAndWorkspaceCards} | ||
| reportActions={exportedReportActions} | ||
| policyForMovingExpenses={policyForMovingExpenses} | ||
| /> | ||
| </> | ||
| )} | ||
| </PressableWithFeedback> | ||
| </OfflineWithFeedback> | ||
| ); | ||
| } | ||
|
|
||
| export default TransactionListItemNarrow; | ||
140 changes: 140 additions & 0 deletions
140
src/components/Search/SearchList/ListItem/TransactionListItem/TransactionListItemWide.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import React, {useRef} from 'react'; | ||
| import type {View} from 'react-native'; | ||
| import {getButtonRole} from '@components/Button/utils'; | ||
| import OfflineWithFeedback from '@components/OfflineWithFeedback'; | ||
| import PressableWithFeedback from '@components/Pressable/PressableWithFeedback'; | ||
| import type {ListItem} from '@components/SelectionList/types'; | ||
| import TransactionItemRow from '@components/TransactionItemRow'; | ||
| import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle'; | ||
| import useStyleUtils from '@hooks/useStyleUtils'; | ||
| import useSyncFocus from '@hooks/useSyncFocus'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import CONST from '@src/CONST'; | ||
| import type {TransactionListItemWideProps} from './types'; | ||
|
|
||
| function TransactionListItemWide<TItem extends ListItem>({ | ||
| item, | ||
| transactionItem, | ||
| isDeletedTransaction, | ||
| isFocused, | ||
| showTooltip, | ||
| isDisabled, | ||
| canSelectMultiple, | ||
| onSelectRow, | ||
| onCheckboxPress, | ||
| onFocus, | ||
| onLongPressRow, | ||
| shouldSyncFocus, | ||
| columns, | ||
| isLoading, | ||
| isActionLoading, | ||
| isLastItem, | ||
| transactionViolations, | ||
| handleActionButtonPress, | ||
| transactionPreviewData, | ||
| exportedReportActions, | ||
| nonPersonalAndWorkspaceCards, | ||
| policyForMovingExpenses, | ||
| }: TransactionListItemWideProps<TItem>) { | ||
| const styles = useThemeStyles(); | ||
| const theme = useTheme(); | ||
| const StyleUtils = useStyleUtils(); | ||
| const pressableRef = useRef<View>(null); | ||
| useSyncFocus(pressableRef, !!isFocused, shouldSyncFocus); | ||
|
|
||
| const amountColumnSize = transactionItem.isAmountColumnWide ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL; | ||
| const taxAmountColumnSize = transactionItem.isTaxAmountColumnWide ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL; | ||
| const dateColumnSize = transactionItem.shouldShowYear ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL; | ||
| const submittedColumnSize = transactionItem.shouldShowYearSubmitted ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL; | ||
| const approvedColumnSize = transactionItem.shouldShowYearApproved ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL; | ||
| const postedColumnSize = transactionItem.shouldShowYearPosted ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL; | ||
| const exportedColumnSize = transactionItem.shouldShowYearExported ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL; | ||
|
|
||
| const pressableStyle = [ | ||
| styles.transactionListItemStyle, | ||
| item.isSelected && styles.activeComponentBG, | ||
| { | ||
| ...styles.flexRow, | ||
| ...styles.justifyContentBetween, | ||
| ...styles.alignItemsCenter, | ||
| ...StyleUtils.getSearchTableRowPressableStyle(!!isLastItem, item.isSelected), | ||
| }, | ||
| ]; | ||
|
|
||
| const animatedHighlightStyle = useAnimatedHighlightStyle({ | ||
| borderRadius: 0, | ||
| shouldHighlight: item?.shouldAnimateInHighlight ?? false, | ||
| highlightColor: theme.messageHighlightBG, | ||
| backgroundColor: item.isSelected ? theme.activeComponentBG : theme.highlightBG, | ||
| shouldApplyOtherStyles: false, | ||
| }); | ||
|
|
||
| return ( | ||
| <OfflineWithFeedback pendingAction={item.pendingAction}> | ||
| <PressableWithFeedback | ||
| ref={pressableRef} | ||
| onLongPress={() => onLongPressRow?.(item)} | ||
| onPress={isDeletedTransaction && !canSelectMultiple ? undefined : () => onSelectRow(item, transactionPreviewData)} | ||
| disabled={isDisabled && !item.isSelected} | ||
| accessibilityLabel={item.text ?? ''} | ||
| role={!isDeletedTransaction ? getButtonRole(true) : 'none'} | ||
| isNested | ||
| onMouseDown={(e) => e.preventDefault()} | ||
| hoverStyle={[!item.isDisabled && styles.hoveredComponentBG, item.isSelected && styles.activeComponentBG]} | ||
| dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true, [CONST.INNER_BOX_SHADOW_ELEMENT]: false}} | ||
| id={item.keyForList ?? ''} | ||
| sentryLabel={CONST.SENTRY_LABEL.SEARCH.TRANSACTION_LIST_ITEM} | ||
| style={[ | ||
| pressableStyle, | ||
| isFocused && StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, !!isFocused, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG), | ||
| isDeletedTransaction && styles.cursorDefault, | ||
| ]} | ||
| onFocus={onFocus} | ||
| wrapperStyle={[ | ||
| styles.mh5, | ||
| styles.flex1, | ||
| animatedHighlightStyle, | ||
| styles.userSelectNone, | ||
| isLastItem && [styles.searchTableBottomRadius, styles.overflowHidden, styles.searchTableBottomRadius], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Valid suggestion.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed duplicate |
||
| ]} | ||
| > | ||
| {({hovered}) => ( | ||
| <TransactionItemRow | ||
| transactionItem={transactionItem} | ||
| report={transactionItem.report} | ||
| policy={transactionItem.policy} | ||
| shouldShowTooltip={showTooltip} | ||
| onButtonPress={handleActionButtonPress} | ||
| onCheckboxPress={() => onCheckboxPress?.(item)} | ||
| shouldUseNarrowLayout={false} | ||
| isLargeScreenWidth | ||
| columns={columns} | ||
| isActionLoading={isLoading ?? isActionLoading} | ||
| isSelected={!!transactionItem.isSelected} | ||
| isDisabled={!!isDisabled} | ||
| dateColumnSize={dateColumnSize} | ||
| submittedColumnSize={submittedColumnSize} | ||
| approvedColumnSize={approvedColumnSize} | ||
| postedColumnSize={postedColumnSize} | ||
| exportedColumnSize={exportedColumnSize} | ||
| amountColumnSize={amountColumnSize} | ||
| taxAmountColumnSize={taxAmountColumnSize} | ||
| isActionColumnWide={transactionItem.isActionColumnWide} | ||
| shouldShowCheckbox={!!canSelectMultiple} | ||
| checkboxSentryLabel={CONST.SENTRY_LABEL.SEARCH.TRANSACTION_LIST_ITEM_CHECKBOX} | ||
| style={[styles.p3, styles.pv2, isLastItem ? styles.searchTableBottomRadius : styles.noBorderRadius]} | ||
| violations={transactionViolations} | ||
| onArrowRightPress={isDeletedTransaction ? undefined : () => onSelectRow(item, transactionPreviewData)} | ||
| isHover={hovered} | ||
| nonPersonalAndWorkspaceCards={nonPersonalAndWorkspaceCards} | ||
| reportActions={exportedReportActions} | ||
| policyForMovingExpenses={policyForMovingExpenses} | ||
| /> | ||
| )} | ||
| </PressableWithFeedback> | ||
| </OfflineWithFeedback> | ||
| ); | ||
| } | ||
|
|
||
| export default TransactionListItemWide; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed duplicate