README.md 3.12 KB
Newer Older
xwenliang's avatar
init  
xwenliang committed
1 2
# react-native-picker

xwenliang's avatar
xwenliang committed
3
[![npm version](https://img.shields.io/npm/v/react-native-picker.svg?style=flat-square)](https://www.npmjs.com/package/react-native-picker) <a href="https://david-dm.org/beefe/react-native-picker"><img src="https://david-dm.org/beefe/react-native-picker.svg?style=flat-square" alt="dependency status"></a>  
4

xwenliang's avatar
init  
xwenliang committed
5 6
A Picker written in pure javascript for cross-platform support.

xwenliang's avatar
bugs  
xwenliang committed
7
It was most likely an example of how to build a cross-platform Picker Component use [react-native-picker-android](https://github.com/beefe/react-native-picker-android).
xwenliang's avatar
init  
xwenliang committed
8

xwenliang's avatar
xwenliang committed
9
###Warn
xwenliang's avatar
xwenliang committed
10
if 0.14.2 <= react-native <=0.24 `npm install react-native-picker@2.0.5 --save`  
xwenliang's avatar
xwenliang committed
11
if 0.24 < react-native `npm install react-native-picker --save`
xwenliang's avatar
init  
xwenliang committed
12

xwenliang's avatar
xwenliang committed
13 14 15 16 17 18
####Demo

- <b>[Date-picker](./demo/date-picker.js)</b>
- <b>[Area-picker](./demo/area-picker.js)</b>


xwenliang's avatar
xwenliang committed
19 20
![ui](./doc/ui.gif)

xwenliang's avatar
xwenliang committed
21 22
![ui2](./doc/ui2.jpg)

xwenliang's avatar
init  
xwenliang committed
23 24
###Documentation

xwenliang's avatar
bugs  
xwenliang committed
25
####Props
xwenliang's avatar
xwenliang committed
26
- <b>style</b> style of picker, you can set width and height of picker in this prop
xwenliang's avatar
xwenliang committed
27
- <b>pickerElevation</b> elevation of picker (for issue https://github.com/beefe/react-native-picker/issues/27)
xwenliang's avatar
xwenliang committed
28 29
- <b>pickerBtnText</b> string, tool bar's confirm btn text
- <b>pickerCancelBtnText</b> string, tool bar's cancel ben text
xwenliang's avatar
xwenliang committed
30 31
- <b>pickerBtnStyle</b> textStylePropType, tool bar's btn style
- <b>pickerToolBarStyle</b> viewStylePropType, tool bar's style
xwenliang's avatar
xwenliang committed
32
- <b>showDuration</b> number, animation of picker
xwenliang's avatar
xwenliang committed
33
- <b>showMask</b> boolean, default to be false, cancel the picker by tapping in the rest of the screen support when setted to be true
xwenliang's avatar
xwenliang committed
34 35
- <b>pickerTitle</b> string, title of picker
- <b>pickerTitleStyle</b> textStylePropType, style of title
xwenliang's avatar
bugs  
xwenliang committed
36 37 38
- <b>pickerData</b> array
- <b>selectedValue</b> any
- <b>onPickerDone</b> function
xwenliang's avatar
xwenliang committed
39
- <b>onPickerCancel</b> function
xwenliang's avatar
xwenliang committed
40
- <b>onValueChange</b> function
xwenliang's avatar
bugs  
xwenliang committed
41

xwenliang's avatar
xwenliang committed
42 43
####Methods
- <b>toggle</b> show or hide picker, default to be hiden
xwenliang's avatar
xwenliang committed
44 45 46
- <b>show</b> show picker
- <b>hide</b> hide picker
- <b>isPickerShow</b> get status of picker, return a boolean
xwenliang's avatar
xwenliang committed
47

xwenliang's avatar
bugs  
xwenliang committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61
###Usage

####Step 1 - install

```
	npm install react-native-picker --save
```

####Step 2 - import and use in project

```javascript
	import Picker from 'react-native-picker'
	
	<Picker
xwenliang's avatar
xwenliang committed
62 63
		style={{
			height: 300
Matt Shaffer's avatar
Matt Shaffer committed
64
		}}
xwenliang's avatar
bugs  
xwenliang committed
65
		showDuration={300}
xwenliang's avatar
xwenliang committed
66
		showMask={true}
xwenliang's avatar
bugs  
xwenliang committed
67 68 69 70
		pickerData={}//picker`s value List
		selectedValue={}//default to be selected value
		onPickerDone={}//when confirm your choice
	/>
xwenliang's avatar
xwenliang committed
71 72 73 74 75 76
```

###Notice

####support two modes:

xwenliang's avatar
xwenliang committed
77
<b>1. parallel:</b> such as time picker, wheels have no connection with each other
xwenliang's avatar
xwenliang committed
78

xwenliang's avatar
xwenliang committed
79
<b>2. cascade:</b> such as date picker, address picker .etc, when front wheel changed, the behind wheels will all be reset
xwenliang's avatar
xwenliang committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

####parallel:

- single wheel:

```javascript
	pickerData = [1,2,3,4];
	selectedValue = 3;
```

- two or more wheel:

```javascript
	pickerData = [
		[1,2,3,4],
		[5,6,7,8],
		...
	];
	selectedValue = [1, 5];
```

####cascade:

- two wheel

```javascript
	pickerData = {
		{
			a: [1,2,3,4],
			b: [5,6,7,8],
			...
		}
	};
	selectedValue = ['a', 2];
```

- three wheel

```javascript
	pickerData = {
		a: {
			a1: [1,2,3,4],
			a2: [5,6,7,8],
			a3: [9,10,11,12]
		},
		b: {
			b1: [1,2,3,4],
			b2: [5,6,7,8],
			b3: [9,10,12,12]
		}
		...
	};
	selectedValue = ['a', 'a1', 1];
```