File tree Expand file tree Collapse file tree 2 files changed +22
-13
lines changed Expand file tree Collapse file tree 2 files changed +22
-13
lines changed Original file line number Diff line number Diff line change @@ -52,10 +52,9 @@ class DatePicker extends Component {
52
52
setModalVisible ( visible ) {
53
53
const { height, duration} = this . props ;
54
54
55
- this . setState ( { modalVisible : visible } ) ;
56
-
57
55
// slide animation
58
56
if ( visible ) {
57
+ this . setState ( { modalVisible : visible } ) ;
59
58
Animated . timing (
60
59
this . state . animatedHeight ,
61
60
{
@@ -64,8 +63,14 @@ class DatePicker extends Component {
64
63
}
65
64
) . start ( ) ;
66
65
} else {
67
- this . setState ( {
68
- animatedHeight : new Animated . Value ( 0 )
66
+ Animated . timing (
67
+ this . state . animatedHeight ,
68
+ {
69
+ toValue : 0 ,
70
+ duration : duration
71
+ }
72
+ ) . start ( ( ) => {
73
+ this . setState ( { modalVisible : visible } ) ;
69
74
} ) ;
70
75
}
71
76
}
Original file line number Diff line number Diff line change @@ -156,15 +156,19 @@ describe('DatePicker:', () => {
156
156
const wrapper = shallow ( < DatePicker /> ) ;
157
157
const datePicker = wrapper . instance ( ) ;
158
158
159
- datePicker . setModalVisible ( true ) ;
160
-
161
- expect ( wrapper . state ( 'modalVisible' ) ) . to . equal ( true ) ;
162
- expect ( wrapper . state ( 'animatedHeight' ) . _animation . _toValue ) . to . above ( 200 ) ;
163
-
164
- datePicker . setModalVisible ( false ) ;
165
-
166
- expect ( wrapper . state ( 'modalVisible' ) ) . to . equal ( false ) ;
167
- expect ( wrapper . state ( 'animatedHeight' ) ) . to . deep . equal ( new Animated . Value ( 0 ) ) ;
159
+ new Promise ( function ( resolve , reject ) {
160
+ datePicker . setModalVisible ( true ) ;
161
+ } ) . then ( ( result ) => {
162
+ expect ( wrapper . state ( 'modalVisible' ) ) . to . equal ( true ) ;
163
+ expect ( wrapper . state ( 'animatedHeight' ) . _animation . _toValue ) . to . above ( 200 ) ;
164
+ } )
165
+
166
+ new Promise ( function ( resolve , reject ) {
167
+ datePicker . setModalVisible ( false ) ;
168
+ } ) . then ( ( result ) => {
169
+ expect ( wrapper . state ( 'modalVisible' ) ) . to . equal ( false ) ;
170
+ expect ( wrapper . state ( 'animatedHeight' ) ) . to . deep . equal ( new Animated . Value ( 0 ) ) ;
171
+ } ) ;
168
172
} ) ;
169
173
170
174
it ( 'onPressCancel' , ( ) => {
You can’t perform that action at this time.
0 commit comments