README.md 3.65 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
xwenliang committed
5
A Native Picker with high performance.
xwenliang's avatar
init  
xwenliang committed
6

xwenliang's avatar
xwenliang committed
7
pure javascript version -> [v3.0.5](https://github.com/beefe/react-native-picker/tree/pure-javascript-version)
xwenliang's avatar
xwenliang committed
8 9


xwenliang's avatar
xwenliang committed
10 11
![ui](./doc/ui.gif)

xwenliang's avatar
xwenliang committed
12 13
![ui2](./doc/ui2.jpg)

xwenliang's avatar
init  
xwenliang committed
14 15
###Documentation

xwenliang's avatar
bugs  
xwenliang committed
16
####Props
xwenliang's avatar
xwenliang committed
17 18 19
- <b>pickerConfirmBtnText</b> string, 确认按钮文字
- <b>pickerCancelBtnText</b> string, 取消按钮文字
- <b>pickerTitleText</b> string, 标题文字
xwenliang's avatar
xwenliang committed
20 21 22 23 24
- <b>pickerConfirmBtnColor</b> [1, 186, 245, 1],  确认按钮字体颜色
- <b>pickerCancelBtnColor</b> [1, 186, 245, 1],  取消按钮字体颜色
- <b>pickerTitleColor</b> [20, 20, 20, 1],  标题字体颜色
- <b>pickerToolBarBg</b> [232, 232, 232, 1],  工具栏背景颜色
- <b>pickerBg</b> [196, 199, 206, 1],  picker背景颜色
xwenliang's avatar
xwenliang committed
25 26 27 28 29
- <b>pickerData</b> 数组或对象,picker数据
- <b>selectedValue</b> string,默认选中数据
- <b>onPickerConfirm</b> function,确认按钮回调
- <b>onPickerCancel</b> function,取消按钮回调
- <b>onPickerSelect</b> function,滚轮滚动时回调
xwenliang's avatar
bugs  
xwenliang committed
30

xwenliang's avatar
xwenliang committed
31 32
####Methods
- <b>toggle</b> show or hide picker, default to be hiden
xwenliang's avatar
xwenliang committed
33 34 35
- <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
36

xwenliang's avatar
bugs  
xwenliang committed
37 38 39 40 41 42 43 44
###Usage

####Step 1 - install

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

xwenliang's avatar
xwenliang committed
45 46 47 48 49 50 51
####Step 2 - link

```
	react-native link
```

####Step 3 - import and use in project
xwenliang's avatar
bugs  
xwenliang committed
52 53

```javascript
xwenliang's avatar
xwenliang committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
	import Picker from 'react-native-picker';

	let data = [];
    for(var i=0;i<100;i++){
        data.push(i);
    }

    Picker.init({
        pickerData: data,
        selectedValue: [59],
        onPickerConfirm: data => {
            console.log(data);
        },
        onPickerCancel: data => {
            console.log(data);
        },
        onPickerSelect: data => {
            console.log(data);
        }
    });
    Picker.show();
xwenliang's avatar
bugs  
xwenliang committed
75
	
xwenliang's avatar
xwenliang committed
76 77 78 79 80 81
```

###Notice

####support two modes:

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

xwenliang's avatar
xwenliang committed
84
<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
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

####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
xwenliang's avatar
xwenliang committed
111 112 113 114 115 116 117 118 119 120
    pickerData = [
        {
            a: [1, 2, 3, 4]
        },
        {
            b: [5, 6, 7, 8]
        },
        ...
    ];
    selectedValue = ['a', 2];
xwenliang's avatar
xwenliang committed
121 122 123 124 125
```

- three wheel

```javascript
xwenliang's avatar
xwenliang committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
    pickerData = [
        {
            a: [
                {
                    a1: [1, 2, 3, 4]
                },
                {
                    a2: [5, 6, 7, 8]
                },
                {
                    a3: [9, 10, 11, 12]
                }
            ]
        },
        {
            b: [
                {
                    b1: [11, 22, 33, 44]
                },
                {
                    b2: [55, 66, 77, 88]
                },
                {
                    b3: [99, 1010, 1111, 1212]
                }
            ]
        },
        {
            c: [
                {
                    c1: ['a', 'b', 'c']
                },
                {
                    c2: ['aa', 'bb', 'cc']
                },
                {
                    c3: ['aaa', 'bbb', 'ccc']
                }
            ]
        },
xwenliang's avatar
xwenliang committed
166
        ...
xwenliang's avatar
xwenliang committed
167 168
    ]
```