React Native Picker for iOS, Android, macOS, and Windows
npm install @react-native-picker/picker@react-native-picker/picker
 !Supports Android, iOS, MacOS, and Windows !MIT License 
| Android | iOS | PickerIOS |
| --- | --- | --- |
|
|
| 
| Windows | MacOS |
| --- | --- |
|
| 
| @react-native-picker/picker | react-native | react-native-windows |
| --- | --- | --- |
| >= 2.0.0 | 0.61+ | 0.64+ |
| >= 1.16.0 | 0.61+ | 0.61+ |
| >= 1.2.0 | 0.60+ or 0.59+ with Jetifier | N/A |
| >= 1.0.0 | 0.57 | N/A |
$ npm install @react-native-picker/picker --save
or
$ yarn add @react-native-picker/picker
As react-native@0.60 and above supports autolinking there is no need to run the linking process.
Read more about autolinking here. This is supported by react-native-windows@0.64 and above.
#### iOS
CocoaPods on iOS needs this extra step:
```
npx pod-install
#### Android
No additional step is required.
Windows (expand for details)
#### Windows
Usage in Windows without autolinking requires the following extra steps:
##### Add the ReactNativePicker project to your solution.
1. Open the solution in Visual Studio 2019
2. Right-click Solution icon in Solution Explorer > Add > Existing Project
Select D:\dev\RNTest\node_modules\@react-native-picker\picker\windows\ReactNativePicker\ReactNativePicker.vcxproj
##### windows/myapp.sln
Add a reference to ReactNativePicker to your main application project. From Visual Studio 2019:
Right-click main application project > Add > Reference...
Check ReactNativePicker from Solution Projects.
##### app.cpp
Add #include "winrt/ReactNativePicker.h" to the headers included at the top of the file.
Add PackageProviders().Append(winrt::ReactNativePicker::ReactPackageProvider()); before InitializeComponent();.
#### MacOS
CocoaPods on MacOS needs this extra step (called from the MacOS directory)
``
pod install
React Native below 0.60 (Link and Manual Installation)
The following steps are only necessary if you are working with a version of React Native lower than 0.60
$ react-native link @react-native-picker/picker
#### iOS
1. In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]node_modules
2. Go to ➜ @react-native-picker/picker and add RNCPicker.xcodeprojlibRNCPicker.a
3. In XCode, in the project navigator, select your project. Add to your project's Build Phases ➜ Link Binary With LibrariesCmd+R
4. Run your project ()<
#### Android
1. Open application file (android/app/src/main/java/[...]/MainApplication.java)import com.reactnativecommunity.picker.RNCPickerPackage;
- Add to the imports at the top of the filenew RNCPickerPackage()
- Add to the list returned by the getPackages() methodandroid/settings.gradle
2. Append the following lines to :`
`
include ':@react-native-picker_picker'
project(':@react-native-picker_picker').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-picker/picker/android')
android/app/build.gradle
3. Insert the following lines inside the dependencies block in :`
`
implementation project(path: ':@react-native-picker_picker')
#### MacOS
1. In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]node_modules
2. Go to ➜ @react-native-picker/picker and add RNCPicker.xcodeprojlibRNCPicker.a
3. In XCode, in the project navigator, select your project. Add to your project's Build Phases ➜ Link Binary With LibrariesCmd+R
4. Run your project ()<
you need to add android:supportsRtl="true" to AndroidManifest.xml`xml`
android:supportsRtl="true">
Import Picker from @react-native-picker/picker:
`javascript`
import {Picker} from '@react-native-picker/picker';
Create state which will be used by the Picker:
`javascript`
const [selectedLanguage, setSelectedLanguage] = useState();
Add Picker like this:
`javascript`
onValueChange={(itemValue, itemIndex) =>
setSelectedLanguage(itemValue)
}>
If you want to open/close picker programmatically on android (available from version 1.16.0+), pass ref to Picker:
`javascript
const pickerRef = useRef();
function open() {
pickerRef.current.focus();
}
function close() {
pickerRef.current.blur();
}
return
selectedValue={selectedLanguage}
onValueChange={(itemValue, itemIndex) =>
setSelectedLanguage(itemValue)
}>
`
- onValueChange
- selectedValue
- style
- testID
- enabled
- mode
- prompt
- itemStyle
- selectionColor
---
Callback for when an item is selected. This is called with the following parameters:
* itemValue: the value prop of the item that was selecteditemPosition
* : the index of the selected item in this picker
| Type | Required |
| -------- | -------- |
| function | No |
---
Value matching value of one of the items. Can be a string or an integer.
| Type | Required |
| ---- | -------- |
| any | No |
---
| Type | Required |
| --------------- | -------- |
| pickerStyleType | No |
---
Used to locate this view in end-to-end tests.
| Type | Required |
| ------ | -------- |
| string | No |
---
If set to false, the picker will be disabled, i.e. the user will not be able to make a selection.
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | Android, Web, Windows |
---
On Android, specifies how to display the selection items when the user taps on the picker:
* 'dialog': Show a modal dialog. This is the default.
* 'dropdown': Shows a dropdown anchored to the picker view
| Type | Required | Platform |
| -------------------------- | -------- | -------- |
| enum('dialog', 'dropdown') | No | Android |
---
On Android, specifies color of dropdown triangle. Input value should be value that is accepted by react-native processColor function.
| Type | Required | Platform |
| ---------- | -------- | -------- |
| ColorValue | No | Android |
---
On Android, specifies ripple color of dropdown triangle. Input value should be value that is accepted by react-native processColor function.
| Type | Required | Platform |
| ---------- | -------- | -------- |
| ColorValue | No | Android |
---
Prompt string for this picker, used on Android in dialog mode as the title of the dialog.
| Type | Required | Platform |
| ------ | -------- | -------- |
| string | No | Android |
---
Style to apply to each of the item labels.
| Type | Required | Platform |
| ---------------------------------- | -------- | -------- |
| text styles | No | iOS, Windows |
On Android & iOS, used to truncate the text with an ellipsis after computing the text layout, including line wrapping,
such that the total number of lines does not exceed this number. Default is '1'
| Type | Required | Platform |
| ------- | -------- | -------- |
| number | No | Android, iOS |
| Type | Required | Platform |
| --------- | -------- | -------- |
| function | No | Android |
| Type | Required | Platform |
| --------- | -------- | -------- |
| function | No | Android |
| Type | Required | Platform |
| ------- | -------- | -------- |
| ColorValue | No | iOS |
Programmatically closes picker
Programmatically opens picker
Props that can be applied to individual Picker.Item
Displayed value on the Picker Item
| Type | Required |
| ------- | -------- |
| string | Yes |
Actual value on the Picker Item
| Type | Required |
| ------- | -------- |
| number,string | Yes |
Displayed color on the Picker Item
| Type | Required |
| ----------- | -------- |
| ColorValue | No |
Displayed fontFamily on the Picker Item
| Type | Required |
| ------- | -------- |
| string | No |
Style to apply to individual item labels.
| Type | Required | Platform |
| ------- | -------- | -------- |
| ViewStyleProp | No | Android |
If set to false, the specific item will be disabled, i.e. the user will not be able to make a selection
@default: true
| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | Android |
Sets the content description to the Picker Item
| Type | Required | Platform |
| ------ | -------- | -------- |
| string | No | Android |
- Inherited View props...
- itemStyle
- onValueChange
- selectedValue
- selectionColor
- themeVariant`
---
| Type | Required |
| ---------------------------------- | -------- |
| text styles | No |
---
| Type | Required |
| -------- | -------- |
| function | No |
---
| Type | Required |
| ---- | -------- |
| any | No |
---
| Type | Required | Platform |
| ------- | -------- | -------- |
| ColorValue | No | iOS |
---
| Type | Required |
| ---- | -------- |
| enum('light', 'dark') | No |