I have implemented the react-native-dropdown-picker. It's working fine, but I would like to customize the items in the dropdown list. I cannot find any examples on how to do this - not even on their page...
Specifically, what I'm after is a small representation of a color as a prefix to the name of the color
There's a function called "renderListItem", that's referenced on their page, but it's not documented very well.
With this implementation, I get what I'm after: a 20x20 pixel representation of the color of the item - but the selection is not sticking...
function handleListItemPress(itemProps) {
itemProps.onPress(itemProps);
}
<DropDownPicker
// closeAfterSelecting={true}
showTickIcon={true}
onOpen={onlyOneOpenDropDownPicker('backgroundcolor')}
style={styles.dropDown}
placeholder='Select backgroundColor'
open={backgroundColorsOpen}
value={selectedBackgroundColor}
items={colors}
setOpen={setBackgroundColorsOpen}
setValue={setSelectedBackgroundColor}
// setItems={setItems}
schema={{
label: 'color',
value: 'color',
}}
searchable={true}
renderListItem={( {
onPress,
value,
label,
isSelected,
}) => {
return (
<TouchableOpacity
onPress={() => onPress(value)}
style={{ flexDirection: 'row', padding: 5 }}>
<View
style={{
backgroundColor: value.toString(),
width: 20,
height: 20,
}}
/>
<Text>{label}</Text>
</TouchableOpacity>
);
}}
/>
So, i finally made it work! This is proof that sometimes you really need to take a break...
A working DropDownPicker;