README.md 4.85 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 6
![ui3](./doc/ui3.jpg)
![ui4](./doc/ui4.jpg)
xwenliang's avatar
xwenliang committed
7

zooble's avatar
zooble committed
8
### Documentation
xwenliang's avatar
init  
xwenliang committed
9

zooble's avatar
zooble committed
10
#### Params
xwenliang's avatar
xwenliang committed
11

xwenliang's avatar
xwenliang committed
12 13 14 15 16 17 18
|Key | Description | Type | Default|
| --- | ----------- | ---- | ------ |
|pickerConfirmBtnText  |            |string  |confirm            |
|pickerCancelBtnText   |            |string  |cancel             |
|pickerTitleText       |            |string  |pls select         |
|pickerConfirmBtnColor |            |array   |[1, 186, 245, 1]   |
|pickerCancelBtnColor  |            |array   |[1, 186, 245, 1]   |
19
|pickerTitleColor      |            |array   |[20, 20, 20, 1]    |
xwenliang's avatar
xwenliang committed
20 21 22
|pickerToolBarBg       |            |array   |[232, 232, 232, 1] |
|pickerBg              |            |array   |[196, 199, 206, 1] |
|pickerToolBarFontSize |            |number  |16                 |
23
|wheelFlex             |            |array   |[1, 1, 1]          |
xwenliang's avatar
xwenliang committed
24 25 26
|pickerFontSize        |            |number  |16                 |
|pickerFontColor       |            |array   |[31, 31, 31, 1]    |
|pickerData            |            |array   |                   |
27
|selectedValue         |            |array   |                   |
xwenliang's avatar
xwenliang committed
28 29 30
|onPickerConfirm       |            |function|                   |
|onPickerCancel        |            |function|                   |
|onPickerSelect        |            |function|                   |
xwenliang's avatar
bugs  
xwenliang committed
31

zooble's avatar
zooble committed
32
#### Methods
xwenliang's avatar
xwenliang committed
33 34 35

|Name | Description | Type | Default|
| --- | ----------- | ---- | ------ |
jinlongtao's avatar
jinlongtao committed
36 37 38 39 40 41
|init         |init and pass parameters to picker      |     |   |
|toggle       |show or hide picker                     |     |   |
|show         |show picker                             |     |   |
|hide         |hide picker                             |     |   |
|select       |select a row                            |array|   |
|isPickerShow |get status of picker, return a boolean  |     |   |
xwenliang's avatar
xwenliang committed
42

xwenliang's avatar
xwenliang committed
43

zooble's avatar
zooble committed
44
### Usage
xwenliang's avatar
bugs  
xwenliang committed
45

zooble's avatar
zooble committed
46
#### Step 1 - install
xwenliang's avatar
bugs  
xwenliang committed
47 48 49 50 51

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

zooble's avatar
zooble committed
52
#### Step 2 - link
xwenliang's avatar
xwenliang committed
53 54 55 56 57

```
	react-native link
```

zooble's avatar
zooble committed
58
#### Step 3 - import and use in project
xwenliang's avatar
bugs  
xwenliang committed
59 60

```javascript
zooble's avatar
zooble committed
61 62
    import Picker from 'react-native-picker';
    let data = [];
xwenliang's avatar
xwenliang committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    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
81
	
xwenliang's avatar
xwenliang committed
82 83
```

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
### Integration With Existing Apps (`iOS`)
The `Podfile` will like below:
``` ruby
platform :ios, '8.0'
target 'YourTarget' do
    pod 'React', :path => '../YOUR_REACT_NATIVE_PROJECT/node_modules/react-native', :subspecs => [
    'Core',
    ...
    ]
    pod 'Picker', :path => '../YOUR_REACT_NATIVE_PROJECT/node_modules/react-native-picker'
end
```
After you have updated the `Podfile` of the existing app, you can install `react-native-picker` like below:
``` bash
$ pod install
```

zooble's avatar
zooble committed
101
### Notice
xwenliang's avatar
xwenliang committed
102

zooble's avatar
zooble committed
103
#### support two modes:
xwenliang's avatar
xwenliang committed
104

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

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

zooble's avatar
zooble committed
109
#### parallel:
xwenliang's avatar
xwenliang committed
110 111 112 113 114

- single wheel:

```javascript
	pickerData = [1,2,3,4];
xwenliang's avatar
xwenliang committed
115
	selectedValue = 3;
xwenliang's avatar
xwenliang committed
116 117 118 119 120 121 122 123 124 125 126 127 128
```

- two or more wheel:

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

zooble's avatar
zooble committed
129
#### cascade:
xwenliang's avatar
xwenliang committed
130 131 132 133

- two wheel

```javascript
xwenliang's avatar
xwenliang committed
134 135 136 137 138 139 140 141 142 143
    pickerData = [
        {
            a: [1, 2, 3, 4]
        },
        {
            b: [5, 6, 7, 8]
        },
        ...
    ];
    selectedValue = ['a', 2];
xwenliang's avatar
xwenliang committed
144 145 146 147 148
```

- three wheel

```javascript
xwenliang's avatar
xwenliang committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    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
189
        ...
xwenliang's avatar
xwenliang committed
190
    ]
xwenliang's avatar
xwenliang committed
191 192
```

zooble's avatar
zooble committed
193
### For pure javascript version -> [v3.0.5](https://github.com/beefe/react-native-picker/tree/pure-javascript-version)