1.2.0 • Published 5 years ago

@nois/react-native-picker-module v1.2.0

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

React Native Picker Module

With this package you can easily use picker with onPress function. Also this package is workaround for Android Picker problem (https://github.com/facebook/react-native/issues/15556).

Using Modal and Picker component for IOS and using RecyclerView and AlertDialog for Android as NativeModule.

Version 1.1.1

Version 1.0.1

Getting Started

With NPM

npm install --save react-native-picker-module

With YARN

yarn add react-native-picker-module

Automatic linking

react-native link react-native-picker-module

Manual Linking

Manual Installation (If something went wrong with react-native link)

Props

PropsTypeDefaultRequiredOS
valuenumber-NoAndroid, IOS
itemsarray-YesAndroid, IOS
titlestring-NoAndroid, IOS
iosobject{duration: 330, overlayColor: 'rgba(0,0,0,0.3)'}NoIOS
pickerReffunc-YesAndroid, IOS
onValueChangefunc-YesAndroid, IOS
onCancelfunc-NoAndroid, IOS
cancelButtonstringCancelNoIOS
confirmButtonstringConfirmNoIOS

Usage

import ReactNativePickerModule from 'react-native-picker-module'

state = {
    selectedValue: null,
    data: [
        "Javascript",
        "Go",
        "Java",
        "Kotlin",
        "C++",
        "C#",
        "PHP"
    ]
};

<TouchableOpacity onPress={() => {this.pickerRef.show()}}>
  <Text>Show Language Picker</Text>
</TouchableOpacity>

<ReactNativePickerModule
  pickerRef={e => this.pickerRef = e}
  value={this.state.selectedValue}
  title={"Select a language"}
  items={this.state.data}
  onCancel={()=>{console.log('Cancelled')}}
  onValueChange={(value, index ) => {
  console.log("value: ",value)
  console.log("index: ",index)
    this.setState({
       selectedValue: value,
       selectedIndex: index,
    })
}}/>

FYI

You can use more than one picker in same screen. You just need to set different pickerRef.

this.languagePicker.show();

<ReactNativePickerModule
  pickerRef={e => this.languagePicker = e}
  value={this.state.selectedValue}
  title={"Select a language"}
  items={this.state.data}
  onValueChange={(value,index) => {
        console.log("value: ",value)
        console.log("index: ",index)
    this.setState({
       selectedValue: value,
       selectedIndex: index,
    })
}}/>

p.s : If you want to get country list from native device you can use this package: https://github.com/talut/react-native-countries

this.countryPicker.show();
<ReactNativePickerModule
  pickerRef={e => this.countryPicker = e}
  value={this.state.selectedValue}
  title={"Select a country"}
  items={this.state.data}
  onValueChange={(value,index) => {
    console.log("value: ",value)
    console.log("index: ",index)
    this.setState({
       selectedValue: value,
       selectedIndex: index,
    })
}}/>

License

This project is licensed under the MIT License - see the LICENSE.md file for details