mirror of
https://github.com/zhigang1992/react-native-paper.git
synced 2026-06-11 08:13:29 +08:00
feat: allow List.Accordion to behave as a controlled component (#638)
fixes #616, #635 closes #618
This commit is contained in:
committed by
Satyajit Sahoo
parent
8764f60370
commit
decbedbd82
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user