Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
79 changes: 46 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" />
</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,19 @@ 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" />}
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<Divider />
</List.Section>
Expand All @@ -54,19 +73,19 @@ 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" />}
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<Divider />
</List.Section>
Expand Down Expand Up @@ -98,23 +117,23 @@ 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" />}
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<Divider />
</List.Section>
Expand Down Expand Up @@ -158,7 +177,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 +188,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 +199,7 @@ const ListItemExample = () => {
source={require('../../../example/assets/images/strawberries.jpg')}
/>
)}
right={() => <Checkbox status="checked" />}
right={(props) => <Checkbox status="checked" style={props.style} />}
/>
<Divider />
</List.Section>
Expand Down Expand Up @@ -228,7 +247,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 +259,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 +271,50 @@ const ListItemExample = () => {
source={require('../../../example/assets/images/strawberries.jpg')}
/>
)}
right={() => <Checkbox status="checked" />}
right={(props) => <Checkbox status="checked" 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