@@ -57,7 +57,7 @@ class CascadePicker extends React.Component<Props, State> {
57
57
this . _width = new Animated . Value ( 100 )
58
58
}
59
59
60
- _startAnimation = ( selectedOption : Option | any ) => {
60
+ _startAnimation = ( selectedOption : ? Option ) => {
61
61
let height = ALMOST_ZERO
62
62
let width = 100
63
63
let collapseAnimation = Animated . timing ( this . _height , {
@@ -81,24 +81,21 @@ class CascadePicker extends React.Component<Props, State> {
81
81
} ) ,
82
82
collapseAnimation
83
83
] ) . start ( )
84
- const isCollapsed = ! this . state . isCollapsed
85
84
if ( selectedOption ) {
86
- this . setState ( { isCollapsed } )
87
85
// Pass the option selected
88
86
InteractionManager . runAfterInteractions ( ( ) => {
89
87
this . props . onChange ( selectedOption )
90
88
} )
91
- } else {
92
- this . setState ( { isCollapsed } )
93
89
}
90
+ this . setState ( { isCollapsed : ! this . state . isCollapsed } )
94
91
}
95
92
96
- _findElement = ( element : Object ) => {
97
- return element . weeks === this . props . valueSelected
93
+ _findElement = ( element : Option ) : boolean => {
94
+ return element . value === this . props . valueSelected
98
95
}
99
96
100
97
_renderChilds ( ) {
101
- return this . props . options . map ( ( optionObject : Object , index : number ) => (
98
+ return this . props . options . map ( ( optionObject : Option , index : number ) => (
102
99
< OptionButton
103
100
option = { optionObject }
104
101
onPress = { this . _startAnimation }
@@ -108,7 +105,7 @@ class CascadePicker extends React.Component<Props, State> {
108
105
styles . separator ,
109
106
{
110
107
backgroundColor :
111
- optionObject . weeks === this . props . valueSelected
108
+ optionObject . value === this . props . valueSelected
112
109
? this . props . selectedColor
113
110
: this . props . itemColor
114
111
}
@@ -122,27 +119,25 @@ class CascadePicker extends React.Component<Props, State> {
122
119
_renderButton ( ) {
123
120
const option : ?Option = this . props . valueSelected
124
121
? this . props . options . find ( this . _findElement )
125
- : this . props . options [ 0 ]
122
+ : undefined
126
123
return (
127
- < View >
128
- < MainOptionButton
129
- isCollapsed = { this . state . isCollapsed }
130
- onPress = { this . _startAnimation }
131
- style = { [
132
- styles . option ,
133
- styles . separator ,
134
- {
135
- borderBottomColor : this . props . separatorColor ,
136
- backgroundColor : this . props . mainColor
137
- }
138
- ] }
139
- textStyle = { [
140
- styles . mainOptionText ,
141
- { color : this . props . selectedTextColor }
142
- ] } >
143
- { option ? option . label : this . props . pickerText }
144
- </ MainOptionButton >
145
- </ View >
124
+ < MainOptionButton
125
+ isCollapsed = { this . state . isCollapsed }
126
+ onPress = { this . _startAnimation }
127
+ style = { [
128
+ styles . option ,
129
+ styles . separator ,
130
+ {
131
+ borderBottomColor : this . props . separatorColor ,
132
+ backgroundColor : this . props . mainColor
133
+ }
134
+ ] }
135
+ textStyle = { [
136
+ styles . mainOptionText ,
137
+ { color : this . props . selectedTextColor }
138
+ ] } >
139
+ { option ? option . label : this . props . pickerText }
140
+ </ MainOptionButton >
146
141
)
147
142
}
148
143
0 commit comments