Skip to content

Commit 7a451bc

Browse files
authored
Merge pull request xgfe#76 from kathawthorne/animate-close
Add animation on datepicker dismiss
2 parents 0d887db + fdfcc21 commit 7a451bc

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ class DatePicker extends Component {
5252
setModalVisible(visible) {
5353
const {height, duration} = this.props;
5454

55-
this.setState({modalVisible: visible});
56-
5755
// slide animation
5856
if (visible) {
57+
this.setState({modalVisible: visible});
5958
Animated.timing(
6059
this.state.animatedHeight,
6160
{
@@ -64,8 +63,14 @@ class DatePicker extends Component {
6463
}
6564
).start();
6665
} 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});
6974
});
7075
}
7176
}

test/index.test.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,19 @@ describe('DatePicker:', () => {
156156
const wrapper = shallow(<DatePicker />);
157157
const datePicker = wrapper.instance();
158158

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+
});
168172
});
169173

170174
it('onPressCancel', () => {

0 commit comments

Comments
 (0)