1.0.1 • Published 5 years ago
react-native-flatlist-picker v1.0.1
react-native-flatlist-picker
A cross-platform (iOS / Android), selector/picker component for React Native that is highly customizable and supports sections.
Demo
Install
npm i react-native-flatlist-picker --saveUsage
You can use this component to create piker
Support custom style, PickerItem, PickerCoponent, Animation
See this Code below for an example how to use this component.
Developed from react-native-modal-dropdown
import React, { Component } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import AntDesign from 'react-native-vector-icons/AntDesign'
import { TouchableOpacity } from 'react-native-gesture-handler';
import FlatListPicker from 'react-native-flatlist-picker';
[..]
const dataPicker = [
{ value: 'Value 1', key: 'key1' },
{ value: 'Value 2', key: 'key2' },
{ value: 'Value 3', key: 'key3' },
{ value: 'Value 4', key: 'key4' }
]
class Example extends Component {
constructor(props) {
super(props);
}
componentDidMount = () => {
// To show or hide your picker component
// this.PickerFlatlist.showPickerList()
}
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<TouchableOpacity onPress={() => {
this.FlatListPicker.showPickerList()
// this.FlatListPicker.hidePickerList()
}}
>
<Text style={{ textDecorationLine: 'underline' }}> Press To Show FlatListPicker</Text>
</TouchableOpacity>
<FlatListPicker
ref={ref => { this.FlatListPicker = ref }}
data={dataPicker}
containerStyle={styles.container}
dropdownStyle={{ width: 180 }}
dropdownTextStyle={{ fontSize: 15 }}
pickedTextStyle={{ color: 'black', fontWeight: 'bold' }}
animated="slide"
defaultValue="FlatListPicker...."
renderDropdownIcon={() => (<AntDesign name="caretdown" color="blue" size={15} style={{ padding: 15 }} />)}
onValueChange={(value, index) => alert(`Selected ${value}`)}
/>
</View>
);
}
}
export default TestPicker;
const styles = StyleSheet.create({
container: {
borderWidth: 1,
borderColor: '#CECECE',
width: 250,
height: 50,
alignSelf: 'center',
justifyContent: 'space-between',
alignItems: 'center',
flexDirection: 'row',
marginTop: 30,
padding: 5,
}
});Props
data - []required, array of objects with a unique value and itemcontainerStyle - objectoptional, style definitions for the root elementonValueChange - functionoptional, callback function, when the users has selected an optiondefaultValue - stringoptional, text that is initially shown on the buttonrenderDropdownIcon - functionoptional, to render icon dropdownanimated - stringoptional, define type of animation to show pickerpickedTextStyle - objectstyle for text in pickerItemdropdownStyle - objectoptional, style for container pickerdisableTouchContainer - booleanoptional, to disable container touchable opacityrenderItem - functionoptional, to custom picker itemProps from react-native-modal-dropdownhttps://www.npmjs.com/package/react-native-modal-dropdown#api