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 {
return nextState.expanded !== this.state.expanded;
if (nextProps.opened != null && nextProps.opened !== this.props.opened)
this.state.expanded = nextProps.opened;
return true;
}
render() {

View file

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