@@ -57,7 +57,7 @@ class CascadePicker extends React.Component<Props, State> {
5757 this . _width = new Animated . Value ( 100 )
5858 }
5959
60- _startAnimation = ( selectedOption : Option | any ) => {
60+ _startAnimation = ( selectedOption : ? Option ) => {
6161 let height = ALMOST_ZERO
6262 let width = 100
6363 let collapseAnimation = Animated . timing ( this . _height , {
@@ -81,24 +81,21 @@ class CascadePicker extends React.Component<Props, State> {
8181 } ) ,
8282 collapseAnimation
8383 ] ) . start ( )
84- const isCollapsed = ! this . state . isCollapsed
8584 if ( selectedOption ) {
86- this . setState ( { isCollapsed } )
8785 // Pass the option selected
8886 InteractionManager . runAfterInteractions ( ( ) => {
8987 this . props . onChange ( selectedOption )
9088 } )
91- } else {
92- this . setState ( { isCollapsed } )
9389 }
90+ this . setState ( { isCollapsed : ! this . state . isCollapsed } )
9491 }
9592
96- _findElement = ( element : Object ) => {
97- return element . weeks === this . props . valueSelected
93+ _findElement = ( element : Option ) : boolean => {
94+ return element . value === this . props . valueSelected
9895 }
9996
10097 _renderChilds ( ) {
101- return this . props . options . map ( ( optionObject : Object , index : number ) => (
98+ return this . props . options . map ( ( optionObject : Option , index : number ) => (
10299 < OptionButton
103100 option = { optionObject }
104101 onPress = { this . _startAnimation }
@@ -108,7 +105,7 @@ class CascadePicker extends React.Component<Props, State> {
108105 styles . separator ,
109106 {
110107 backgroundColor :
111- optionObject . weeks === this . props . valueSelected
108+ optionObject . value === this . props . valueSelected
112109 ? this . props . selectedColor
113110 : this . props . itemColor
114111 }
@@ -122,27 +119,25 @@ class CascadePicker extends React.Component<Props, State> {
122119 _renderButton ( ) {
123120 const option : ?Option = this . props . valueSelected
124121 ? this . props . options . find ( this . _findElement )
125- : this . props . options [ 0 ]
122+ : undefined
126123 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 >
146141 )
147142 }
148143
0 commit comments