Skip to content

Commit

Permalink
Add animation on datepicker dismiss
Browse files Browse the repository at this point in the history
  • Loading branch information
Kat Hawthorne committed Jan 26, 2017
1 parent 59d414d commit fdfcc21
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ class DatePicker extends Component {
setModalVisible(visible) {
const {height, duration} = this.props;

this.setState({modalVisible: visible});

// slide animation
if (visible) {
this.setState({modalVisible: visible});
Animated.timing(
this.state.animatedHeight,
{
Expand All @@ -64,8 +63,14 @@ class DatePicker extends Component {
}
).start();
} else {
this.setState({
animatedHeight: new Animated.Value(0)
Animated.timing(
this.state.animatedHeight,
{
toValue: 0,
duration: duration
}
).start(() => {
this.setState({modalVisible: visible});
});
}
}
Expand Down
22 changes: 13 additions & 9 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,19 @@ describe('DatePicker:', () => {
const wrapper = shallow(<DatePicker />);
const datePicker = wrapper.instance();

datePicker.setModalVisible(true);

expect(wrapper.state('modalVisible')).to.equal(true);
expect(wrapper.state('animatedHeight')._animation._toValue).to.above(200);

datePicker.setModalVisible(false);

expect(wrapper.state('modalVisible')).to.equal(false);
expect(wrapper.state('animatedHeight')).to.deep.equal(new Animated.Value(0));
new Promise(function(resolve, reject) {
datePicker.setModalVisible(true);
}).then((result) => {
expect(wrapper.state('modalVisible')).to.equal(true);
expect(wrapper.state('animatedHeight')._animation._toValue).to.above(200);
})

new Promise(function(resolve, reject) {
datePicker.setModalVisible(false);
}).then((result) => {
expect(wrapper.state('modalVisible')).to.equal(false);
expect(wrapper.state('animatedHeight')).to.deep.equal(new Animated.Value(0));
});
});

it('onPressCancel', () => {
Expand Down

0 comments on commit fdfcc21

Please sign in to comment.