diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index bda4951e24687b..604ee53041852c 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 macos + */ + 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 e04fc2179c0155..4f44a655a68606 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/FlatListExample.js b/packages/rn-tester/js/examples/FlatList/FlatListExample.js index ffd38c288343d4..5b979d404079f7 100644 --- a/packages/rn-tester/js/examples/FlatList/FlatListExample.js +++ b/packages/rn-tester/js/examples/FlatList/FlatListExample.js @@ -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 { @@ -303,6 +303,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,