forked from vergnet/application-amicale
Fix crash on collapsible click
This commit is contained in:
parent
98770611ff
commit
5166e0b879
2 changed files with 10 additions and 8 deletions
|
@ -57,8 +57,8 @@ class AnimatedAccordion extends React.Component<PropsType, StateType> {
|
||||||
}
|
}
|
||||||
|
|
||||||
setupChevron() {
|
setupChevron() {
|
||||||
const {state} = this;
|
const {expanded} = this.state;
|
||||||
if (state.expanded) {
|
if (expanded) {
|
||||||
this.chevronIcon = 'chevron-up';
|
this.chevronIcon = 'chevron-up';
|
||||||
this.animStart = '180deg';
|
this.animStart = '180deg';
|
||||||
this.animEnd = '0deg';
|
this.animEnd = '0deg';
|
||||||
|
@ -70,12 +70,14 @@ class AnimatedAccordion extends React.Component<PropsType, StateType> {
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleAccordion = () => {
|
toggleAccordion = () => {
|
||||||
const {state} = this;
|
const {expanded} = this.state;
|
||||||
if (this.chevronRef.current != null) {
|
if (this.chevronRef.current != null) {
|
||||||
this.chevronRef.current.transitionTo({
|
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
|
<List.Item
|
||||||
title={props.title}
|
title={props.title}
|
||||||
subtitle={props.subtitle}
|
subtitle={props.subtitle}
|
||||||
titleStyle={state.expanded ? {color: colors.primary} : undefined}
|
titleStyle={state.expanded ? {color: colors.primary} : null}
|
||||||
onPress={this.toggleAccordion}
|
onPress={this.toggleAccordion}
|
||||||
right={({size}: {size: number}): React.Node => (
|
right={({size}: {size: number}): React.Node => (
|
||||||
<AnimatedListIcon
|
<AnimatedListIcon
|
||||||
ref={this.chevronRef}
|
ref={this.chevronRef}
|
||||||
size={size}
|
size={size}
|
||||||
icon={this.chevronIcon}
|
icon={this.chevronIcon}
|
||||||
color={state.expanded ? colors.primary : undefined}
|
color={state.expanded ? colors.primary : null}
|
||||||
useNativeDriver
|
useNativeDriver
|
||||||
|
style={{rotate: '0deg'}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
left={props.left}
|
left={props.left}
|
||||||
|
|
|
@ -96,7 +96,6 @@ class GroupListAccordion extends React.Component<PropsType> {
|
||||||
}
|
}
|
||||||
unmountWhenCollapsed // Only render list if expanded for increased performance
|
unmountWhenCollapsed // Only render list if expanded for increased performance
|
||||||
opened={props.item.id === 0 || props.currentSearchString.length > 0}>
|
opened={props.item.id === 0 || props.currentSearchString.length > 0}>
|
||||||
{/* $FlowFixMe */}
|
|
||||||
<FlatList
|
<FlatList
|
||||||
data={this.getData()}
|
data={this.getData()}
|
||||||
extraData={props.currentSearchString}
|
extraData={props.currentSearchString}
|
||||||
|
|
Loading…
Reference in a new issue