Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions example/src/Examples/ListAccordionExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ const ListAccordionExample = () => {
>
<List.Item title="List item 1" />
</List.Accordion>
<List.Accordion
left={(props) => <List.Icon {...props} icon="folder" />}
title="Selected"
selected
>
<List.Item title="List item 1" />
</List.Accordion>
</List.Section>
<Divider />
<List.Section title="Expandable & multiline list item">
Expand Down
109 changes: 76 additions & 33 deletions example/src/Examples/ListItemExample.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import { View, StyleSheet } from 'react-native';
import { useState } from 'react';

import { List, Divider, Checkbox, Avatar, Switch } from 'react-native-paper';

import ScreenWrapper from '../ScreenWrapper';

const CenteredCheckbox = () => (
<View style={styles.centered}>
<Checkbox status="checked" aria-label="Headline" />
</View>
);
const SelectableSection = () => {
const [selected, setSelected] = useState(0);

return (
<List.Section title="Selected">
{[0, 1, 2].map((index) => (
<List.Item
key={index}
title="Headline"
description="Supporting text"
selected={index === selected}
onPress={() => setSelected(index)}
leading={<List.Icon icon="account-outline" />}
/>
))}
<Divider />
</List.Section>
);
};

const ListItemExample = () => {
return (
<ScreenWrapper>
<SelectableSection />

<List.Section title="Text-only">
<List.Item title="Headline" />
<List.Item title="Headline" description="Supporting text" />
Expand All @@ -21,16 +37,25 @@ const ListItemExample = () => {
description="Supporting text that is long enough to fill up multiple lines in the item"
/>
<Divider />
<List.Item title="Headline" right={() => <CenteredCheckbox />} />
<List.Item
title="Headline"
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<List.Item
title="Headline"
description="Supporting text"
right={() => <CenteredCheckbox />}
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<List.Item
title="Headline"
description="Supporting text that is long enough to fill up multiple lines in the item"
right={() => <Checkbox status="checked" aria-label="Headline" />}
right={(props) => (
<Checkbox
status="checked"
aria-label="Headline"
style={props.style}
/>
)}
/>
<Divider />
</List.Section>
Expand All @@ -54,19 +79,25 @@ const ListItemExample = () => {
<List.Item
title="Headline"
left={(props) => <List.Icon {...props} icon="account-outline" />}
right={() => <CenteredCheckbox />}
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<List.Item
title="Headline"
description="Supporting text"
left={(props) => <List.Icon {...props} icon="account-outline" />}
right={() => <CenteredCheckbox />}
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<List.Item
title="Headline"
description="Supporting text that is long enough to fill up multiple lines in the item"
left={(props) => <List.Icon {...props} icon="account-outline" />}
right={() => <Checkbox status="checked" aria-label="Headline" />}
right={(props) => (
<Checkbox
status="checked"
aria-label="Headline"
style={props.style}
/>
)}
/>
<Divider />
</List.Section>
Expand Down Expand Up @@ -98,23 +129,29 @@ const ListItemExample = () => {
left={(props) => (
<Avatar.Text style={props.style} label="A" size={40} />
)}
right={() => <CenteredCheckbox />}
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<List.Item
title="Headline"
description="Supporting text"
left={(props) => (
<Avatar.Text style={props.style} label="A" size={40} />
)}
right={() => <CenteredCheckbox />}
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<List.Item
title="Headline"
description="Supporting text that is long enough to fill up multiple lines in the item"
left={(props) => (
<Avatar.Text style={props.style} label="A" size={40} />
)}
right={() => <Checkbox status="checked" aria-label="Headline" />}
right={(props) => (
<Checkbox
status="checked"
aria-label="Headline"
style={props.style}
/>
)}
/>
<Divider />
</List.Section>
Expand Down Expand Up @@ -158,7 +195,7 @@ const ListItemExample = () => {
source={require('../../../example/assets/images/strawberries.jpg')}
/>
)}
right={() => <CenteredCheckbox />}
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<List.Item
title="Headline"
Expand All @@ -169,7 +206,7 @@ const ListItemExample = () => {
source={require('../../../example/assets/images/strawberries.jpg')}
/>
)}
right={() => <CenteredCheckbox />}
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<List.Item
title="Headline"
Expand All @@ -180,7 +217,13 @@ const ListItemExample = () => {
source={require('../../../example/assets/images/strawberries.jpg')}
/>
)}
right={() => <Checkbox status="checked" aria-label="Headline" />}
right={(props) => (
<Checkbox
status="checked"
aria-label="Headline"
style={props.style}
/>
)}
/>
<Divider />
</List.Section>
Expand Down Expand Up @@ -228,7 +271,7 @@ const ListItemExample = () => {
source={require('../../../example/assets/images/strawberries.jpg')}
/>
)}
right={() => <CenteredCheckbox />}
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<List.Item
title="Headline"
Expand All @@ -240,7 +283,7 @@ const ListItemExample = () => {
source={require('../../../example/assets/images/strawberries.jpg')}
/>
)}
right={() => <CenteredCheckbox />}
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<List.Item
title="Headline"
Expand All @@ -252,56 +295,56 @@ const ListItemExample = () => {
source={require('../../../example/assets/images/strawberries.jpg')}
/>
)}
right={() => <Checkbox status="checked" aria-label="Headline" />}
right={(props) => (
<Checkbox
status="checked"
aria-label="Headline"
style={props.style}
/>
)}
/>
<Divider />
</List.Section>

<List.Section title="With switch">
<List.Item
title="Headline"
right={() => <Switch disabled style={styles.centered} />}
right={(props) => <Switch disabled style={props.style} />}
/>
<List.Item
title="Headline"
description="Supporting text"
right={() => <Switch disabled style={styles.centered} />}
right={(props) => <Switch disabled style={props.style} />}
/>
<List.Item
title="Headline"
description="Supporting text that is long enough to fill up multiple lines in the item"
right={() => <Switch disabled />}
right={(props) => <Switch disabled style={props.style} />}
/>
<Divider />
<List.Item
title="Headline"
left={(props) => <List.Icon {...props} icon="account-outline" />}
right={() => <Switch disabled style={styles.centered} />}
right={(props) => <Switch disabled style={props.style} />}
/>
<List.Item
title="Headline"
description="Supporting text"
left={(props) => <List.Icon {...props} icon="account-outline" />}
right={() => <Switch disabled style={styles.centered} />}
right={(props) => <Switch disabled style={props.style} />}
/>
<List.Item
title="Headline"
description="Supporting text that is long enough to fill up multiple lines in the item"
left={(props) => <List.Icon {...props} icon="account-outline" />}
right={() => <Switch disabled />}
right={(props) => <Switch disabled style={props.style} />}
/>
<Divider />
</List.Section>
</ScreenWrapper>
);
};

const styles = StyleSheet.create({
centered: {
alignSelf: 'center',
},
});

ListItemExample.title = 'List.Item';

export default ListItemExample;
Loading
Loading