diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index 14fb9e8fec6ecc..9cb7c5794498cb 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -369,6 +369,19 @@ class FlatList extends React.PureComponent, void> { } } + // [TODO(macOS GH#750) + /** + * Move selection to the specified index + * + * @platform ios + */ + selectRowAtIndex(index: number) { + if (this._listRef) { + this._listRef.selectRowAtIndex(index); + } + } + // ]TODO(macOS GH#750) + /** * Provides a handle to the underlying scroll responder. */ diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index d9a93d013da9bf..c2ba62b50cfebe 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -592,6 +592,10 @@ class VirtualizedList extends React.PureComponent { this.scrollToOffset({offset: newOffset}); } } + + selectRowAtIndex(rowIndex: number) { + this._selectRowAtIndex(rowIndex); + } // ]TODO(macOS GH#774) recordInteraction() { diff --git a/packages/rn-tester/js/examples/FlatList/FlatList-basic.js b/packages/rn-tester/js/examples/FlatList/FlatList-basic.js index a9dcd074cbf642..6c714006ae9813 100644 --- a/packages/rn-tester/js/examples/FlatList/FlatList-basic.js +++ b/packages/rn-tester/js/examples/FlatList/FlatList-basic.js @@ -63,7 +63,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 { @@ -329,6 +329,10 @@ class FlatListExample extends React.PureComponent { _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,