@@ -77,9 +77,13 @@ class Picker extends BaseComponent {
77
77
*/
78
78
onPress : PropTypes . func ,
79
79
/**
80
- * A function that extract the unique value out of the value prop in case value has a custom structure
80
+ * A function that extract the unique value out of the value prop in case value has a custom structure (e.g. {myValue, myLabel})
81
81
*/
82
82
getItemValue : PropTypes . func ,
83
+ /**
84
+ * A function that extract the label out of the value prop in case value has a custom structure (e.g. {myValue, myLabel})
85
+ */
86
+ getItemLabel : PropTypes . func ,
83
87
/**
84
88
* A function that returns the label to show for the selected Picker value
85
89
*/
@@ -181,15 +185,15 @@ class Picker extends BaseComponent {
181
185
182
186
getLabel ( ) {
183
187
const { value} = this . state ;
188
+ const { getLabel, getItemLabel} = this . props ;
184
189
185
190
if ( _ . isArray ( value ) ) {
186
191
return _ . chain ( value )
187
- . map ( 'label' )
192
+ . map ( getItemLabel || 'label' )
188
193
. join ( ', ' )
189
194
. value ( ) ;
190
195
}
191
196
192
- const { getLabel} = this . props ;
193
197
if ( _ . isFunction ( getLabel ) ) {
194
198
return getLabel ( value ) ;
195
199
}
@@ -214,8 +218,9 @@ class Picker extends BaseComponent {
214
218
} ;
215
219
216
220
toggleItemSelection = item => {
221
+ const { getItemValue} = this . props ;
217
222
const { value} = this . state ;
218
- const newValue = _ . xorBy ( value , [ item ] , 'value' ) ;
223
+ const newValue = _ . xorBy ( value , [ item ] , getItemValue || 'value' ) ;
219
224
this . setState ( {
220
225
value : newValue
221
226
} ) ;
@@ -251,7 +256,7 @@ class Picker extends BaseComponent {
251
256
} ;
252
257
253
258
appendPropsToChildren = ( ) => {
254
- const { children, mode, getItemValue, showSearch, renderItem} = this . props ;
259
+ const { children, mode, getItemValue, getItemLabel , showSearch, renderItem} = this . props ;
255
260
const { value, searchValue} = this . state ;
256
261
const childrenWithProps = React . Children . map ( children , child => {
257
262
const childValue = PickerPresenter . getItemValue ( { getItemValue, ...child . props } ) ;
@@ -264,6 +269,7 @@ class Picker extends BaseComponent {
264
269
isSelected,
265
270
onPress : mode === Picker . modes . MULTI ? this . toggleItemSelection : this . onDoneSelecting ,
266
271
getItemValue : child . props . getItemValue || getItemValue ,
272
+ getItemLabel : child . props . getItemLabel || getItemLabel ,
267
273
onSelectedLayout : this . onSelectedItemLayout ,
268
274
renderItem : child . props . renderItem || renderItem ,
269
275
accessibilityState : isSelected ? { selected : true } : undefined ,
0 commit comments