From 5210c54cd9ee201441bb84bce7ee75df1c25e948 Mon Sep 17 00:00:00 2001 From: Dilina Date: Sat, 4 Jul 2020 21:13:01 +0530 Subject: [PATCH] FlatList Integration --- src/index.js | 89 +++++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 39 deletions(-) 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}> + );