Skip to content

Commit 47516f2

Browse files
authored
Feat/add label to wheelPicker (#1259)
* Feat/add label to wheelPicker * naming * naming + edit screen
1 parent 55d764f commit 47516f2

File tree

3 files changed

+109
-17
lines changed

3 files changed

+109
-17
lines changed

demo/src/screens/incubatorScreens/WheelPickerScreen.tsx

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {useCallback, useState} from 'react';
2-
import {View, Text, Incubator, Colors, Typography} from 'react-native-ui-lib';
2+
import {View, Text, Incubator, Colors, Typography, Button, Dialog} from 'react-native-ui-lib';
33
import _ from 'lodash';
44

55
// Months
@@ -21,10 +21,21 @@ const months = [
2121
// Years
2222
const years = _.times(2020, i => i);
2323

24-
const useData = (initialMonth?: string, initialYear?: string) => {
24+
const days = _.times(365, i => i + 1);
2525

26+
const useData = (initialMonth?: string, initialYear?: string, initialDays?: number) => {
2627
const [selectedMonth, setMonth] = useState<string | undefined>(initialMonth);
2728
const [selectedYear, setYear] = useState<string | undefined>(initialYear);
29+
const [selectedDays, setDays] = useState<number | undefined>(initialDays);
30+
const [showDialog, setShowDialog] = useState(false);
31+
32+
const onPickDaysPress = () => {
33+
setShowDialog(true);
34+
};
35+
36+
const onDialogDismissed = () => {
37+
setShowDialog(false);
38+
};
2839

2940
const onMonthChange = (item: string | undefined, _: number) => {
3041
setMonth(item);
@@ -34,6 +45,10 @@ const useData = (initialMonth?: string, initialYear?: string) => {
3445
setYear(item);
3546
};
3647

48+
const onDaysChange = (item: number | undefined, _: number) => {
49+
setDays(item);
50+
};
51+
3752
const getMonths = useCallback(() => {
3853
return _.map(months, item => ({label: item, value: item}));
3954
}, []);
@@ -42,25 +57,47 @@ const useData = (initialMonth?: string, initialYear?: string) => {
4257
return _.map(years, item => ({label: '' + item, value: item}));
4358
}, []);
4459

60+
const getDays = useCallback(() => {
61+
return _.map(days, item => ({label: '' + item, value: item}));
62+
}, []);
63+
4564
return {
46-
getMonths,
65+
getMonths,
4766
getYears,
67+
getDays,
4868
onMonthChange,
4969
onYearChange,
70+
onDaysChange,
5071
selectedMonth,
51-
selectedYear
72+
selectedYear,
73+
selectedDays,
74+
onPickDaysPress,
75+
onDialogDismissed,
76+
showDialog
5277
};
5378
};
5479

5580
export default () => {
56-
57-
const {selectedMonth, onMonthChange, getMonths, selectedYear, onYearChange, getYears} = useData('February', undefined);
81+
const {
82+
selectedMonth,
83+
onMonthChange,
84+
getMonths,
85+
selectedYear,
86+
onYearChange,
87+
getYears,
88+
selectedDays,
89+
onDaysChange,
90+
getDays,
91+
onPickDaysPress,
92+
onDialogDismissed,
93+
showDialog
94+
} = useData('February', undefined, 5);
5895

5996
return (
6097
<View flex padding-page>
6198
<Text h1>Wheel Picker</Text>
62-
63-
<View flex centerV centerH>
99+
100+
<View flex marginT-20 centerH>
64101
<Text h3>Months</Text>
65102
<Incubator.WheelPicker
66103
style={{width: '100%'}}
@@ -71,11 +108,26 @@ export default () => {
71108
textStyle={Typography.text60R}
72109
selectedValue={selectedMonth}
73110
/>
74-
111+
75112
<Text h3>Years</Text>
76-
<View height={300} width={'100%'}>
77-
<Incubator.WheelPicker onChange={onYearChange} selectedValue={selectedYear} items={getYears()}/>
113+
<View width={'100%'}>
114+
<Incubator.WheelPicker
115+
onChange={onYearChange}
116+
numberOfVisibleRows={3}
117+
selectedValue={selectedYear}
118+
items={getYears()}
119+
/>
78120
</View>
121+
122+
<Button marginT-40 label={'Pick Days'} marginH-120 onPress={onPickDaysPress}/>
123+
<Dialog width={'90%'} height={260} bottom visible={showDialog} onDismiss={onDialogDismissed}>
124+
<Incubator.WheelPicker
125+
onChange={onDaysChange}
126+
selectedValue={selectedDays}
127+
label={selectedDays === 1 ? 'Day' : 'Days'}
128+
items={getDays()}
129+
/>
130+
</Dialog>
79131
</View>
80132
</View>
81133
);

generatedTypes/incubator/WheelPicker/index.d.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { TextStyle, ViewStyle } from 'react-native';
33
import { ItemProps } from './Item';
4+
import { TextProps } from '../../components/text';
45
export interface WheelPickerProps {
56
/**
67
* Data source for WheelPicker
@@ -28,6 +29,18 @@ export interface WheelPickerProps {
2829
* Row text style
2930
*/
3031
textStyle?: TextStyle;
32+
/**
33+
* Additional label on the right of the item text
34+
*/
35+
label?: string;
36+
/**
37+
* The Additional label's style
38+
*/
39+
labelStyle?: TextStyle;
40+
/**
41+
* The Additional label's props
42+
*/
43+
labelProps?: TextProps;
3144
/**
3245
* Event, on active row change
3346
*/
@@ -45,5 +58,5 @@ export interface WheelPickerProps {
4558
*/
4659
selectedValue: ItemProps | number | string;
4760
}
48-
declare const WheelPicker: React.MemoExoticComponent<({ items: propItems, itemHeight, numberOfVisibleRows, activeTextColor, inactiveTextColor, textStyle, onChange, style, children, selectedValue }: WheelPickerProps) => JSX.Element>;
61+
declare const WheelPicker: React.MemoExoticComponent<({ items: propItems, itemHeight, numberOfVisibleRows, activeTextColor, inactiveTextColor, textStyle, label, labelStyle, labelProps, onChange, style, children, selectedValue }: WheelPickerProps) => JSX.Element>;
4962
export default WheelPicker;

src/incubator/WheelPicker/index.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Fader, {FaderPosition} from '../../components/fader';
99
import {Constants} from '../../helpers';
1010
import Item, {ItemProps} from './Item';
1111
import usePresenter from './usePresenter';
12+
import Text, {TextProps} from '../../components/text';
1213

1314
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
1415

@@ -39,6 +40,18 @@ export interface WheelPickerProps {
3940
* Row text style
4041
*/
4142
textStyle?: TextStyle;
43+
/**
44+
* Additional label on the right of the item text
45+
*/
46+
label?: string;
47+
/**
48+
* The Additional label's style
49+
*/
50+
labelStyle?: TextStyle;
51+
/**
52+
* The Additional label's props
53+
*/
54+
labelProps?: TextProps;
4255
/**
4356
* Event, on active row change
4457
*/
@@ -62,9 +75,12 @@ const WheelPicker = React.memo(
6275
items: propItems,
6376
itemHeight = 44,
6477
numberOfVisibleRows = 5,
65-
activeTextColor,
78+
activeTextColor = Colors.primary,
6679
inactiveTextColor,
6780
textStyle,
81+
label,
82+
labelStyle,
83+
labelProps,
6884
onChange,
6985
style,
7086
children,
@@ -143,7 +159,7 @@ const WheelPicker = React.memo(
143159
[itemHeight]
144160
);
145161

146-
const separators = () => {
162+
const renderSeparatorsAndLabel = () => {
147163
return (
148164
<View absF centerV pointerEvents="none">
149165
<View
@@ -153,17 +169,28 @@ const WheelPicker = React.memo(
153169
height: Spacings.s9,
154170
borderColor: Colors.grey60
155171
}}
156-
/>
172+
center
173+
>
174+
{renderLabel()}
175+
</View>
157176
</View>
158177
);
159178
};
160179

180+
const renderLabel = () => {
181+
return (
182+
<Text marginL-80 text80M {...labelProps} color={activeTextColor} style={labelStyle}>
183+
{label}
184+
</Text>
185+
);
186+
};
187+
161188
const fader = useMemo(() => (position: FaderPosition) => {
162189
return <Fader visible position={position} size={60}/>;
163190
}, []);
164191

165192
return (
166-
<View style={style}>
193+
<View bg-white style={style}>
167194
<AnimatedFlatList
168195
height={height}
169196
data={items}
@@ -185,7 +212,7 @@ const WheelPicker = React.memo(
185212
/>
186213
{fader(FaderPosition.BOTTOM)}
187214
{fader(FaderPosition.TOP)}
188-
{separators()}
215+
{renderSeparatorsAndLabel()}
189216
</View>
190217
);
191218
});

0 commit comments

Comments
 (0)