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
3 changes: 2 additions & 1 deletion src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ function BaseSelectionList<TItem extends ListItem>(
onLongPressRow,
shouldShowTextInput = !!textInputLabel || !!textInputIconLeft,
shouldShowListEmptyContent = true,
shouldIgnoreFocus = false,
scrollEventThrottle,
contentContainerStyle,
}: BaseSelectionListProps<TItem>,
Expand Down Expand Up @@ -468,7 +469,7 @@ function BaseSelectionList<TItem extends ListItem>(
isAlternateTextMultilineSupported={isAlternateTextMultilineSupported}
alternateTextNumberOfLines={alternateTextNumberOfLines}
onFocus={() => {
if (isDisabled) {
if (shouldIgnoreFocus || isDisabled) {
return;
}
setFocusedIndex(normalizedIndex);
Expand Down
4 changes: 4 additions & 0 deletions src/components/SelectionList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {forwardRef, useEffect, useState} from 'react';
import type {ForwardedRef} from 'react';
import {Keyboard} from 'react-native';
import * as Browser from '@libs/Browser';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import BaseSelectionList from './BaseSelectionList';
import type {BaseSelectionListProps, ListItem, SelectionListHandle} from './types';
Expand Down Expand Up @@ -42,6 +43,9 @@ function SelectionList<TItem extends ListItem>({onScroll, ...props}: BaseSelecti
{...props}
ref={ref}
onScroll={onScroll ?? defaultOnScroll}
// Ignore the focus if it's caused by a touch event on mobile chrome.
// For example, a long press will trigger a focus event on mobile chrome.
shouldIgnoreFocus={Browser.isMobileChrome() && isScreenTouched}

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.

So, I found that the long press callback is called later than the onFocus, so I changed the solution to ignore the focus whenever the touch event is detected. Luckily we already detect the touch event in this file, so I just need to pass down the shouldIgnoreFocus prop and ignore the focus if it's true.

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.

It might be more helpful later if the comment clearly mentions the quirk of Android Chrome triggering the onFocus event on long press.

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.

Updated

/>
);
}
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 @@ -489,6 +489,9 @@ type BaseSelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
/** Styles to apply to SectionList component */
sectionListStyle?: StyleProp<ViewStyle>;

/** Whether to ignore the focus event */
shouldIgnoreFocus?: boolean;

/** Whether focus event should be delayed */
shouldDelayFocus?: boolean;

Expand Down