@@ -11,14 +11,17 @@ import {
11
11
Avatar ,
12
12
Assets ,
13
13
PanningProvider ,
14
- Typography
14
+ Typography ,
15
+ PickerProps ,
16
+ DialogProps
15
17
} from 'react-native-ui-lib' ; //eslint-disable-line
16
18
import contactsData from '../../data/conversations' ;
17
- import tagIcon from '../../assets/icons/tags.png' ;
18
- import dropdown from '../../assets/icons/chevronDown.png' ;
19
19
import { longOptions } from './PickerScreenLongOptions' ;
20
20
21
- const contacts = _ . map ( contactsData , c => ( { ...c , value : c . name , label : c . name } ) ) ;
21
+ const tagIcon = require ( '../../assets/icons/tags.png' ) ;
22
+ const dropdown = require ( '../../assets/icons/chevronDown.png' ) ;
23
+
24
+ const contacts = _ . map ( contactsData , ( c , index ) => ( { ...c , value : index , label : c . name } ) ) ;
22
25
23
26
const options = [
24
27
{ label : 'JavaScript' , value : 'js' } ,
@@ -35,26 +38,19 @@ const filters = [
35
38
] ;
36
39
37
40
export default class PickerScreen extends Component {
38
- constructor ( props ) {
39
- super ( props ) ;
40
-
41
- this . state = {
42
- itemsCount : 1 ,
43
- // language: {value: 'java', label: 'Java'},
44
- language : undefined ,
45
- language2 : options [ 2 ] . value , // for migrated picker example
46
- languages : [ ] ,
47
- nativePickerValue : 'java' ,
48
- customModalValues : [ ] ,
49
- filter : filters [ 0 ] ,
50
- contact : contacts [ 0 ] ,
51
- tags : [ { label : 'Amit' } , { label : 'Ethan' } ] ,
52
- tags2 : [ 'Tags' , 'Input' ] ,
53
- tags3 : [ 'Non' , 'Removable' , 'Tags' ]
54
- } ;
55
- }
41
+ state = {
42
+ itemsCount : 1 ,
43
+ // language: {value: 'java', label: 'Java'},
44
+ language : undefined ,
45
+ language2 : options [ 2 ] . value , // for migrated picker example
46
+ languages : [ ] ,
47
+ nativePickerValue : 'java' ,
48
+ customModalValues : [ ] ,
49
+ filter : filters [ 0 ] ,
50
+ contact : 0
51
+ } ;
56
52
57
- dialogHeader = props => {
53
+ dialogHeader : DialogProps [ 'renderPannableHeader' ] = props => {
58
54
const { title} = props ;
59
55
return (
60
56
< Text margin-15 text60 >
@@ -63,7 +59,7 @@ export default class PickerScreen extends Component {
63
59
) ;
64
60
} ;
65
61
66
- renderDialog = modalProps => {
62
+ renderDialog : PickerProps [ 'renderCustomModal' ] = modalProps => {
67
63
const { visible, children, toggleModal, onDone} = modalProps ;
68
64
69
65
return (
@@ -99,19 +95,18 @@ export default class PickerScreen extends Component {
99
95
enableModalBlur = { false }
100
96
onChange = { item => this . setState ( { language : item } ) }
101
97
topBarProps = { { title : 'Languages' } }
102
- style = { { color : Colors . red20 } }
98
+ // style={{color: Colors.red20}}
103
99
showSearch
104
100
searchPlaceholder = { 'Search a language' }
105
101
searchStyle = { { color : Colors . blue30 , placeholderTextColor : Colors . grey50 } }
106
102
// onSearchChange={value => console.warn('value', value)}
107
103
>
108
104
{ _ . map ( longOptions , option => (
109
- < Picker . Item key = { option . value } value = { option } disabled = { option . disabled } />
105
+ < Picker . Item key = { option . value } value = { option } label = { '' } disabled = { option . disabled } />
110
106
) ) }
111
107
</ Picker >
112
108
113
109
< Picker
114
- marginT-20
115
110
placeholder = "Favorite Languages (up to 3)"
116
111
value = { this . state . languages }
117
112
onChange = { items => this . setState ( { languages : items } ) }
@@ -120,7 +115,7 @@ export default class PickerScreen extends Component {
120
115
rightIconSource = { dropdown }
121
116
>
122
117
{ _ . map ( options , option => (
123
- < Picker . Item key = { option . value } value = { option } disabled = { option . disabled } />
118
+ < Picker . Item key = { option . value } value = { option } label = { '' } disabled = { option . disabled } />
124
119
) ) }
125
120
</ Picker >
126
121
@@ -131,7 +126,7 @@ export default class PickerScreen extends Component {
131
126
value = { this . state . nativePickerValue }
132
127
onChange = { nativePickerValue => this . setState ( { nativePickerValue} ) }
133
128
rightIconSource = { dropdown }
134
- containerStyle = { { marginTop : 20 } }
129
+ // containerStyle={{marginTop: 20}}
135
130
// renderPicker={() => {
136
131
// return (
137
132
// <View>
@@ -154,7 +149,6 @@ export default class PickerScreen extends Component {
154
149
</ Picker >
155
150
156
151
< Picker
157
- marginT-20
158
152
title = "Custom modal"
159
153
placeholder = "Pick multiple Languages"
160
154
value = { this . state . customModalValues }
@@ -174,13 +168,13 @@ export default class PickerScreen extends Component {
174
168
) ) }
175
169
</ Picker >
176
170
177
- < Text marginT-20 marginB-10 text70 grey60 >
171
+ < Text marginB-10 text70 >
178
172
Custom Picker:
179
173
</ Text >
180
174
< Picker
181
175
value = { this . state . filter }
182
176
onChange = { filter => this . setState ( { filter} ) }
183
- renderPicker = { ( { label} ) => {
177
+ renderPicker = { ( _value ?: any , label ?: string ) => {
184
178
return (
185
179
< View row >
186
180
< Icon style = { { marginRight : 1 , height : 16 , resizeMode : 'contain' } } source = { tagIcon } />
@@ -192,62 +186,78 @@ export default class PickerScreen extends Component {
192
186
} }
193
187
>
194
188
{ _ . map ( filters , filter => (
195
- < Picker . Item key = { filter . value } value = { filter } />
189
+ < Picker . Item key = { filter . value } value = { filter } label = { '' } />
196
190
) ) }
197
191
</ Picker >
198
192
199
- < Text marginT-20 marginB-10 text70 grey60 >
193
+ < Text text60 marginT-s5 >
194
+ Migrated Pickers
195
+ </ Text >
196
+
197
+ < Text marginT-20 marginB-10 text70 >
200
198
Custom Picker Items:
201
199
</ Text >
202
200
< Picker
201
+ migrate
203
202
value = { this . state . contact }
204
- onChange = { contact => this . setState ( { contact} ) }
205
- getItemValue = { contact => contact . name }
206
- renderPicker = { contact => {
203
+ onChange = { contact => {
204
+ this . setState ( { contact} ) ;
205
+ } }
206
+ // getItemValue={contact => contact?.value}
207
+ renderPicker = { ( contactValue ?: number ) => {
208
+ const contact = contacts [ contactValue ! ] ?? undefined ;
207
209
return (
208
210
< View row >
209
- < Avatar size = { 30 } source = { { uri : contact . thumbnail } } />
210
- < Text text70 marginL-10 >
211
- { contact . name }
212
- </ Text >
211
+ { contact ? (
212
+ < >
213
+ < Avatar size = { 30 } source = { { uri : contact ?. thumbnail } } />
214
+ < Text text70 marginL-10 >
215
+ { contact ?. name }
216
+ </ Text >
217
+ </ >
218
+ ) : (
219
+ < Text text70 grey30 >
220
+ Pick a contact
221
+ </ Text >
222
+ ) }
213
223
</ View >
214
224
) ;
215
225
} }
216
226
>
217
227
{ _ . map ( contacts , contact => (
218
228
< Picker . Item
219
229
key = { contact . name }
220
- value = { contact }
221
- renderItem = { ( item , props ) => (
222
- < View
223
- style = { {
224
- height : 56 ,
225
- borderBottomWidth : 1 ,
226
- borderColor : Colors . grey80
227
- } }
228
- paddingH-15
229
- row
230
- centerV
231
- spread
232
- >
233
- < View row centerV >
234
- < Avatar size = { 35 } source = { { uri : item . thumbnail } } />
235
- < Text marginL-10 text70 grey10 >
236
- { item . name }
237
- </ Text >
230
+ value = { contact . value }
231
+ label = { contact . label }
232
+ renderItem = { ( contactValue , props ) => {
233
+ const contact = contacts [ contactValue as number ] ;
234
+ return (
235
+ < View
236
+ style = { {
237
+ height : 56 ,
238
+ borderBottomWidth : 1 ,
239
+ borderColor : Colors . grey80
240
+ } }
241
+ paddingH-15
242
+ row
243
+ centerV
244
+ spread
245
+ >
246
+ < View row centerV >
247
+ < Avatar size = { 35 } source = { { uri : contact ?. thumbnail } } />
248
+ < Text marginL-10 text70 grey10 >
249
+ { contact ?. name }
250
+ </ Text >
251
+ </ View >
252
+ { props . isSelected && < Icon source = { Assets . icons . check } /> }
238
253
</ View >
239
- { props . isSelected && < Icon source = { Assets . icons . check } /> }
240
- </ View >
241
- ) }
242
- getItemLabel = { item => item . name }
254
+ ) ;
255
+ } }
256
+ getItemLabel = { contactValue => contacts [ contactValue as number ] ?. name }
243
257
/>
244
258
) ) }
245
259
</ Picker >
246
260
247
- < Text text60 marginT-s5 marginB-s2 >
248
- Migrated Picker
249
- </ Text >
250
-
251
261
< Picker
252
262
migrate
253
263
migrateTextField
@@ -259,6 +269,7 @@ export default class PickerScreen extends Component {
259
269
showSearch
260
270
searchPlaceholder = { 'Search a language' }
261
271
searchStyle = { { color : Colors . blue30 , placeholderTextColor : Colors . grey50 } }
272
+ marginT-s4
262
273
// mode={Picker.modes.MULTI}
263
274
// useNativePicker
264
275
>
0 commit comments