Added animated accordions in group selection

This commit is contained in:
Arnaud Vergnet 2020-04-16 20:15:56 +02:00
parent 46d293564f
commit 7998fa47ca
2 changed files with 49 additions and 31 deletions

View file

@ -2,8 +2,10 @@
import * as React from 'react'; import * as React from 'react';
import {IconButton, List, withTheme} from 'react-native-paper'; import {IconButton, List, withTheme} from 'react-native-paper';
import {FlatList} from "react-native"; import {FlatList, View} from "react-native";
import {stringMatchQuery} from "../../utils/Search"; import {stringMatchQuery} from "../../utils/Search";
import Collapsible from "react-native-collapsible";
import * as Animatable from "react-native-animatable";
type Props = { type Props = {
item: Object, item: Object,
@ -20,14 +22,18 @@ type State = {
} }
const LIST_ITEM_HEIGHT = 64; const LIST_ITEM_HEIGHT = 64;
const AnimatedListIcon = Animatable.createAnimatableComponent(List.Icon);
class GroupListAccordion extends React.Component<Props, State> { class GroupListAccordion extends React.Component<Props, State> {
chevronRef: Object;
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
expanded: props.item.id === "0", expanded: props.item.id === "0",
} }
this.chevronRef = React.createRef();
} }
shouldComponentUpdate(nextProps: Props, nextSate: State) { shouldComponentUpdate(nextProps: Props, nextSate: State) {
@ -39,7 +45,10 @@ class GroupListAccordion extends React.Component<Props, State> {
|| (nextProps.favoriteNumber !== this.props.favoriteNumber); || (nextProps.favoriteNumber !== this.props.favoriteNumber);
} }
onPress = () => this.setState({expanded: !this.state.expanded}); onPress = () => {
this.chevronRef.current.transitionTo({ rotate: this.state.expanded ? '0deg' : '180deg' });
this.setState({expanded: !this.state.expanded})
};
keyExtractor = (item: Object) => item.id.toString(); keyExtractor = (item: Object) => item.id.toString();
@ -82,7 +91,8 @@ class GroupListAccordion extends React.Component<Props, State> {
render() { render() {
const item = this.props.item; const item = this.props.item;
return ( return (
<List.Accordion <View>
<List.Item
title={item.name} title={item.name}
expanded={this.state.expanded} expanded={this.state.expanded}
onPress={this.onPress} onPress={this.onPress}
@ -98,8 +108,16 @@ class GroupListAccordion extends React.Component<Props, State> {
color={this.props.theme.colors.tetrisScore} color={this.props.theme.colors.tetrisScore}
/> />
: null} : null}
right={(props) => <AnimatedListIcon
ref={this.chevronRef}
{...props}
icon={"chevron-down"}
useNativeDriver
/>}
/>
<Collapsible
collapsed={!this.state.expanded}
> >
{/*$FlowFixMe*/}
<FlatList <FlatList
data={item.content} data={item.content}
extraData={this.props.currentSearchString} extraData={this.props.currentSearchString}
@ -107,10 +125,11 @@ class GroupListAccordion extends React.Component<Props, State> {
keyExtractor={this.keyExtractor} keyExtractor={this.keyExtractor}
listKey={item.id} listKey={item.id}
// Performance props, see https://reactnative.dev/docs/optimizing-flatlist-configuration // Performance props, see https://reactnative.dev/docs/optimizing-flatlist-configuration
// getItemLayout={this.itemLayout} // Broken with search getItemLayout={this.itemLayout} // Broken with search
removeClippedSubviews={true} removeClippedSubviews={true}
/> />
</List.Accordion> </Collapsible>
</View>
); );
} }
} }

View file

@ -1,12 +1,11 @@
// @flow // @flow
import * as React from 'react'; import * as React from 'react';
import {FlatList} from "react-native"; import {FlatList, View} from "react-native";
import {Drawer, List, withTheme} from 'react-native-paper'; import {Drawer, List, withTheme} from 'react-native-paper';
import {Linking} from "expo"; import {Linking} from "expo";
import Collapsible from "react-native-collapsible"; import Collapsible from "react-native-collapsible";
import * as Animatable from "react-native-animatable"; import * as Animatable from "react-native-animatable";
import {View} from "react-native-animatable";
type Props = { type Props = {
navigation: Object, navigation: Object,