From ea16a1f50f1b48ebf97e1469d1cae67cdb76b5da Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Fri, 1 May 2020 16:13:46 +0200 Subject: [PATCH] Improved planex group search performance --- .../Animations/AnimatedAccordion.js | 4 +- .../Lists/PlanexGroups/GroupListAccordion.js | 39 ++++++++++--------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/components/Animations/AnimatedAccordion.js b/src/components/Animations/AnimatedAccordion.js index 62c6454..9cc7dba 100644 --- a/src/components/Animations/AnimatedAccordion.js +++ b/src/components/Animations/AnimatedAccordion.js @@ -63,7 +63,9 @@ class AnimatedAccordion extends React.Component { }; 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() { diff --git a/src/components/Lists/PlanexGroups/GroupListAccordion.js b/src/components/Lists/PlanexGroups/GroupListAccordion.js index 6dbfecc..73139cd 100644 --- a/src/components/Lists/PlanexGroups/GroupListAccordion.js +++ b/src/components/Lists/PlanexGroups/GroupListAccordion.js @@ -23,10 +23,6 @@ const LIST_ITEM_HEIGHT = 64; class GroupListAccordion extends React.Component { - 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 { 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 ( - - ); - } else - return null; + renderItem = ({item}: { item: group }) => { + const onPress = () => this.props.onGroupPress(item); + const onStarPress = () => this.props.onFavoritePress(item); + return ( + + ); + } + + 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 { > {/*$FlowFixMe*/}