1+ import _ from 'lodash' ;
12import React , { useCallback , useState } from 'react' ;
23import { View , Text , Incubator , Colors , Typography , Button , Dialog } from 'react-native-ui-lib' ;
3- import _ from 'lodash' ;
44
55const monthItems = _ . map ( [
66 'January' ,
@@ -16,7 +16,7 @@ const monthItems = _.map([
1616 'November' ,
1717 'December'
1818] ,
19- item => ( { label : item , value : item } ) ) ;
19+ item => ( { label : item , value : item , align : Incubator . WheelPickerAlign . RIGHT } ) ) ;
2020
2121const yearItems = _ . times ( 2050 , i => i )
2222 . reverse ( )
@@ -28,10 +28,14 @@ export default () => {
2828 const [ yearsValue , setYearsValue ] = useState ( 2022 ) ;
2929
3030 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 ) ) ;
3232 } ,
3333 [ yearsValue ] ) ;
3434
35+ const onChange = useCallback ( ( value ) => {
36+ setYearsValue ( value ) ;
37+ } , [ ] ) ;
38+
3539 const onPickDaysPress = useCallback ( ( ) => {
3640 setShowDialog ( true ) ;
3741 } , [ ] ) ;
@@ -44,32 +48,46 @@ export default () => {
4448 < View flex padding-page >
4549 < Text h1 > Wheel Picker</ Text >
4650
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 >
5663
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+ />
6072 </ View >
73+ </ View >
6174
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)
6481 </ Text >
6582 < 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 ) } />
6885 </ View >
6986 </ View >
7087
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 } />
7391 < Dialog width = { '90%' } height = { 260 } bottom visible = { showDialog } onDismiss = { onDialogDismissed } >
7492 < Incubator . WheelPicker initialValue = { 5 } label = { 'Days' } items = { dayItems } />
7593 </ Dialog >
0 commit comments