react-native-selectbox v0.1.2
react-native-selectbox
This is a platform independant (Android / iOS) version of the native picker / selectbox that react-native has. It's basically the Android version and the iOS version merged into one: only show a single selected label and only after clicking on this show the full list of items.
This is a derivation of the react-native-modal-picker by d-a-n I've simplified this a bit and removed alot
of state handling preferring outside control. This allows for Redux state handling. I've also added the option of having the react-native-picker prompt feature.
The prompt is a simple text above the list inside the modal.
Install
npm i react-native-selectbox --saveUsage
You can either use this component as an wrapper around your existing component or use it in its default mode. In default mode a customizable button is rendered.
See SampleApp for an example how to use this component.
import Selectbox from 'react-native-selectbox'
[..]
class App extends React.Component {
...
_onChange = (item) => {
// the full item as defined in the list of items is passed to the onChange handler to give full
// flexibility on what to do...
}
render() {
const items = [
{ key: 0, label: 'Fruits', value:'some value' },
{ key: 1, label: 'Fruits', value:{this: "could", be:"anything"} },
];
return (
<View>
<Selectbox
selectedItem=this.props.selectedItem
onChange={this._onChange}
items=items />
</View>
);
}
}Props
items - []required, array of objects with a unique key and labelselectedItem - objectrequired, the selected Item to be rendered directlypromptLabel - objectoptional, a string which will appear above the list of options / pickercancelLabel - objectoptional, a string to be shown on the modal (defaults:cancel)onChange - functionoptional, callback function, when the user selects an itemanimationType - functionoptional, a string for the animation used to show the modal (defaults:slide)transparent - functionoptional, a boolean value for the transparency of the modalstyle - objectoptional, style definitions for the root elementoptionLabelStyle - stringoptional, style definitions for each element from the optionsselectLabelStyle - objectoptional, style definitions for currently selected item