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
8 changes: 8 additions & 0 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function BaseSelectionList<TItem extends ListItem>(
shouldDebounceScrolling = false,
shouldPreventActiveCellVirtualization = false,
shouldScrollToFocusedIndex = true,
isSmallScreenWidth,
onContentSizeChange,
listItemTitleStyles,
initialNumToRender = 12,
Expand Down Expand Up @@ -412,6 +413,11 @@ function BaseSelectionList<TItem extends ListItem>(

if (shouldShowTextInput) {
clearInputAfterSelect();
} else if (isSmallScreenWidth) {
if (!item.isDisabledCheckbox) {
onCheckboxPress?.(item);
}
return;
}
}
Comment on lines 414 to 422

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (shouldShowTextInput) {
    clearInputAfterSelect();
    return;
}

if (isSmallScreenWidth && !item.isDisabledCheckbox) {
    onCheckboxPress?.(item);
}

@abzokhattab isn't this a better way of writing ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the return statement here is a breaking change:

if (shouldShowTextInput) {
    clearInputAfterSelect();
    return;
}

What I did was separate the logic into two if conditions, so that the return statement is executed in both cases—whether the item is disabled or not:

} else if (isSmallScreenWidth) {
    if (!item.isDisabledCheckbox) {
        onCheckboxPress?.(item);
    }
    return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What i mean is that if shouldShowTextInput is true then we won't go to else if (isSmallScreenWidth), so those two conditions needs to be separated out right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get what you mean, but the reason we're checking whether shouldShowTextInput is false is to avoid this behavior on pages where the text input appears at the top. Allowing it in those cases could introduce unexpected behavior. (The search page is an exception—it's handled separately in another PR that's not related to the current issue.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RoomMembersPage is an example

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update:

  • On my to-do list for tomorrow


Expand All @@ -437,6 +443,8 @@ function BaseSelectionList<TItem extends ListItem>(
shouldPreventDefaultFocusOnSelectRow,
isFocused,
isScreenFocused,
isSmallScreenWidth,
onCheckboxPress,
],
);

Expand Down
3 changes: 3 additions & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@ type SelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
/** Whether to scroll to the focused index */
shouldScrollToFocusedIndex?: boolean;

/** Whether the layout is narrow */
isSmallScreenWidth?: boolean;

/** Called when scrollable content view of the ScrollView changes */
onContentSizeChange?: (w: number, h: number) => void;

Expand Down
1 change: 1 addition & 0 deletions src/components/SelectionListWithModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function SelectionListWithModal<TItem extends ListItem>(
sections={sections}
onLongPressRow={handleLongPressRow}
isScreenFocused={isScreenFocused}
isSmallScreenWidth={isSmallScreenWidth}
// eslint-disable-next-line react/jsx-props-no-spreading
{...rest}
/>
Expand Down