README.md 4.96 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
|Key | Type | Default| Support | Description |
| --- | --- | ---- | ------ | ----------- |
|isLoop                | Boolean | false              |     Android  |   |
15
|pickerTextEllipsisLen | number  | 6                  |     Android  |   |
xwenliang's avatar
xwenliang committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|pickerConfirmBtnText  | string  | confirm            | iOS/Android  |   |
|pickerCancelBtnText   | string  | cancel             | iOS/Android  |   |
|pickerTitleText       | string  | pls select         | iOS/Android  |   |
|pickerConfirmBtnColor | array   | [1, 186, 245, 1]   | iOS/Android  |   |
|pickerCancelBtnColor  | array   | [1, 186, 245, 1]   | iOS/Android  |   |
|pickerTitleColor      | array   | [20, 20, 20, 1]    | iOS/Android  |   |
|pickerToolBarBg       | array   | [232, 232, 232, 1] | iOS/Android  |   |
|pickerBg              | array   | [196, 199, 206, 1] | iOS/Android  |   |
|pickerToolBarFontSize | number  | 16                 | iOS/Android  |   |
|wheelFlex             | array   | [1, 1, 1]          | iOS/Android  |   |
|pickerFontSize        | number  | 16                 | iOS/Android  |   |
|pickerFontColor       | array   | [31, 31, 31, 1]    | iOS/Android  |   |
|pickerRowHeight       | number  | 24                 | iOS          |   |
|pickerData            | array   |                    | iOS/Android  |   |
|selectedValue         | array   |                    | iOS/Android  |   |
|onPickerConfirm       | function|                    | iOS/Android  |   |
|onPickerCancel        | function|                    | iOS/Android  |   |
|onPickerSelect        | function|                    | iOS/Android  |   |
xwenliang's avatar
bugs  
xwenliang committed
34

zooble's avatar
zooble committed
35
#### Methods
xwenliang's avatar
xwenliang committed
36

xwenliang's avatar
xwenliang committed
37 38 39 40 41 42 43 44
|Key | Support | Description |
| --- | ---- | ----------- |
|init         | iOS/Android |init and pass parameters to picker      |
|toggle       | iOS/Android |show or hide picker                     |
|show         | iOS/Android |show picker                             |
|hide         | iOS/Android |hide picker                             |
|select       | iOS/Android |select a row                            |
|isPickerShow | iOS/Android |get status of picker, return a boolean  |
xwenliang's avatar
xwenliang committed
45

xwenliang's avatar
xwenliang committed
46

zooble's avatar
zooble committed
47
### Usage
xwenliang's avatar
bugs  
xwenliang committed
48

zooble's avatar
zooble committed
49
#### Step 1 - install
xwenliang's avatar
bugs  
xwenliang committed
50

xwenliang's avatar
xwenliang committed
51
```javascript
xwenliang's avatar
bugs  
xwenliang committed
52 53 54
	npm install react-native-picker --save
```

zooble's avatar
zooble committed
55
#### Step 2 - link
xwenliang's avatar
xwenliang committed
56 57 58 59 60

```
	react-native link
```

zooble's avatar
zooble committed
61
#### Step 3 - import and use in project
xwenliang's avatar
bugs  
xwenliang committed
62 63

```javascript
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
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);
xwenliang's avatar
xwenliang committed
81
    }
82 83
});
Picker.show();
xwenliang's avatar
bugs  
xwenliang committed
84
	
xwenliang's avatar
xwenliang committed
85 86
```

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
### 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
104
### Notice
xwenliang's avatar
xwenliang committed
105

zooble's avatar
zooble committed
106
#### support two modes:
xwenliang's avatar
xwenliang committed
107

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

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

zooble's avatar
zooble committed
112
#### parallel:
xwenliang's avatar
xwenliang committed
113 114 115 116

- single wheel:

```javascript
117 118
pickerData = [1,2,3,4];
selectedValue = 3;
xwenliang's avatar
xwenliang committed
119 120 121 122 123
```

- two or more wheel:

```javascript
124 125 126 127 128 129
pickerData = [
    [1,2,3,4],
    [5,6,7,8],
    ...
];
selectedValue = [1, 5];
xwenliang's avatar
xwenliang committed
130 131
```

zooble's avatar
zooble committed
132
#### cascade:
xwenliang's avatar
xwenliang committed
133 134 135 136

- two wheel

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

- three wheel

```javascript
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 189 190 191 192 193
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
194 195
```

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