Fix crash on collapsible click

This commit is contained in:
Arnaud Vergnet 2020-08-06 14:14:01 +02:00
parent 98770611ff
commit 5166e0b879
2 changed files with 10 additions and 8 deletions

View file

@ -57,8 +57,8 @@ class AnimatedAccordion extends React.Component<PropsType, StateType> {
}
setupChevron() {
const {state} = this;
if (state.expanded) {
const {expanded} = this.state;
if (expanded) {
this.chevronIcon = 'chevron-up';
this.animStart = '180deg';
this.animEnd = '0deg';
@ -70,12 +70,14 @@ class AnimatedAccordion extends React.Component<PropsType, StateType> {
}
toggleAccordion = () => {
const {state} = this;
const {expanded} = this.state;
if (this.chevronRef.current != null) {
this.chevronRef.current.transitionTo({
rotate: state.expanded ? this.animStart : this.animEnd,
rotate: expanded ? this.animStart : this.animEnd,
});
this.setState({expanded: !state.expanded});
this.setState((prevState: StateType): {expanded: boolean} => ({
expanded: !prevState.expanded,
}));
}
};
@ -87,15 +89,16 @@ class AnimatedAccordion extends React.Component<PropsType, StateType> {
<List.Item
title={props.title}
subtitle={props.subtitle}
titleStyle={state.expanded ? {color: colors.primary} : undefined}
titleStyle={state.expanded ? {color: colors.primary} : null}
onPress={this.toggleAccordion}
right={({size}: {size: number}): React.Node => (
<AnimatedListIcon
ref={this.chevronRef}
size={size}
icon={this.chevronIcon}
color={state.expanded ? colors.primary : undefined}
color={state.expanded ? colors.primary : null}
useNativeDriver
style={{rotate: '0deg'}}
/>
)}
left={props.left}

View file

@ -96,7 +96,6 @@ class GroupListAccordion extends React.Component<PropsType> {
}
unmountWhenCollapsed // Only render list if expanded for increased performance
opened={props.item.id === 0 || props.currentSearchString.length > 0}>
{/* $FlowFixMe */}
<FlatList
data={this.getData()}
extraData={props.currentSearchString}