Skip to content
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

[0.66] Flatlist keyboard navigation: Mouse can move selection #1269

Merged
merged 4 commits into from
Jul 22, 2022
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
13 changes: 13 additions & 0 deletions Libraries/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,19 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
}
}

// [TODO(macOS GH#750)
/**
* Move selection to the specified index
*
* @platform macos
*/
selectRowAtIndex(index: number) {
if (this._listRef) {
this._listRef.selectRowAtIndex(index);
}
}
// ]TODO(macOS GH#750)

/**
* Provides a handle to the underlying scroll responder.
*/
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ class VirtualizedList extends React.PureComponent<Props, State> {
this.scrollToOffset({offset: newOffset});
}
}

selectRowAtIndex(rowIndex: number) {
this._selectRowAtIndex(rowIndex);
}
// ]TODO(macOS GH#774)

recordInteraction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type State = {|
fadingEdgeLength: number,
onPressDisabled: boolean,
textSelectable: boolean,
enableSelectionOnKeyPress: boolean, // TODO(macOS GH#774)]
enableSelectionOnKeyPress: boolean, // TODO(macOS GH#774)
|};

class FlatListExample extends React.PureComponent<Props, State> {
Expand Down Expand Up @@ -303,6 +303,10 @@ class FlatListExample extends React.PureComponent<Props, State> {
_pressItem = (key: string) => {
this._listRef && this._listRef.recordInteraction();
const index = Number(key);
// [TODO(macOS GH#774)
if (this.state.enableSelectionOnKeyPress) {
this._listRef && this._listRef.selectRowAtIndex(index);
} // ]TODO(macOS GH#774)
const itemState = pressItem(this.state.data[index]);
this.setState(state => ({
...state,
Expand Down