feat: allow List.Accordion to behave as a controlled component (#638)

fixes #616, #635
closes #618
This commit is contained in:
Lucas Vieira
2018-11-05 19:13:41 -02:00
committed by Satyajit Sahoo
parent 8764f60370
commit decbedbd82
5 changed files with 336 additions and 27 deletions

View File

@@ -9,15 +9,28 @@ type Props = {
theme: Theme,
};
class ListAccordionExample extends React.Component<Props> {
type State = {
expanded: boolean,
};
class ListAccordionExample extends React.Component<Props, State> {
static title = 'List.Accordion';
state = {
expanded: true,
};
_handlePress = () => {
this.setState({ expanded: !this.state.expanded });
};
render() {
const {
theme: {
colors: { background },
},
} = this.props;
return (
<ScrollView style={[styles.container, { backgroundColor: background }]}>
<List.Section title="Expandable list item">
@@ -28,6 +41,14 @@ class ListAccordionExample extends React.Component<Props> {
<List.Item title="List item 1" />
<List.Item title="List item 2" />
</List.Accordion>
<List.Accordion
left={props => <List.Icon {...props} icon="folder" />}
title="Start expanded"
expanded={this.state.expanded}
onPress={this._handlePress}
>
<List.Item title="List item 1" />
</List.Accordion>
</List.Section>
<Divider />
<List.Section title="Expandable & multiline list item">