@@ -16,25 +16,12 @@ class CollapsiblePickerIOS extends React.Component {
16
16
isCollapsed,
17
17
height : new Animated . Value ( isCollapsed ? 0 : UIPICKER_HEIGHT )
18
18
} ;
19
- this . animatePicker = this . animatePicker . bind ( this ) ;
20
- this . togglePicker = this . togglePicker . bind ( this ) ;
19
+ this . animatePicker = this . _animatePicker . bind ( this ) ;
20
+ this . togglePicker = this . _togglePicker . bind ( this ) ;
21
+ this . onValueChange = this . _onValueChange . bind ( this ) ;
21
22
}
22
23
23
- componentWillReceiveProps ( props ) {
24
- const isCollapsed =
25
- typeof props . locals . isCollapsed === typeof true
26
- ? props . locals . isCollapsed
27
- : this . props . locals . isCollapsed ;
28
- if ( isCollapsed !== this . state . isCollapsed ) {
29
- this . animatePicker ( isCollapsed ) ;
30
- this . setState ( { isCollapsed } ) ;
31
- if ( typeof props . locals . onCollapseChange === "function" ) {
32
- props . locals . onCollapseChange ( isCollapsed ) ;
33
- }
34
- }
35
- }
36
-
37
- animatePicker ( isCollapsed ) {
24
+ _animatePicker ( isCollapsed ) {
38
25
const locals = this . props . locals ;
39
26
let animation = Animated . timing ;
40
27
let animationConfig = {
@@ -48,7 +35,6 @@ class CollapsiblePickerIOS extends React.Component {
48
35
animationConfig = locals . config . animationConfig ;
49
36
}
50
37
}
51
-
52
38
animation (
53
39
this . state . height ,
54
40
Object . assign (
@@ -60,7 +46,7 @@ class CollapsiblePickerIOS extends React.Component {
60
46
) . start ( ) ;
61
47
}
62
48
63
- togglePicker ( ) {
49
+ _togglePicker ( ) {
64
50
this . setState ( { isCollapsed : ! this . state . isCollapsed } , ( ) => {
65
51
this . animatePicker ( this . state . isCollapsed ) ;
66
52
if ( typeof this . props . locals . onCollapseChange === "function" ) {
@@ -69,6 +55,14 @@ class CollapsiblePickerIOS extends React.Component {
69
55
} ) ;
70
56
}
71
57
58
+ _onValueChange ( val ) {
59
+ const { onChange, value } = this . props . locals ;
60
+ if ( val !== value ) {
61
+ this . togglePicker ( ) ;
62
+ onChange ( val ) ;
63
+ }
64
+ }
65
+
72
66
render ( ) {
73
67
const locals = this . props . locals ;
74
68
const { stylesheet } = locals ;
@@ -97,6 +91,7 @@ class CollapsiblePickerIOS extends React.Component {
97
91
) ;
98
92
99
93
const height = this . state . isCollapsed ? 0 : UIPICKER_HEIGHT ;
94
+
100
95
return (
101
96
< View
102
97
style = { [
@@ -122,7 +117,7 @@ class CollapsiblePickerIOS extends React.Component {
122
117
ref = "input"
123
118
style = { selectStyle }
124
119
selectedValue = { locals . value }
125
- onValueChange = { locals . onChange }
120
+ onValueChange = { this . onValueChange }
126
121
help = { locals . help }
127
122
enabled = { ! locals . disabled }
128
123
mode = { locals . mode }
0 commit comments