-
Notifications
You must be signed in to change notification settings - Fork 3
ListItem React Native Elements
Nandini Bulusu edited this page Mar 21, 2019
·
6 revisions
ListItem is a Component from React Native Elements. To import, place this at the top of your screen file.
import { ListItem } from 'react-native-elements';
FlatList is an interface that renders simple, flat lists. ListItem's props can be seen here.
keyExtractor = (item, index) => index.toString();
renderItem = ({ item }) => (
<ListItem
title={item.yourtitle}
/>
)
render() {
return (
<FlatList
keyExtractor = {this.keyExtractor}
data={your_data}
renderItem={this.renderItem}
/>
);
}
To add a Checkbox in the ListItem, we have to implement the CheckBox Component. The full list of props are located here.
state = { checked: [], } // Need a state for checking the box
press = item => { // The onPress method
const { checked } = this.state;
// These ensures that multiple checkboxes don't all get affected when one is clicked
if (!checked.includes(item)) {
this.setState({ checked: [...checked, item] });
} else {
this.setState({ checked: checked.filter(a => a !== item) });
}
};
keyExtractor = (item, index) => index.toString();
renderItem = ({ item }) => (
<ListItem
checkBox= {{ // CheckBox Props
checkedIcon: 'circle',
uncheckedIcon: 'circle',
checkedColor:'#B6BF00',
uncheckedColor: '#B6BF80',
onPress: () => this.press(item),
checked: this.state.checked.includes(item),
}}
title={item.yourtitle}
chevron={true}
/>
)
render() {
return (
<FlatList
keyExtractor = {this.keyExtractor}
data={your_data}
extraData={this.state} // FlatList will then re-render if the state is changed.
renderItem={this.renderItem}
/>
);
}
Multiple Checkboxes being changed when one is clicked: here
DDA iOS and Android App. Developed by Code the Change Foundation
Developer Documentation
Mockup
Database
API
User Management
React Native
Research