1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-02-01 19:15:01 +02:00

Mobile: Scroll dropdown to selected value when first opened (#11091)

This commit is contained in:
Henry Heino 2024-09-21 04:58:01 -07:00 committed by GitHub
parent d023ce592c
commit 5c23765458
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -78,6 +78,17 @@ class Dropdown extends Component<DropdownProps, DropdownState> {
private onCloseList = () => {
this.setState({ listVisible: false });
};
private onListLoad = (listRef: FlatList|null) => {
if (!listRef) return;
for (let i = 0; i < this.props.items.length; i++) {
const item = this.props.items[i];
if (item.value === this.props.selectedValue) {
listRef.scrollToIndex({ index: i, animated: false });
break;
}
}
};
public render() {
const items = this.props.items;
@ -228,6 +239,7 @@ class Dropdown extends Component<DropdownProps, DropdownState> {
accessibilityRole='menu'
style={wrapperStyle}>
<FlatList
ref={this.onListLoad}
style={itemListStyle}
data={this.props.items}
renderItem={itemRenderer}