Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 35 additions & 55 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function BaseSelectionList<TItem extends ListItem>({
setShouldDisableHoverStyle(true);
}, [setShouldDisableHoverStyle]);

const [focusedIndex, setFocusedIndex, currentHoverIndexRef] = useArrowKeyFocusManager({
const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({
initialFocusedIndex,
maxIndex: data.length - 1,
disabledIndexes: dataDetails.disabledArrowKeyIndexes,
Expand Down Expand Up @@ -319,68 +319,48 @@ function BaseSelectionList<TItem extends ListItem>({
);
};

const setCurrentHoverIndex = useCallback(
(hoverIndex: number | null) => {
if (shouldDisableHoverStyle) {
return;
}
currentHoverIndexRef.current = hoverIndex;
},
[currentHoverIndexRef, shouldDisableHoverStyle],
);

const renderItem: ListRenderItem<TItem> = ({item, index}: ListRenderItemInfo<TItem>) => {
const isItemDisabled = isDisabled || item.isDisabled;
const selected = isItemSelected(item);
const isItemFocused = (!isDisabled || selected) && focusedIndex === index;
const isItemHighlighted = !!itemsToHighlight?.has(item.keyForList);

return (
<View
onMouseMove={() => setCurrentHoverIndex(index)}
onMouseEnter={() => setCurrentHoverIndex(index)}
onMouseLeave={(e) => {
e.stopPropagation();
setCurrentHoverIndex(null);
<ListItemRenderer
ListItem={ListItem}
selectRow={selectRow}
showTooltip={shouldShowTooltips}
item={{
shouldAnimateInHighlight: isItemHighlighted,
isSelected: selected,
...item,
}}
>
<ListItemRenderer
ListItem={ListItem}
selectRow={selectRow}
showTooltip={shouldShowTooltips}
item={{
shouldAnimateInHighlight: isItemHighlighted,
isSelected: selected,
...item,
}}
setFocusedIndex={setFocusedIndex}
index={index}
isFocused={isItemFocused}
isDisabled={isItemDisabled}
canSelectMultiple={canSelectMultiple}
onDismissError={onDismissError}
onLongPressRow={onLongPressRow}
onCheckboxPress={onCheckboxPress}
shouldSingleExecuteRowSelect={shouldSingleExecuteRowSelect}
shouldUseDefaultRightHandSideCheckmark={shouldUseDefaultRightHandSideCheckmark}
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
rightHandSideComponent={rightHandSideComponent}
isMultilineSupported={isRowMultilineSupported}
isAlternateTextMultilineSupported={(alternateNumberOfSupportedLines ?? 0) > 1}
alternateTextNumberOfLines={alternateNumberOfSupportedLines}
shouldIgnoreFocus={shouldIgnoreFocus}
titleStyles={style?.listItemTitleStyles}
wrapperStyle={style?.listItemWrapperStyle}
titleContainerStyles={style?.listItemTitleContainerStyles}
errorRowStyles={style?.listItemErrorRowStyles}
singleExecution={singleExecution}
shouldHighlightSelectedItem={shouldHighlightSelectedItem}
shouldSyncFocus={!isTextInputFocusedRef.current && hasKeyBeenPressed.current}
shouldDisableHoverStyle={shouldDisableHoverStyle}
shouldStopMouseLeavePropagation={false}
shouldShowRightCaret={shouldShowRightCaret}
/>
</View>
setFocusedIndex={setFocusedIndex}
index={index}
isFocused={isItemFocused}
isDisabled={isItemDisabled}
canSelectMultiple={canSelectMultiple}
onDismissError={onDismissError}
onLongPressRow={onLongPressRow}
onCheckboxPress={onCheckboxPress}
shouldSingleExecuteRowSelect={shouldSingleExecuteRowSelect}
shouldUseDefaultRightHandSideCheckmark={shouldUseDefaultRightHandSideCheckmark}
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
rightHandSideComponent={rightHandSideComponent}
isMultilineSupported={isRowMultilineSupported}
isAlternateTextMultilineSupported={(alternateNumberOfSupportedLines ?? 0) > 1}
alternateTextNumberOfLines={alternateNumberOfSupportedLines}
shouldIgnoreFocus={shouldIgnoreFocus}
titleStyles={style?.listItemTitleStyles}
wrapperStyle={style?.listItemWrapperStyle}
titleContainerStyles={style?.listItemTitleContainerStyles}
errorRowStyles={style?.listItemErrorRowStyles}
singleExecution={singleExecution}
shouldHighlightSelectedItem={shouldHighlightSelectedItem}
shouldSyncFocus={!isTextInputFocusedRef.current && hasKeyBeenPressed.current}
shouldDisableHoverStyle={shouldDisableHoverStyle}
shouldShowRightCaret={shouldShowRightCaret}
/>
);
};

Expand Down
5 changes: 1 addition & 4 deletions src/components/SelectionList/ListItem/BaseListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ function BaseListItem<TItem extends ListItem>({
shouldUseDefaultRightHandSideCheckmark = true,
shouldHighlightSelectedItem = true,
shouldDisableHoverStyle,
shouldStopMouseLeavePropagation = true,
shouldShowRightCaret = false,
accessible,
accessibilityRole = getButtonRole(true),
Expand All @@ -63,9 +62,7 @@ function BaseListItem<TItem extends ListItem>({
useSyncFocus(pressableRef, !!isFocused, shouldSyncFocus);
const handleMouseLeave = (e: React.MouseEvent<Element, MouseEvent>) => {
bind.onMouseLeave();
if (shouldStopMouseLeavePropagation) {
e.stopPropagation();
}
e.stopPropagation();
setMouseUp();
};

Expand Down
2 changes: 0 additions & 2 deletions src/components/SelectionList/ListItem/ListItemRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function ListItemRenderer<TItem extends ListItem>({
shouldUseDefaultRightHandSideCheckmark,
shouldHighlightSelectedItem,
shouldDisableHoverStyle,
shouldStopMouseLeavePropagation,
shouldShowRightCaret,
errorRowStyles,
}: ListItemRendererProps<TItem>) {
Expand Down Expand Up @@ -106,7 +105,6 @@ function ListItemRenderer<TItem extends ListItem>({
shouldUseDefaultRightHandSideCheckmark={shouldUseDefaultRightHandSideCheckmark}
shouldHighlightSelectedItem={shouldHighlightSelectedItem}
shouldDisableHoverStyle={shouldDisableHoverStyle}
shouldStopMouseLeavePropagation={shouldStopMouseLeavePropagation}
shouldShowRightCaret={shouldShowRightCaret}
/>
{item.footerContent && item.footerContent}
Expand Down
2 changes: 0 additions & 2 deletions src/components/SelectionList/ListItem/RadioListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function RadioListItem<TItem extends ListItem>({
titleStyles,
shouldHighlightSelectedItem = true,
shouldDisableHoverStyle,
shouldStopMouseLeavePropagation,
accessibilityRole,
}: RadioListItemProps<TItem>) {
const styles = useThemeStyles();
Expand All @@ -51,7 +50,6 @@ function RadioListItem<TItem extends ListItem>({
pendingAction={item.pendingAction}
shouldHighlightSelectedItem={shouldHighlightSelectedItem}
shouldDisableHoverStyle={shouldDisableHoverStyle}
shouldStopMouseLeavePropagation={shouldStopMouseLeavePropagation}
accessibilityRole={accessibilityRole}
>
<>
Expand Down
Loading
Loading