Skip to content

Commit e29285e

Browse files
authored
v7_Picker (#2478)
* Migrate picker component * Remove commented code
1 parent 7eb9e2b commit e29285e

File tree

11 files changed

+61
-97
lines changed

11 files changed

+61
-97
lines changed

demo/src/screens/componentScreens/PickerScreen.tsx

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ export default class PickerScreen extends Component {
5151
itemsCount: 1,
5252
// language: {value: 'java', label: 'Java'},
5353
language: undefined,
54-
language2: options[2].value, // for migrated picker example
54+
language2: options[2].value,
5555
languages: [],
5656
nativePickerValue: 'java',
5757
customModalValues: [],
58-
filter: filters[0],
58+
filter: filters[0].value,
5959
scheme: schemes[0].value,
6060
contact: 0
6161
};
@@ -102,10 +102,9 @@ export default class PickerScreen extends Component {
102102
searchPlaceholder={'Search a language'}
103103
searchStyle={{color: Colors.blue30, placeholderTextColor: Colors.grey50}}
104104
// onSearchChange={value => console.warn('value', value)}
105-
migrateTextField
106105
>
107106
{_.map(longOptions, option => (
108-
<Picker.Item key={option.value} value={option} label={''} disabled={option.disabled}/>
107+
<Picker.Item key={option.value} value={option.value} label={option.label} disabled={option.disabled}/>
109108
))}
110109
</Picker>
111110

@@ -116,21 +115,20 @@ export default class PickerScreen extends Component {
116115
mode={Picker.modes.MULTI}
117116
selectionLimit={3}
118117
trailingAccessory={dropdownIcon}
119-
migrateTextField
120118
>
121119
{_.map(options, option => (
122-
<Picker.Item key={option.value} value={option} label={''} disabled={option.disabled}/>
120+
<Picker.Item key={option.value} value={option.value} label={option.label} disabled={option.disabled}/>
123121
))}
124122
</Picker>
125123

126124
<Picker
127-
title="Wheel Picker"
125+
label="Wheel Picker"
128126
placeholder="Pick a Language"
129-
useNativePicker
127+
useWheelPicker
130128
// useWheelPicker
131129
value={this.state.nativePickerValue}
132130
onChange={nativePickerValue => this.setState({nativePickerValue})}
133-
rightIconSource={dropdown}
131+
trailingAccessory={<Icon source={dropdown}/>}
134132
// containerStyle={{marginTop: 20}}
135133
// renderPicker={() => {
136134
// return (
@@ -139,13 +137,6 @@ export default class PickerScreen extends Component {
139137
// </View>
140138
// );
141139
// }}
142-
// renderNativePicker={props => {
143-
// return (
144-
// <View flex bg-red50>
145-
// <Text>CUSTOM NATIVE PICKER</Text>
146-
// </View>
147-
// );
148-
// }}
149140
// topBarProps={{doneLabel: 'YES', cancelLabel: 'NO'}}
150141
>
151142
{_.map(options, option => (
@@ -160,13 +151,12 @@ export default class PickerScreen extends Component {
160151
onChange={items => this.setState({customModalValues: items})}
161152
mode={Picker.modes.MULTI}
162153
trailingAccessory={dropdownIcon}
163-
migrateTextField
164154
renderCustomModal={this.renderDialog}
165155
>
166156
{_.map(options, option => (
167157
<Picker.Item
168158
key={option.value}
169-
value={option}
159+
value={option.value}
170160
label={option.label}
171161
labelStyle={Typography.text65}
172162
disabled={option.disabled}
@@ -196,19 +186,15 @@ export default class PickerScreen extends Component {
196186
}}
197187
>
198188
{_.map(filters, filter => (
199-
<Picker.Item key={filter.value} value={filter} label={''}/>
189+
<Picker.Item key={filter.value} value={filter.value} label={filter.label}/>
200190
))}
201191
</Picker>
202192

203-
<Text text60 marginT-s5 $textDefault>
204-
Migrated Pickers
205-
</Text>
206-
207193
<Text marginT-20 marginB-10 text70 $textDefault>
208194
Custom Picker Items:
209195
</Text>
210196
<Picker
211-
migrate
197+
ref={this.picker}
212198
value={this.state.contact}
213199
onChange={contact => {
214200
this.setState({contact});
@@ -268,27 +254,6 @@ export default class PickerScreen extends Component {
268254
))}
269255
</Picker>
270256

271-
<Picker
272-
migrate
273-
ref={this.picker}
274-
migrateTextField
275-
label="Language"
276-
placeholder="Favorite Language"
277-
value={this.state.language2}
278-
onChange={value => this.setState({language2: value})}
279-
topBarProps={{title: 'Languages'}}
280-
showSearch
281-
searchPlaceholder={'Search a language'}
282-
searchStyle={{color: Colors.blue30, placeholderTextColor: Colors.grey50}}
283-
marginT-s4
284-
enableErrors={false}
285-
// mode={Picker.modes.MULTI}
286-
// useNativePicker
287-
>
288-
{_.map(options, option => (
289-
<Picker.Item key={option.value} value={option.value} label={option.label} disabled={option.disabled}/>
290-
))}
291-
</Picker>
292257
<Button
293258
label="Open Picker Manually"
294259
link
@@ -299,11 +264,11 @@ export default class PickerScreen extends Component {
299264
<Text text60 marginT-s5>
300265
Different Field Types
301266
</Text>
302-
<Text text80 marginB-s5>(Form/Filter/Settings)</Text>
267+
<Text text80 marginB-s5>
268+
(Form/Filter/Settings)
269+
</Text>
303270

304271
<Picker
305-
migrate
306-
migrateTextField
307272
value={this.state.filter}
308273
onChange={value => this.setState({filter: value})}
309274
placeholder="Filter posts"
@@ -316,8 +281,6 @@ export default class PickerScreen extends Component {
316281
</Picker>
317282

318283
<Picker
319-
migrate
320-
migrateTextField
321284
value={this.state.scheme}
322285
onChange={value => this.setState({scheme: value})}
323286
label="Color Scheme"

src/components/picker/NativePicker.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO: Remove this sub component
12
import _ from 'lodash';
23
import React, {Component} from 'react';
34
import TextField from '../textField';
@@ -64,10 +65,10 @@ class NativePicker extends Component {
6465

6566
renderPicker = () => {
6667
const {selectedValue} = this.state;
67-
const {children, renderNativePicker, pickerStyle, wheelPickerProps, testID} = this.props;
68-
if (_.isFunction(renderNativePicker)) {
69-
return renderNativePicker(this.props);
70-
}
68+
const {children, /* renderNativePicker, */ pickerStyle, wheelPickerProps, testID} = this.props;
69+
// if (_.isFunction(renderNativePicker)) {
70+
// return renderNativePicker(this.props);
71+
// }
7172
return (
7273
<WheelPicker
7374
style={pickerStyle}

src/components/picker/PickerItem.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const PickerItem = (props: PickerItemProps) => {
3030
const context = useContext(PickerContext);
3131
const {migrate} = context;
3232
const customRenderItem = context.renderItem || props.renderItem;
33+
// @ts-expect-error TODO: fix after removing migrate prop completely
3334
const itemValue = !migrate && typeof value === 'object' ? value?.value : value;
3435
const isSelected = isItemSelected(itemValue, context.value);
3536
const itemLabel = getItemLabel(label, value, props.getItemLabel || context.getItemLabel);
@@ -64,6 +65,7 @@ const PickerItem = (props: PickerItemProps) => {
6465
if (migrate) {
6566
context.onPress(value);
6667
} else {
68+
// @ts-expect-error TODO: fix after removing migrate prop completely
6769
context.onPress(typeof value === 'object' || context.isMultiMode ? value : ({value, label: itemLabel}) as PickerSingleValue);
6870
}
6971
}, [migrate, value, context.onPress]);

src/components/picker/PickerItemsList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ const PickerItemsList = (props: PickerItemsListProps) => {
8282
return (
8383
<View>
8484
<View row spread padding-page>
85-
<Text>{topBarProps.title}</Text>
85+
<Text>{topBarProps?.title}</Text>
8686
<Text text70 $textPrimary accessibilityRole={'button'} onPress={() => context.onPress(wheelPickerValue)}>
87-
{topBarProps.doneLabel ?? 'Select'}
87+
{topBarProps?.doneLabel ?? 'Select'}
8888
</Text>
8989
</View>
9090
<WheelPicker

src/components/picker/PickerPresenter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function isItemSelected(childValue: PickerSingleValue, selectedValue?: Pi
1818

1919
if (Array.isArray(selectedValue)) {
2020
isSelected = !!_.find(selectedValue, v => {
21+
// @ts-expect-error TODO: fix after removing migrate prop completely
2122
return v === childValue || (typeof v === 'object' && v?.value === childValue);
2223
});
2324
} else {

src/components/picker/__tests__/index.spec.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ const testID = 'picker';
1414
describe('Picker', () => {
1515
describe('getLabel', () => {
1616
it('should get label of a simple item', async () => {
17-
const driver = new PickerDriver({component: <TestCase value={countries[2]}/>, testID});
17+
const driver = new PickerDriver({component: <TestCase value={countries[2].value}/>, testID});
1818

1919
expect(await driver.getByDisplayValue(countries[2].label)).toBeDefined();
2020
expect(await driver.getByDisplayValue(countries[3].label)).not.toBeDefined();
2121
});
2222

2323
it('should get label out of an array of items', async () => {
24-
const driver = new PickerDriver({component: <TestCase value={[countries[2], countries[4]]}/>, testID});
24+
const driver = new PickerDriver({
25+
component: <TestCase value={[countries[2].value, countries[4].value]}/>,
26+
testID
27+
});
2528

2629
expect(await driver.getByDisplayValue(`${countries[2].label}, ${countries[4].label}`)).toBeDefined();
2730
});

src/components/picker/api/picker.api.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,11 @@
8181
"type": "(props) => void",
8282
"description": "Render custom search input (only when passing showSearch)"
8383
},
84-
{
85-
"name": "useNativePicker",
86-
"type": "boolean",
87-
"description": "Allow to use the native picker solution (different style for iOS and Android)"
88-
},
8984
{
9085
"name": "useWheelPicker",
9186
"type": "boolean",
9287
"description": "Use wheel picker instead of a list picker"
9388
},
94-
{
95-
"name": "renderNativePicker",
96-
"type": "(props) => void",
97-
"description": "Callback for rendering a custom native picker inside the dialog (relevant to native picker only)"
98-
},
9989
{
10090
"name": "listProps",
10191
"type": "FlatListProps",

src/components/picker/helpers/usePickerLabel.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ const usePickerLabel = (props: UsePickerLabelProps) => {
3131
return getLabelsFromArray(value);
3232
}
3333

34-
if (typeof value === 'object') {
35-
return value?.label;
36-
}
34+
// TODO: Remove
35+
// if (typeof value === 'object') {
36+
// return value?.label;
37+
// }
3738

3839
// otherwise, extract from picker items
3940
const selectedItem = _.find(items, {value});

src/components/picker/helpers/usePickerMigrationWarnings.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import _ from 'lodash';
33
import {LogService} from '../../../services';
44
import {PickerProps, PickerModes} from '../types';
55

6+
// @ts-expect-error TODO: Remove this whole file when migration is completed
67
type UsePickerMigrationWarnings = Pick<PickerProps, 'value' | 'mode' | 'useNativePicker'>;
78

89
const usePickerMigrationWarnings = (props: UsePickerMigrationWarnings) => {

src/components/picker/index.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@ import TextFieldMigrator from '../textField/TextFieldMigrator';
1717
import Icon from '../icon';
1818
import View from '../view';
1919
import Text from '../text';
20-
// @ts-expect-error
21-
import NativePicker from './NativePicker';
20+
// import NativePicker from './NativePicker';
2221
import PickerItemsList from './PickerItemsList';
2322
import PickerItem from './PickerItem';
2423
import PickerContext from './PickerContext';
2524
import usePickerSelection from './helpers/usePickerSelection';
2625
import usePickerLabel from './helpers/usePickerLabel';
2726
import usePickerSearch from './helpers/usePickerSearch';
2827
import useImperativePickerHandle from './helpers/useImperativePickerHandle';
29-
import usePickerMigrationWarnings from './helpers/usePickerMigrationWarnings';
28+
// import usePickerMigrationWarnings from './helpers/usePickerMigrationWarnings';
3029
import {extractPickerItems} from './PickerPresenter';
3130
import {
3231
PickerProps,
@@ -63,7 +62,7 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
6362
searchStyle,
6463
searchPlaceholder,
6564
renderCustomSearch,
66-
useNativePicker,
65+
// useNativePicker,
6766
useWheelPicker,
6867
renderPicker,
6968
customPickerProps,
@@ -86,8 +85,9 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
8685
renderItem,
8786
children,
8887
useSafeArea,
89-
migrate,
90-
migrateTextField,
88+
// TODO: Remove migrate props and migrate code
89+
migrate = true,
90+
migrateTextField = true,
9191
accessibilityLabel,
9292
accessibilityHint,
9393
...others
@@ -99,7 +99,8 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
9999

100100
const pickerExpandable = useRef<ExpandableOverlayMethods>(null);
101101

102-
usePickerMigrationWarnings({value, mode});
102+
// TODO: Remove
103+
// usePickerMigrationWarnings({value, mode});
103104

104105
const pickerRef = useImperativePickerHandle(ref, pickerExpandable);
105106
const {
@@ -134,6 +135,7 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
134135
}, []);
135136

136137
const contextValue = useMemo(() => {
138+
// @ts-expect-error cleanup after removing migrate prop
137139
const pickerValue = !migrate && typeof value === 'object' && !_.isArray(value) ? value?.value : value;
138140
return {
139141
migrate,
@@ -264,9 +266,9 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
264266
}
265267
};
266268

267-
if (useNativePicker) {
268-
return <NativePicker {...themeProps}/>;
269-
}
269+
// if (useNativePicker) {
270+
// return <NativePicker {...themeProps}/>;
271+
// }
270272

271273
return (
272274
<PickerContext.Provider value={contextValue}>

0 commit comments

Comments
 (0)