Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlatList Integration #46

Merged
merged 1 commit into from
Jul 5, 2020
Merged
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
89 changes: 50 additions & 39 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
TouchableOpacity,
ScrollView,
Platform,
TextInput
TextInput,
FlatList
} from 'react-native';
import PropTypes from 'prop-types';

Expand Down Expand Up @@ -200,6 +201,47 @@ class DropDownPicker extends React.Component {
return this.props.multipleText.replace('%d', this.state.choice.length);
}

_renderItem = ({item,index})=> {
return (
<TouchableOpacity
key={index}
onPress={() => 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}
>
<Text style={[this.props.labelStyle,
this.state.choice.value === item.value && this.props.activeLabelStyle
]}>{item.label}</Text>
{
this.state.props.multiple && this.state.choice.findIndex(i => i.label === item.label && i.value === item.value) > -1 && (
this.props.customTickIcon()
)
}
</TouchableOpacity>
)
}

_renderEmptyContainer = () => {
return (
<Text style={[styles.notFound, {
fontFamily: this.props.labelStyle?.fontFamily
}]}>
{this.props.searchableError}
</Text>
)
}

render() {
const { multiple, disabled } = this.state.props;
const { placeholder } = this.props;
Expand Down Expand Up @@ -278,44 +320,13 @@ class DropDownPicker extends React.Component {
)
}

<ScrollView style={{width: '100%'}} nestedScrollEnabled={true}>
{
items.length > 0 ? items.map((item, index) => (
<TouchableOpacity
key={index}
onPress={() => 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}
>
<Text style={[this.props.labelStyle,
this.state.choice.value === item.value && this.props.activeLabelStyle
]}>{item.label}</Text>
{
multiple && this.state.choice.findIndex(i => i.label === item.label && i.value === item.value) > -1 && (
this.props.customTickIcon()
)
}
</TouchableOpacity>
)) : (
<Text style={[styles.notFound, {
fontFamily: this.props.labelStyle?.fontFamily
}]}>
{this.props.searchableError}
</Text>
)
}
</ScrollView>
<FlatList
style={{width: '100%'}}
data={items}
renderItem={this._renderItem}
keyExtractor={(item, index) => index.toString()}
ListEmptyComponent={this._renderEmptyContainer}>
</FlatList>
</View>
</View>
);
Expand Down