Skip to content

Commit

Permalink
Keyboard navigation in Flatlist (microsoft#1258)
Browse files Browse the repository at this point in the history
* add pull yml

* match handleOpenURLNotification event payload with iOS (microsoft#755) (#2)

Co-authored-by: Ryan Linton <ryanlntn@gmail.com>

* [pull] master from microsoft:master (#11)

* Deprecated api (microsoft#853)

* Remove deprecated/unused context param
* Update a few Mac deprecated APIs

* Packing RN dependencies, hermes and ignoring javadoc failure,  (microsoft#852)

* Ignore javadoc failure

* Bringing few more changes from 0.63-stable

* Fixing a patch in engine selection

* Fixing a patch in nuget spec

* Fixing the output directory of nuget pack

* Packaging dependencies in the nuget

* Fix onMouseEnter/onMouseLeave callbacks not firing on Pressable (microsoft#855)

* add pull yml

* match handleOpenURLNotification event payload with iOS (microsoft#755) (#2)

Co-authored-by: Ryan Linton <ryanlntn@gmail.com>

* fix mouse evetns on pressable

* delete extra yml from this branch

* Add macOS tags

* reorder props to have onMouseEnter/onMouseLeave always be before onPress

Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com>
Co-authored-by: Ryan Linton <ryanlntn@gmail.com>

* Grammar fixes. (microsoft#856)

Updates simple grammar issues.

Co-authored-by: Nick Trescases <42704557+ntre@users.noreply.github.com>
Co-authored-by: Anandraj <anandrag@microsoft.com>
Co-authored-by: Saad Najmi <saadnajmi2@gmail.com>
Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com>
Co-authored-by: Ryan Linton <ryanlntn@gmail.com>
Co-authored-by: Muhammad Hamza Zaman <mh.zaman.4069@gmail.com>

* wip

* wip

* more wip

* Home/End/OptionUp/OptionDown work

* ensureItemAtIndexIsVisible works

* Home/End work

* Initial cleanup for PR

* More cleanup

* More cleanup

* Make it a real prop

* No need for client code

* Don't move keyboard focus with selection

* Update tags

* Fix flow errors

* Update colors, make ScrollView focusable

* prettier

* undo change

* Fix flow errors

* Clean up code + handle page up/down with new prop

Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com>
Co-authored-by: Ryan Linton <ryanlntn@gmail.com>
Co-authored-by: Nick Trescases <42704557+ntre@users.noreply.github.com>
Co-authored-by: Anandraj <anandrag@microsoft.com>
Co-authored-by: Muhammad Hamza Zaman <mh.zaman.4069@gmail.com>
  • Loading branch information
6 people authored and Shawn Dempsey committed Feb 13, 2023
1 parent 61831ee commit 295efbd
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,13 @@ class VirtualizedList extends React.PureComponent<Props, State> {
this._selectRowAtIndex(rowAbove);
};

_selectRowAtIndex = rowIndex => {
this.setState(state => {
return {selectedRowIndex: rowIndex};
});
return rowIndex;
};

_selectRowBelowIndex = rowIndex => {
const rowBelow = rowIndex < this.state.last ? rowIndex + 1 : rowIndex;
this._selectRowAtIndex(rowBelow);
Expand Down Expand Up @@ -1611,6 +1618,34 @@ class VirtualizedList extends React.PureComponent<Props, State> {
if (this.props.onSelectionEntered) {
this.props.onSelectionEntered(item);
}
} else if (key === 'OPTION_UP') {
newIndex = this._selectRowAtIndex(0);
this._handleSelectionChange(prevIndex, newIndex);
} else if (key === 'OPTION_DOWN') {
newIndex = this._selectRowAtIndex(this.state.last);
this._handleSelectionChange(prevIndex, newIndex);
} else if (key === 'PAGE_UP') {
const maxY =
event.nativeEvent.contentSize.height -
event.nativeEvent.layoutMeasurement.height;
const newOffset = Math.min(
maxY,
nativeEvent.contentOffset.y + -nativeEvent.layoutMeasurement.height,
);
this.scrollToOffset({animated: true, offset: newOffset});
} else if (key === 'PAGE_DOWN') {
const maxY =
event.nativeEvent.contentSize.height -
event.nativeEvent.layoutMeasurement.height;
const newOffset = Math.min(
maxY,
nativeEvent.contentOffset.y + nativeEvent.layoutMeasurement.height,
);
this.scrollToOffset({animated: true, offset: newOffset});
} else if (key === 'HOME') {
this.scrollToOffset({animated: true, offset: 0});
} else if (key === 'END') {
this.scrollToEnd({animated: true});
}
} else if (key === 'Home') {
this.scrollToOffset({animated: true, offset: 0});
Expand All @@ -1619,6 +1654,20 @@ class VirtualizedList extends React.PureComponent<Props, State> {
}
}
};

_handleSelectionChange = (prevIndex, newIndex) => {
this.ensureItemAtIndexIsVisible(newIndex);
if (prevIndex !== newIndex) {
const item = this.props.getItem(this.props.data, newIndex);
if (this.props.onSelectionChanged) {
this.props.onSelectionChanged({
previousSelection: prevIndex,
newSelection: newIndex,
item: item,
});
}
}
};
// ]TODO(macOS GH#774)

_renderDebugOverlay() {
Expand Down

0 comments on commit 295efbd

Please sign in to comment.