Skip to content

Commit b6e9457

Browse files
authored
Merge pull request #46 from mars-lan/master
Make sure that onHideAfterConfirm is only called when the confirm button is pressed
2 parents ed50fdd + ce0e04a commit b6e9457

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/CustomDatePickerIOS/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,20 @@ export default class CustomDatePickerIOS extends Component {
4747
}
4848
}
4949

50-
_handleConfirm = () => this.props.onConfirm(this.state.date);
50+
_handleCancel = () => {
51+
this.confirmed = false;
52+
this.props.onCancel();
53+
};
54+
55+
_handleConfirm = () => {
56+
this.confirmed = true;
57+
this.props.onConfirm(this.state.date);
58+
}
5159

5260
_handleOnModalHide = () => {
53-
this.props.onHideAfterConfirm(this.state.date);
61+
if (this.confirmed) {
62+
this.props.onHideAfterConfirm(this.state.date);
63+
}
5464
};
5565

5666
_handleDateChange = date => {
@@ -69,7 +79,6 @@ export default class CustomDatePickerIOS extends Component {
6979

7080
render() {
7181
const {
72-
onCancel,
7382
isVisible,
7483
mode,
7584
titleIOS,
@@ -137,7 +146,7 @@ export default class CustomDatePickerIOS extends Component {
137146
</View>
138147

139148
<View style={styles.cancelButton}>
140-
<TouchableOpacity onPress={onCancel}>
149+
<TouchableOpacity onPress={this._handleCancel}>
141150
{customCancelButtonIOS || cancelButton}
142151
</TouchableOpacity>
143152
</View>

0 commit comments

Comments
 (0)