diff --git a/src/index.js b/src/index.js index 019e655e..3a319618 100644 --- a/src/index.js +++ b/src/index.js @@ -6,7 +6,8 @@ import { TouchableOpacity, ScrollView, Platform, - TextInput + TextInput, + FlatList } from 'react-native'; import PropTypes from 'prop-types'; @@ -200,6 +201,47 @@ class DropDownPicker extends React.Component { return this.props.multipleText.replace('%d', this.state.choice.length); } + _renderItem = ({item,index})=> { + return ( + this.select(item, index)} + style={[styles.dropDownItem, this.props.itemStyle, ( + this.state.choice.value === item.value && this.props.activeItemStyle + ), { + opacity: item?.disabled || false === true ? 0.3 : 1, + ...( + this.state.props.multiple && { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'space-between' + } + ) + }]} + disabled={item?.disabled || false === true} + > + {item.label} + { + this.state.props.multiple && this.state.choice.findIndex(i => i.label === item.label && i.value === item.value) > -1 && ( + this.props.customTickIcon() + ) + } + + ) + } + + _renderEmptyContainer = () => { + return ( + + {this.props.searchableError} + + ) + } + render() { const { multiple, disabled } = this.state.props; const { placeholder } = this.props; @@ -278,44 +320,13 @@ class DropDownPicker extends React.Component { ) } - - { - items.length > 0 ? items.map((item, index) => ( - this.select(item, index)} - style={[styles.dropDownItem, this.props.itemStyle, ( - this.state.choice.value === item.value && this.props.activeItemStyle - ), { - opacity: item?.disabled || false === true ? 0.3 : 1, - ...( - multiple && { - flexDirection: 'row', - alignItems: 'center', - justifyContent: 'space-between' - } - ) - }]} - disabled={item?.disabled || false === true} - > - {item.label} - { - multiple && this.state.choice.findIndex(i => i.label === item.label && i.value === item.value) > -1 && ( - this.props.customTickIcon() - ) - } - - )) : ( - - {this.props.searchableError} - - ) - } - + index.toString()} + ListEmptyComponent={this._renderEmptyContainer}> + );