-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add List.AccordionGroup component (#1307)
- Loading branch information
Showing
5 changed files
with
304 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import * as React from 'react'; | ||
import { ScrollView, StyleSheet } from 'react-native'; | ||
import { List, withTheme, Theme } from 'react-native-paper'; | ||
|
||
type Props = { | ||
theme: Theme; | ||
}; | ||
|
||
type State = { | ||
expandedId: string | number | undefined; | ||
}; | ||
|
||
class ListAccordionGroupExample extends React.Component<Props, State> { | ||
static title = 'List.AccordionGroup'; | ||
|
||
state = { | ||
expandedId: undefined, | ||
}; | ||
|
||
_onAccordionPress = (expandedId: string | number) => { | ||
this.setState(({ expandedId: currentExpandedId }) => ({ | ||
expandedId: currentExpandedId === expandedId ? undefined : expandedId, | ||
})); | ||
}; | ||
|
||
render() { | ||
const { | ||
theme: { | ||
colors: { background }, | ||
}, | ||
} = this.props; | ||
|
||
const { expandedId } = this.state; | ||
|
||
return ( | ||
<ScrollView style={[styles.container, { backgroundColor: background }]}> | ||
<List.AccordionGroup> | ||
<List.Section title="Uncontrolled Accordion Group example"> | ||
<List.Accordion | ||
left={props => <List.Icon {...props} icon="folder" />} | ||
title="Expandable list item" | ||
id="1" | ||
> | ||
<List.Item title="List item 1" /> | ||
<List.Item title="List item 2" /> | ||
</List.Accordion> | ||
<List.Accordion | ||
left={props => <List.Icon {...props} icon="folder" />} | ||
title="Expandable list item 2" | ||
id="2" | ||
> | ||
<List.Item title="List item 1" /> | ||
</List.Accordion> | ||
<List.Accordion | ||
left={props => <List.Icon {...props} icon="folder" />} | ||
title="Expandable list item 2" | ||
id="3" | ||
> | ||
<List.Item title="Another item" /> | ||
</List.Accordion> | ||
</List.Section> | ||
</List.AccordionGroup> | ||
<List.AccordionGroup | ||
expandedId={expandedId} | ||
onAccordionPress={this._onAccordionPress} | ||
> | ||
<List.Section title="Controlled Accordion Group example"> | ||
<List.Accordion | ||
left={props => <List.Icon {...props} icon="folder" />} | ||
title="Expandable list item" | ||
id="1" | ||
> | ||
<List.Item title="List item 1" /> | ||
<List.Item title="List item 2" /> | ||
</List.Accordion> | ||
<List.Accordion | ||
left={props => <List.Icon {...props} icon="folder" />} | ||
title="Expandable list item 2" | ||
id="2" | ||
> | ||
<List.Item title="List item 1" /> | ||
</List.Accordion> | ||
<List.Accordion | ||
left={props => <List.Icon {...props} icon="folder" />} | ||
title="Expandable list item 2" | ||
id="3" | ||
> | ||
<List.Item title="Another item" /> | ||
</List.Accordion> | ||
</List.Section> | ||
</List.AccordionGroup> | ||
</ScrollView> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
}, | ||
}); | ||
|
||
export default withTheme(ListAccordionGroupExample); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.