-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve SelectionList item rendering performance
- Loading branch information
Showing
5 changed files
with
191 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
89 changes: 89 additions & 0 deletions
89
src/components/SelectionList/BaseSelectionListItemRenderer.tsx
This file contains 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,89 @@ | ||
import React from 'react'; | ||
import type useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager'; | ||
import type useSingleExecution from '@hooks/useSingleExecution'; | ||
import * as SearchUtils from '@libs/SearchUtils'; | ||
import type {BaseListItemProps, BaseSelectionListProps, ListItem} from './types'; | ||
|
||
function BaseSelectionListItemRenderer<TItem extends ListItem>({ | ||
ListItem, | ||
item, | ||
index, | ||
isFocused, | ||
isDisabled, | ||
showTooltip, | ||
canSelectMultiple, | ||
onLongPressRow, | ||
shouldSingleExecuteRowSelect, | ||
selectRow, | ||
onCheckboxPress, | ||
onDismissError, | ||
shouldPreventDefaultFocusOnSelectRow, | ||
rightHandSideComponent, | ||
isMultilineSupported, | ||
isAlternateTextMultilineSupported, | ||
alternateTextNumberOfLines, | ||
shouldIgnoreFocus, | ||
setFocusedIndex, | ||
normalizedIndex, | ||
shouldSyncFocus, | ||
wrapperStyle, | ||
singleExecution, | ||
}: Omit<BaseListItemProps<TItem>, 'onSelectRow'> & | ||
Pick<BaseSelectionListProps<TItem>, 'ListItem' | 'shouldIgnoreFocus' | 'shouldSingleExecuteRowSelect'> & { | ||
index: number; | ||
selectRow: (item: TItem, indexToFocus?: number) => void; | ||
setFocusedIndex: ReturnType<typeof useArrowKeyFocusManager>[1]; | ||
normalizedIndex: number; | ||
singleExecution: ReturnType<typeof useSingleExecution>['singleExecution']; | ||
}) { | ||
const handleOnCheckboxPress = () => { | ||
if (SearchUtils.isReportListItemType(item)) { | ||
return onCheckboxPress; | ||
} | ||
return onCheckboxPress ? () => onCheckboxPress(item) : undefined; | ||
}; | ||
|
||
return ( | ||
<> | ||
<ListItem | ||
item={item} | ||
isFocused={isFocused} | ||
isDisabled={isDisabled} | ||
showTooltip={showTooltip} | ||
canSelectMultiple={canSelectMultiple} | ||
onLongPressRow={onLongPressRow} | ||
onSelectRow={() => { | ||
if (shouldSingleExecuteRowSelect) { | ||
singleExecution(() => selectRow(item, index))(); | ||
} else { | ||
selectRow(item, index); | ||
} | ||
}} | ||
onCheckboxPress={handleOnCheckboxPress()} | ||
onDismissError={() => onDismissError?.(item)} | ||
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow} | ||
// We're already handling the Enter key press in the useKeyboardShortcut hook, so we don't want the list item to submit the form | ||
shouldPreventEnterKeySubmit | ||
rightHandSideComponent={rightHandSideComponent} | ||
keyForList={item.keyForList ?? ''} | ||
isMultilineSupported={isMultilineSupported} | ||
isAlternateTextMultilineSupported={isAlternateTextMultilineSupported} | ||
alternateTextNumberOfLines={alternateTextNumberOfLines} | ||
onFocus={() => { | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
if (shouldIgnoreFocus || isDisabled) { | ||
return; | ||
} | ||
setFocusedIndex(normalizedIndex); | ||
}} | ||
shouldSyncFocus={shouldSyncFocus} | ||
wrapperStyle={wrapperStyle} | ||
/> | ||
{item.footerContent && item.footerContent} | ||
</> | ||
); | ||
} | ||
|
||
BaseSelectionListItemRenderer.displayName = 'BaseSelectionListItemRenderer'; | ||
|
||
export default BaseSelectionListItemRenderer; |
This file contains 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
This file contains 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