forked from vergnet/application-amicale
Added animated accordions in group selection
This commit is contained in:
parent
46d293564f
commit
7998fa47ca
2 changed files with 49 additions and 31 deletions
|
@ -2,8 +2,10 @@
|
|||
|
||||
import * as React from 'react';
|
||||
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 Collapsible from "react-native-collapsible";
|
||||
import * as Animatable from "react-native-animatable";
|
||||
|
||||
type Props = {
|
||||
item: Object,
|
||||
|
@ -20,14 +22,18 @@ type State = {
|
|||
}
|
||||
|
||||
const LIST_ITEM_HEIGHT = 64;
|
||||
const AnimatedListIcon = Animatable.createAnimatableComponent(List.Icon);
|
||||
|
||||
class GroupListAccordion extends React.Component<Props, State> {
|
||||
|
||||
chevronRef: Object;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
expanded: props.item.id === "0",
|
||||
}
|
||||
this.chevronRef = React.createRef();
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps: Props, nextSate: State) {
|
||||
|
@ -39,7 +45,10 @@ class GroupListAccordion extends React.Component<Props, State> {
|
|||
|| (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();
|
||||
|
||||
|
@ -82,35 +91,45 @@ class GroupListAccordion extends React.Component<Props, State> {
|
|||
render() {
|
||||
const item = this.props.item;
|
||||
return (
|
||||
<List.Accordion
|
||||
title={item.name}
|
||||
expanded={this.state.expanded}
|
||||
onPress={this.onPress}
|
||||
style={{
|
||||
height: this.props.height,
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
left={props =>
|
||||
item.id === "0"
|
||||
? <List.Icon
|
||||
<View>
|
||||
<List.Item
|
||||
title={item.name}
|
||||
expanded={this.state.expanded}
|
||||
onPress={this.onPress}
|
||||
style={{
|
||||
height: this.props.height,
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
left={props =>
|
||||
item.id === "0"
|
||||
? <List.Icon
|
||||
{...props}
|
||||
icon={"star"}
|
||||
color={this.props.theme.colors.tetrisScore}
|
||||
/>
|
||||
: null}
|
||||
right={(props) => <AnimatedListIcon
|
||||
ref={this.chevronRef}
|
||||
{...props}
|
||||
icon={"star"}
|
||||
color={this.props.theme.colors.tetrisScore}
|
||||
/>
|
||||
: null}
|
||||
>
|
||||
{/*$FlowFixMe*/}
|
||||
<FlatList
|
||||
data={item.content}
|
||||
extraData={this.props.currentSearchString}
|
||||
renderItem={this.renderItem}
|
||||
keyExtractor={this.keyExtractor}
|
||||
listKey={item.id}
|
||||
// Performance props, see https://reactnative.dev/docs/optimizing-flatlist-configuration
|
||||
// getItemLayout={this.itemLayout} // Broken with search
|
||||
removeClippedSubviews={true}
|
||||
icon={"chevron-down"}
|
||||
useNativeDriver
|
||||
/>}
|
||||
/>
|
||||
</List.Accordion>
|
||||
<Collapsible
|
||||
collapsed={!this.state.expanded}
|
||||
>
|
||||
<FlatList
|
||||
data={item.content}
|
||||
extraData={this.props.currentSearchString}
|
||||
renderItem={this.renderItem}
|
||||
keyExtractor={this.keyExtractor}
|
||||
listKey={item.id}
|
||||
// Performance props, see https://reactnative.dev/docs/optimizing-flatlist-configuration
|
||||
getItemLayout={this.itemLayout} // Broken with search
|
||||
removeClippedSubviews={true}
|
||||
/>
|
||||
</Collapsible>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
// @flow
|
||||
|
||||
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 {Linking} from "expo";
|
||||
import Collapsible from "react-native-collapsible";
|
||||
import * as Animatable from "react-native-animatable";
|
||||
import {View} from "react-native-animatable";
|
||||
|
||||
type Props = {
|
||||
navigation: Object,
|
||||
|
|
Loading…
Reference in a new issue