Skip to content

Commit 4947072

Browse files
authored
Picker screens aligned to the new props migration (#3080)
* Picker screens aligned to the new props migration * refcator web demo picker examples
1 parent 4870678 commit 4947072

File tree

4 files changed

+71
-135
lines changed

4 files changed

+71
-135
lines changed

demo/src/screens/SettingsScreen.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,8 @@ class SettingsScreen extends Component {
8080
value={defaultScreen?.value}
8181
label={'Default Screen'}
8282
onChange={this.setDefaultScreen}
83-
>
84-
{_.map(filteredScreens, screen => (
85-
<Picker.Item key={screen.value} value={screen.value} label={screen.label}/>
86-
))}
87-
</Picker>
83+
items={filteredScreens}
84+
/>
8885

8986
<View style={{borderWidth: 1, borderColor: Colors.grey70, marginTop: 40}}>
9087
<View style={[{padding: 5, borderBottomWidth: 1}, styles.block]}>

demo/src/screens/componentScreens/PickerScreen.tsx

Lines changed: 47 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,39 @@ const tagIcon = require('../../assets/icons/tags.png');
2424
const dropdown = require('../../assets/icons/chevronDown.png');
2525
const dropdownIcon = <Icon source={dropdown} tintColor={Colors.$iconDefault}/>;
2626

27-
const contacts = _.map(contactsData, (c, index) => ({...c, value: index, label: c.name}));
27+
const renderContact = (contactValue: any, props: any) => {
28+
const contact = contacts[contactValue as number];
29+
return (
30+
<View
31+
style={{
32+
height: 56,
33+
borderBottomWidth: 1,
34+
borderColor: Colors.$backgroundNeutral
35+
}}
36+
paddingH-15
37+
row
38+
centerV
39+
spread
40+
>
41+
<View row centerV>
42+
<Avatar size={35} source={{uri: contact?.thumbnail}}/>
43+
<Text marginL-10 text70 $textDefault>
44+
{contact?.name}
45+
</Text>
46+
</View>
47+
{props.isSelected && <Icon source={Assets.icons.check} tintColor={Colors.$iconDefault}/>}
48+
</View>
49+
);
50+
};
51+
52+
const contacts = _.map(contactsData, (c, index) => ({...c, value: index, label: c.name, renderItem: renderContact}));
2853

2954
const options = [
30-
{label: 'JavaScript', value: 'js'},
31-
{label: 'Java', value: 'java'},
32-
{label: 'Python', value: 'python'},
33-
{label: 'C++', value: 'c++', disabled: true},
34-
{label: 'Perl', value: 'perl'}
55+
{label: 'JavaScript', value: 'js', labelStyle: Typography.text65},
56+
{label: 'Java', value: 'java', labelStyle: Typography.text65},
57+
{label: 'Python', value: 'python', labelStyle: Typography.text65},
58+
{label: 'C++', value: 'c++', disabled: true, labelStyle: Typography.text65},
59+
{label: 'Perl', value: 'perl', labelStyle: Typography.text65}
3560
];
3661

3762
const filters = [
@@ -76,7 +101,6 @@ export default class PickerScreen extends Component {
76101

77102
renderDialog: PickerProps['renderCustomModal'] = (modalProps: RenderCustomModalProps) => {
78103
const {visible, children, toggleModal, onDone} = modalProps;
79-
80104
return (
81105
<Incubator.Dialog
82106
visible={visible}
@@ -116,11 +140,8 @@ export default class PickerScreen extends Component {
116140
searchPlaceholder={'Search a language'}
117141
searchStyle={{color: Colors.blue30, placeholderTextColor: Colors.grey50}}
118142
// onSearchChange={value => console.warn('value', value)}
119-
>
120-
{_.map(longOptions, option => (
121-
<Picker.Item key={option.value} value={option.value} label={option.label} disabled={option.disabled}/>
122-
))}
123-
</Picker>
143+
items={longOptions}
144+
/>
124145

125146
<Picker
126147
placeholder="Favorite Languages (up to 3)"
@@ -129,11 +150,8 @@ export default class PickerScreen extends Component {
129150
mode={Picker.modes.MULTI}
130151
selectionLimit={3}
131152
trailingAccessory={dropdownIcon}
132-
>
133-
{_.map(options, option => (
134-
<Picker.Item key={option.value} value={option.value} label={option.label} disabled={option.disabled}/>
135-
))}
136-
</Picker>
153+
items={options}
154+
/>
137155

138156
<Picker
139157
label="Wheel Picker"
@@ -142,20 +160,8 @@ export default class PickerScreen extends Component {
142160
value={this.state.nativePickerValue}
143161
onChange={nativePickerValue => this.setState({nativePickerValue})}
144162
trailingAccessory={<Icon source={dropdown}/>}
145-
// containerStyle={{marginTop: 20}}
146-
// renderPicker={() => {
147-
// return (
148-
// <View>
149-
// <Text>Open Native Picker!</Text>
150-
// </View>
151-
// );
152-
// }}
153-
// topBarProps={{doneLabel: 'YES', cancelLabel: 'NO'}}
154-
>
155-
{_.map(options, option => (
156-
<Picker.Item key={option.value} value={option.value} label={option.label} disabled={option.disabled}/>
157-
))}
158-
</Picker>
163+
items={options}
164+
/>
159165

160166
<Picker
161167
label="Custom modal"
@@ -195,12 +201,8 @@ export default class PickerScreen extends Component {
195201
customPickerProps={{migrateDialog: true, dialogProps: {bottom: true, width: '100%', height: '45%'}}}
196202
showSearch
197203
searchPlaceholder={'Search a language'}
198-
>
199-
{_.map(dialogOptions, option => (
200-
<Picker.Item key={option.value} value={option.value} label={option.label} disabled={option.disabled}/>
201-
))}
202-
</Picker>
203-
204+
items={dialogOptions}
205+
/>
204206
<Text marginB-10 text70 $textDefault>
205207
Custom Picker:
206208
</Text>
@@ -221,12 +223,8 @@ export default class PickerScreen extends Component {
221223
</View>
222224
);
223225
}}
224-
>
225-
{_.map(filters, filter => (
226-
<Picker.Item key={filter.value} value={filter.value} label={filter.label}/>
227-
))}
228-
</Picker>
229-
226+
items={filters}
227+
/>
230228
<Text marginT-20 marginB-10 text70 $textDefault>
231229
Custom Picker Items:
232230
</Text>
@@ -236,7 +234,6 @@ export default class PickerScreen extends Component {
236234
onChange={contact => {
237235
this.setState({contact});
238236
}}
239-
// getItemValue={contact => contact?.value}
240237
renderPicker={(contactValue?: number) => {
241238
const contact = contacts[contactValue!] ?? undefined;
242239
return (
@@ -256,78 +253,36 @@ export default class PickerScreen extends Component {
256253
</View>
257254
);
258255
}}
259-
>
260-
{_.map(contacts, contact => (
261-
<Picker.Item
262-
key={contact.name}
263-
value={contact.value}
264-
label={contact.label}
265-
renderItem={(contactValue, props) => {
266-
const contact = contacts[contactValue as number];
267-
return (
268-
<View
269-
style={{
270-
height: 56,
271-
borderBottomWidth: 1,
272-
borderColor: Colors.$backgroundNeutral
273-
}}
274-
paddingH-15
275-
row
276-
centerV
277-
spread
278-
>
279-
<View row centerV>
280-
<Avatar size={35} source={{uri: contact?.thumbnail}}/>
281-
<Text marginL-10 text70 $textDefault>
282-
{contact?.name}
283-
</Text>
284-
</View>
285-
{props.isSelected && <Icon source={Assets.icons.check} tintColor={Colors.$iconDefault}/>}
286-
</View>
287-
);
288-
}}
289-
getItemLabel={contactValue => contacts[contactValue as number]?.name}
290-
/>
291-
))}
292-
</Picker>
293-
256+
items={contacts}
257+
/>
294258
<Button
295259
label="Open Picker Manually"
296260
link
297261
style={{alignSelf: 'flex-start'}}
298262
onPress={() => this.picker.current?.openExpandable?.()}
299263
/>
300-
301264
<Text text60 marginT-s5>
302265
Different Field Types
303266
</Text>
304267
<Text text80 marginB-s5>
305268
(Form/Filter/Settings)
306269
</Text>
307-
308270
<Picker
309271
value={this.state.filter}
310272
onChange={value => this.setState({filter: value})}
311273
placeholder="Filter posts"
312274
fieldType={Picker.fieldTypes.filter}
313275
marginB-s3
314-
>
315-
{filters.map(filter => (
316-
<Picker.Item key={filter.value} {...filter}/>
317-
))}
318-
</Picker>
319-
276+
items={filters}
277+
/>
320278
<Picker
321279
value={this.state.scheme}
322280
onChange={value => this.setState({scheme: value})}
323281
label="Color Scheme"
324282
placeholder="Filter posts"
325283
fieldType={Picker.fieldTypes.settings}
326-
>
327-
{schemes.map(scheme => (
328-
<Picker.Item key={scheme.value} {...scheme}/>
329-
))}
330-
</Picker>
284+
items={schemes}
285+
/>
331286
</View>
332287
</ScrollView>
333288
);

demo/src/screens/realExamples/ProductPage/index.tsx

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import {View, Text, Icon, Colors, Image, Button, Carousel, Picker, PickerValue}
44
import _ from 'lodash';
55
import Assets from '../../../assets/Assets';
66

7-
const colorOptions: {[key: string]: {name: string; color: string}} = {
8-
red: {name: 'Red', color: Colors.red30},
9-
green: {name: 'Green', color: Colors.green30},
10-
blue: {name: 'Blue', color: Colors.blue30}
11-
};
7+
const colorOptions = [
8+
{label: 'Red', value: 'red', color: Colors.red30},
9+
{label: 'Green', value: 'green', color: Colors.green30},
10+
{label: 'Blue', value: 'blue', color: Colors.blue30}
11+
];
1212

13-
const sizeOptions = {
14-
s: {name: 'Small'},
15-
m: {name: 'Medium'},
16-
l: {name: 'Large'}
17-
};
13+
const sizeOptions = [
14+
{label: 'S', value: 's'},
15+
{label: 'M', value: 'm'},
16+
{label: 'L', value: 'l'}
17+
];
1818

1919
const images = [
2020
'https://images.pexels.com/photos/3297502/pexels-photo-3297502.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500',
@@ -75,33 +75,26 @@ class Product extends Component {
7575

7676
<View marginT-s2>
7777
<Picker
78-
migrate
7978
value={selectedColor}
8079
onChange={(value: PickerValue) => this.setState({selectedColor: value})}
8180
trailingAccessory={
8281
<Icon
8382
{...{
8483
width: 24,
8584
height: 24,
86-
backgroundColor: colorOptions[selectedColor].color,
85+
backgroundColor: colorOptions[_.findIndex(colorOptions, {value: selectedColor})].color,
8786
borderRadius: 12
8887
}}
8988
/>
9089
}
91-
>
92-
{_.map(colorOptions, (colorOption, colorKey) => {
93-
return <Picker.Item key={colorKey} value={colorKey} label={colorOption.name}/>;
94-
})}
95-
</Picker>
90+
items={colorOptions}
91+
/>
92+
9693
<Picker
97-
migrate
9894
value={selectedSize}
9995
onChange={(value: PickerValue) => this.setState({selectedSize: value})}
100-
>
101-
{_.map(sizeOptions, (sizeOption, sizeKey) => {
102-
return <Picker.Item key={sizeKey} value={sizeKey} label={sizeOption.name}/>;
103-
})}
104-
</Picker>
96+
items={sizeOptions}
97+
/>
10598
</View>
10699

107100
<Button label={'Add to Cart'}/>

webDemo/src/examples/Picker.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,8 @@ const PickerWrapper = () => {
7777
showSearch
7878
searchPlaceholder={'Search a language'}
7979
searchStyle={{color: Colors.blue30, placeholderTextColor: Colors.grey50}}
80-
>
81-
{options.map(option => (
82-
<Picker.Item key={option.value} value={option.value} label={option.label} disabled={option.disabled}/>
83-
))}
84-
</Picker>
80+
items={options}
81+
/>
8582
</View>
8683
<Text text80BO center>
8784
Multi Value Picker
@@ -98,11 +95,8 @@ const PickerWrapper = () => {
9895
showSearch
9996
searchPlaceholder={'Search a filter'}
10097
searchStyle={{color: Colors.blue30, placeholderTextColor: Colors.grey50}}
101-
>
102-
{filters.map(filter => (
103-
<Picker.Item key={filter.value} value={filter.value} label={filter.label} disabled={filter.disabled}/>
104-
))}
105-
</Picker>
98+
items={filters}
99+
/>
106100
</View>
107101
<Text text80BO center>
108102
Dialog Picker
@@ -114,11 +108,8 @@ const PickerWrapper = () => {
114108
onChange={items => setCustomModalValues(items)}
115109
mode={Picker.modes.MULTI}
116110
renderCustomModal={renderDialog}
117-
>
118-
{schemes.map(option => (
119-
<Picker.Item key={option.value} value={option.value} label={option.label} disabled={option.disabled}/>
120-
))}
121-
</Picker>
111+
items={schemes}
112+
/>
122113
</View>
123114
</View>
124115
);

0 commit comments

Comments
 (0)