Improved planex group search performance

This commit is contained in:
Arnaud Vergnet 2020-05-01 16:13:46 +02:00
parent 0b7191887d
commit ea16a1f50f
2 changed files with 24 additions and 19 deletions

View file

@ -63,7 +63,9 @@ class AnimatedAccordion extends React.Component<Props, State> {
}; };
shouldComponentUpdate(nextProps: Props, nextState: State): boolean { shouldComponentUpdate(nextProps: Props, nextState: State): boolean {
return nextState.expanded !== this.state.expanded; if (nextProps.opened != null && nextProps.opened !== this.props.opened)
this.state.expanded = nextProps.opened;
return true;
} }
render() { render() {

View file

@ -23,10 +23,6 @@ const LIST_ITEM_HEIGHT = 64;
class GroupListAccordion extends React.Component<Props> { class GroupListAccordion extends React.Component<Props> {
constructor(props) {
super(props);
}
shouldComponentUpdate(nextProps: Props) { shouldComponentUpdate(nextProps: Props) {
return (nextProps.currentSearchString !== this.props.currentSearchString) return (nextProps.currentSearchString !== this.props.currentSearchString)
|| (nextProps.favoriteNumber !== this.props.favoriteNumber) || (nextProps.favoriteNumber !== this.props.favoriteNumber)
@ -35,19 +31,26 @@ class GroupListAccordion extends React.Component<Props> {
keyExtractor = (item: group) => item.id.toString(); keyExtractor = (item: group) => item.id.toString();
renderItem = ({item}: {item: group}) => { renderItem = ({item}: { item: group }) => {
if (stringMatchQuery(item.name, this.props.currentSearchString)) { const onPress = () => this.props.onGroupPress(item);
const onPress = () => this.props.onGroupPress(item); const onStarPress = () => this.props.onFavoritePress(item);
const onStarPress = () => this.props.onFavoritePress(item); return (
return ( <GroupListItem
<GroupListItem height={LIST_ITEM_HEIGHT}
height={LIST_ITEM_HEIGHT} item={item}
item={item} onPress={onPress}
onPress={onPress} onStarPress={onStarPress}/>
onStarPress={onStarPress}/> );
); }
} else
return null; getData() {
const originalData = this.props.item.content;
let displayData = [];
for (let i = 0; i < originalData.length; i++) {
if (stringMatchQuery(originalData[i].name, this.props.currentSearchString))
displayData.push(originalData[i]);
}
return displayData;
} }
render() { render() {
@ -73,7 +76,7 @@ class GroupListAccordion extends React.Component<Props> {
> >
{/*$FlowFixMe*/} {/*$FlowFixMe*/}
<FlatList <FlatList
data={item.content} data={this.getData()}
extraData={this.props.currentSearchString} extraData={this.props.currentSearchString}
renderItem={this.renderItem} renderItem={this.renderItem}
keyExtractor={this.keyExtractor} keyExtractor={this.keyExtractor}