Skip to content

Commit 3dc160d

Browse files
authored
Add appropriate deprecate warnings for picker API (#986)
* Add appropriate deprecate warnings for picker API * Remove redundant TODO comments
1 parent cff347a commit 3dc160d

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

demo/src/screens/componentScreens/PickerScreen.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
import _ from 'lodash';
22
import React, {Component} from 'react';
33
import {ScrollView, Image} from 'react-native';
4-
import {
5-
View,
6-
Colors,
7-
Dialog,
8-
Text,
9-
Picker,
10-
Avatar,
11-
Assets,
12-
PanningProvider
13-
} from 'react-native-ui-lib'; //eslint-disable-line
4+
import {View, Colors, Dialog, Text, Picker, Avatar, Assets, PanningProvider} from 'react-native-ui-lib'; //eslint-disable-line
145
import contacts from '../../data/conversations';
156
import tagIcon from '../../assets/icons/tags.png';
167
import dropdown from '../../assets/icons/chevronDown.png';
@@ -37,6 +28,7 @@ export default class PickerScreen extends Component {
3728
itemsCount: 1,
3829
// language: {value: 'java', label: 'Java'},
3930
language: undefined,
31+
language2: undefined, // for migrated picker example
4032
languages: [],
4133
nativePickerValue: 'java',
4234
customModalValues: [],
@@ -239,6 +231,24 @@ export default class PickerScreen extends Component {
239231
/>
240232
))}
241233
</Picker>
234+
235+
<Text text60 marginT-s5 marginB-s2>Migrated Picker</Text>
236+
237+
<Picker
238+
title="Language"
239+
placeholder="Favorite Language"
240+
value={this.state.language2}
241+
onChange={value => this.setState({language2: value})}
242+
topBarProps={{title: 'Languages'}}
243+
showSearch
244+
searchPlaceholder={'Search a language'}
245+
searchStyle={{color: Colors.blue30, placeholderTextColor: Colors.dark50}}
246+
// useNativePicker
247+
>
248+
{_.map(options, option => (
249+
<Picker.Item key={option.value} value={option.value} label={option.label} disabled={option.disabled} />
250+
))}
251+
</Picker>
242252
</View>
243253
</ScrollView>
244254
);

src/components/picker/PickerItem.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// TODO: deprecate passing an an object as a value, use label and value props separately
21
import _ from 'lodash';
32
import PropTypes from 'prop-types';
43
import React from 'react';
@@ -11,7 +10,6 @@ import TouchableOpacity from '../touchableOpacity';
1110
import Image from '../image';
1211
import Text from '../text';
1312

14-
1513
/**
1614
* @description: Picker.Item, for configuring the Picker's selectable options
1715
* @extends: TouchableOpacity
@@ -23,20 +21,19 @@ class PickerItem extends BaseComponent {
2321

2422
static propTypes = {
2523
/**
26-
* [DEPRECATED - please include the label in the value prop] The item label
24+
* Item's value
2725
*/
28-
label: PropTypes.string,
26+
value: PropTypes.oneOfType([PropTypes.object, PropTypes.string, PropTypes.number]),
2927
/**
30-
* The item value with the following format - {value: ..., label: ...},
31-
* for custom shape use getItemLabel, getItemValue props
28+
* Item's label
3229
*/
33-
value: PropTypes.oneOfType([PropTypes.object, PropTypes.string, PropTypes.number]),
30+
label: PropTypes.string,
3431
/**
35-
* Function to return the label out of the item value prop when value is custom shaped.
32+
* Custom function for the item label (e.g (value) => customLabel)
3633
*/
3734
getItemLabel: PropTypes.func,
3835
/**
39-
* Function to return the value out of the item value prop when value is custom shaped.
36+
* DEPRECATE: Function to return the value out of the item value prop when value is custom shaped.
4037
*/
4138
getItemValue: PropTypes.func,
4239
/**
@@ -69,19 +66,15 @@ class PickerItem extends BaseComponent {
6966
onSelectedLayout: PropTypes.func
7067
};
7168

72-
/* eslint-disable */
73-
/* constructor(props) {
69+
70+
constructor(props) {
7471
super(props);
7572

76-
if (props.label) {
77-
console.warn('PickerItem \'label\' prop will be deprecated soon. please include label in \'value\' prop. (refer docs)'); //eslint-disable-line
78-
}
79-
80-
if (!_.isObject(props.value)) {
81-
console.warn('PickerItem \'value\' prop type has changed to object, please use it with the following format: {value: ..., label: ...} or use getItemValue & getItemLabel props'); //eslint-disable-line
73+
if (_.isPlainObject(props.value)) {
74+
console.warn('UILib Picker.Item will stop supporting passing object as value & label (e.g {value, label}) in the next major version. Please pass separate label and value props');
8275
}
83-
} */
84-
/* eslint-enable */
76+
}
77+
8578

8679
generateStyles() {
8780
this.styles = createStyles(this.props);

src/components/picker/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// TODO: deprecate value allowing passing an object, separate between label and value props
2-
// TODO: extract picker labels from children in order to obtain the correct label to render (similar to NativePicker)
3-
41
import _ from 'lodash';
52
import PropTypes from 'prop-types';
63
import React, {PureComponent} from 'react';
@@ -160,6 +157,9 @@ class Picker extends PureComponent {
160157
// if (props.useNativePicker && _.isPlainObject(props.value)) {
161158
// console.warn('UILib Picker: don\'t use object as value for native picker, use either string or a number');
162159
// }
160+
if (_.isPlainObject(props.value)) {
161+
console.warn('UILib Picker will stop supporting passing object as value in the next major version. Please use either string or a number as value');
162+
}
163163
}
164164

165165
static getDerivedStateFromProps(nextProps, prevState) {

0 commit comments

Comments
 (0)