@@ -4,7 +4,7 @@ import {Alert} from 'react-native';
4
4
import { Text , View , SectionsWheelPicker , SegmentedControl , Button , Incubator } from 'react-native-ui-lib' ;
5
5
6
6
const SectionsWheelPickerScreen = ( ) => {
7
- const [ showMinutes , setShowMinutes ] = useState ( false ) ;
7
+ const [ numOfSections , setNumOfSections ] = useState ( 1 ) ;
8
8
9
9
const [ selectedDays , setSelectedDays ] = useState ( 0 ) ;
10
10
const [ selectedHours , setSelectedHours ] = useState ( 0 ) ;
@@ -35,7 +35,7 @@ const SectionsWheelPickerScreen = () => {
35
35
const hours = selectedHours === 1 ? 'hour' : 'hours' ;
36
36
const minutes = selectedMinutes === 1 ? 'minute' : 'minutes' ;
37
37
38
- showMinutes
38
+ numOfSections === 3
39
39
? Alert . alert ( 'Your chosen duration is:\n' +
40
40
selectedDays +
41
41
' ' +
@@ -48,7 +48,9 @@ const SectionsWheelPickerScreen = () => {
48
48
selectedMinutes +
49
49
' ' +
50
50
minutes )
51
- : Alert . alert ( 'Your chosen duration is:\n' + selectedDays + ' ' + days + ' and ' + selectedHours + ' ' + hours ) ;
51
+ : numOfSections === 2
52
+ ? Alert . alert ( 'Your chosen duration is:\n' + selectedDays + ' ' + days + ' and ' + selectedHours + ' ' + hours )
53
+ : Alert . alert ( 'Your chosen duration is:\n' + selectedDays + ' ' + days ) ;
52
54
} ;
53
55
54
56
const onResetPress = ( ) => {
@@ -58,20 +60,33 @@ const SectionsWheelPickerScreen = () => {
58
60
} ;
59
61
60
62
const sections : Incubator . WheelPickerProps [ ] = [
61
- { items : getItems ( days ) , onChange : onDaysChange , selectedValue : selectedDays , label : 'Days' } ,
62
- { items : getItems ( hours ) , onChange : onHoursChange , selectedValue : selectedHours , label : 'Hrs' } ,
63
+ {
64
+ items : getItems ( days ) ,
65
+ onChange : onDaysChange ,
66
+ selectedValue : selectedDays ,
67
+ label : 'Days' ,
68
+ style : numOfSections === 1 ? { flex : 1 } : { flex : 1 , alignItems : 'flex-end' }
69
+ } ,
70
+ {
71
+ items : getItems ( hours ) ,
72
+ onChange : onHoursChange ,
73
+ selectedValue : selectedHours ,
74
+ label : 'Hrs' ,
75
+ style : numOfSections === 2 ? { flex : 1 , alignItems : 'flex-start' } : undefined
76
+ } ,
63
77
{
64
78
items : getItems ( minutes ) ,
65
79
onChange : onMinutesChange ,
66
80
selectedValue : selectedMinutes ,
67
- label : 'Mins'
81
+ label : 'Mins' ,
82
+ style : { flex : 1 , alignItems : 'flex-start' }
68
83
}
69
84
] ;
70
85
71
- const sectionsToPresent = showMinutes ? sections : _ . slice ( sections , 0 , 2 ) ;
86
+ const sectionsToPresent = _ . slice ( sections , 0 , numOfSections ) ;
72
87
73
88
const onChangeIndex = ( index : number ) => {
74
- return index === 0 ? setShowMinutes ( false ) : setShowMinutes ( true ) ;
89
+ return setNumOfSections ( index + 1 ) ;
75
90
} ;
76
91
77
92
return (
@@ -80,13 +95,16 @@ const SectionsWheelPickerScreen = () => {
80
95
Sections Wheel Picker
81
96
</ Text >
82
97
< View centerH marginT-40 >
83
- < SegmentedControl segments = { [ { label : '2 sections' } , { label : '3 sections' } ] } onChangeIndex = { onChangeIndex } />
98
+ < SegmentedControl
99
+ segments = { [ { label : '1 section' } , { label : '2 sections' } , { label : '3 sections' } ] }
100
+ onChangeIndex = { onChangeIndex }
101
+ />
84
102
< Text text50 marginV-20 >
85
103
Pick a duration
86
104
</ Text >
87
105
</ View >
88
106
< SectionsWheelPicker sections = { sectionsToPresent } />
89
- < Button marginH-150 marginT-300 label = { 'Save' } onPress = { onSavePress } />
107
+ < Button marginH-150 marginT-40 label = { 'Save' } onPress = { onSavePress } />
90
108
< Button marginH-150 marginT-15 label = { 'Reset' } onPress = { onResetPress } />
91
109
</ View >
92
110
) ;
0 commit comments