1
+ import _ from 'lodash' ;
1
2
import React , { useCallback , useState } from 'react' ;
2
3
import { View , Text , Incubator , Colors , Typography , Button , Dialog } from 'react-native-ui-lib' ;
3
- import _ from 'lodash' ;
4
4
5
5
const monthItems = _ . map ( [
6
6
'January' ,
@@ -16,7 +16,7 @@ const monthItems = _.map([
16
16
'November' ,
17
17
'December'
18
18
] ,
19
- item => ( { label : item , value : item } ) ) ;
19
+ item => ( { label : item , value : item , align : Incubator . WheelPickerAlign . RIGHT } ) ) ;
20
20
21
21
const yearItems = _ . times ( 2050 , i => i )
22
22
. reverse ( )
@@ -28,10 +28,14 @@ export default () => {
28
28
const [ yearsValue , setYearsValue ] = useState ( 2022 ) ;
29
29
30
30
const updateYearsInitialValue = useCallback ( ( increaseYears : boolean ) => {
31
- increaseYears ? setYearsValue ( Math . min ( yearsValue + 5 , 2049 ) ) : setYearsValue ( Math . max ( yearsValue - 5 , 0 ) ) ;
31
+ increaseYears ? setYearsValue ( Math . min ( yearsValue + 1 , 2049 ) ) : setYearsValue ( Math . max ( yearsValue - 1 , 0 ) ) ;
32
32
} ,
33
33
[ yearsValue ] ) ;
34
34
35
+ const onChange = useCallback ( ( value ) => {
36
+ setYearsValue ( value ) ;
37
+ } , [ ] ) ;
38
+
35
39
const onPickDaysPress = useCallback ( ( ) => {
36
40
setShowDialog ( true ) ;
37
41
} , [ ] ) ;
@@ -44,32 +48,46 @@ export default () => {
44
48
< View flex padding-page >
45
49
< Text h1 > Wheel Picker</ Text >
46
50
47
- < View marginT-s5 centerH >
48
- < Text h3 > Months</ Text >
49
- < Incubator . WheelPicker
50
- initialValue = { 'February' }
51
- activeTextColor = { Colors . primary }
52
- inactiveTextColor = { Colors . grey20 }
53
- items = { monthItems }
54
- textStyle = { Typography . text60R }
55
- />
51
+ < View row center marginT-30 >
52
+ < View center >
53
+ < Text h3 > Months</ Text >
54
+ < Incubator . WheelPicker
55
+ initialValue = { 'February' }
56
+ activeTextColor = { Colors . primary }
57
+ inactiveTextColor = { Colors . grey20 }
58
+ items = { monthItems }
59
+ textStyle = { Typography . text60R }
60
+ numberOfVisibleRows = { 3 }
61
+ />
62
+ </ View >
56
63
57
- < Text h3 > Years</ Text >
58
- < View width = { '100%' } marginT-s3 >
59
- < Incubator . WheelPicker numberOfVisibleRows = { 3 } initialValue = { yearsValue } items = { yearItems } />
64
+ < View center >
65
+ < Text h3 > Years</ Text >
66
+ < Incubator . WheelPicker
67
+ numberOfVisibleRows = { 3 }
68
+ initialValue = { yearsValue }
69
+ items = { yearItems }
70
+ onChange = { onChange }
71
+ />
60
72
</ View >
73
+ </ View >
61
74
62
- < Text marginT-10 bodySmall grey30 >
63
- (update value by passing a new initialValue)
75
+ < View center marginT-30 >
76
+ < Text body >
77
+ Move the wheel programmatically
78
+ </ Text >
79
+ < Text bodySmall grey30 >
80
+ (by updating the initialValue prop)
64
81
</ Text >
65
82
< View marginT-10 row >
66
- < Button label = { '-5 years ' } marginR-20 onPress = { ( ) => updateYearsInitialValue ( false ) } />
67
- < Button label = { '+5 years ' } onPress = { ( ) => updateYearsInitialValue ( true ) } />
83
+ < Button size = "medium" label = { 'Previous ' } marginR-20 onPress = { ( ) => updateYearsInitialValue ( false ) } />
84
+ < Button size = "medium" label = { 'Next ' } onPress = { ( ) => updateYearsInitialValue ( true ) } />
68
85
</ View >
69
86
</ View >
70
87
71
- < View marginB-s10 >
72
- < Button marginT-40 label = { 'Pick Days' } marginH-100 onPress = { onPickDaysPress } />
88
+ < View center marginT-40 >
89
+ < Text h3 marginB-20 > Days</ Text >
90
+ < Button size = "small" label = { 'Pick Days' } onPress = { onPickDaysPress } />
73
91
< Dialog width = { '90%' } height = { 260 } bottom visible = { showDialog } onDismiss = { onDialogDismissed } >
74
92
< Incubator . WheelPicker initialValue = { 5 } label = { 'Days' } items = { dayItems } />
75
93
</ Dialog >
0 commit comments