@@ -10,6 +10,7 @@ export default class CustomDatePickerIOS extends Component {
1010 confirmTextIOS : PropTypes . string ,
1111 customCancelButtonIOS : PropTypes . node ,
1212 customConfirmButtonIOS : PropTypes . node ,
13+ customConfirmButtonWhileInteractingIOS : PropTypes . node ,
1314 customTitleContainerIOS : PropTypes . node ,
1415 datePickerContainerStyleIOS : View . propTypes . style ,
1516 date : PropTypes . instanceOf ( Date ) ,
@@ -31,6 +32,7 @@ export default class CustomDatePickerIOS extends Component {
3132
3233 state = {
3334 date : this . props . date ,
35+ userIsInteractingWithPicker : false ,
3436 } ;
3537
3638 componentWillReceiveProps ( nextProps ) {
@@ -43,7 +45,19 @@ export default class CustomDatePickerIOS extends Component {
4345
4446 _handleConfirm = ( ) => this . props . onConfirm ( this . state . date ) ;
4547
46- _handleDateChange = date => this . setState ( { date } ) ;
48+ _handleDateChange = date => {
49+ this . setState ( {
50+ date,
51+ userIsInteractingWithPicker : false ,
52+ } ) ;
53+ } ;
54+
55+ _handleUserTouchInit = ( ) => {
56+ this . setState ( {
57+ userIsInteractingWithPicker : true ,
58+ } ) ;
59+ return false ;
60+ }
4761
4862 render ( ) {
4963 const {
@@ -55,6 +69,7 @@ export default class CustomDatePickerIOS extends Component {
5569 cancelTextIOS,
5670 customCancelButtonIOS,
5771 customConfirmButtonIOS,
72+ customConfirmButtonWhileInteractingIOS,
5873 customTitleContainerIOS,
5974 datePickerContainerStyleIOS,
6075 date,
@@ -66,21 +81,39 @@ export default class CustomDatePickerIOS extends Component {
6681 < Text style = { styles . title } > { titleIOS } </ Text >
6782 </ View >
6883 ) ;
69- const confirmButton = < Text style = { styles . confirmText } > { confirmTextIOS } </ Text > ;
84+ let confirmButton ;
85+
86+ if ( customConfirmButtonIOS ) { // if we have a custom confirm btn
87+ if ( customConfirmButtonWhileInteractingIOS // if we have a custom confirm btn while we're interacting
88+ && this . state . userIsInteractingWithPicker ) { // and if we're currently interacting
89+ confirmButton = customConfirmButtonWhileInteractingIOS ;
90+ } else { // otherwise if we're not interacting etc
91+ confirmButton = customConfirmButtonIOS ; // just set our confirm button as the custom confirmation button
92+ }
93+ } else { // else if we don't even have a custom confirmation button just create a component now
94+ confirmButton = < Text style = { styles . confirmText } > { confirmTextIOS } </ Text >
95+ }
7096 const cancelButton = < Text style = { styles . cancelText } > { cancelTextIOS } </ Text > ;
7197 return (
7298 < ReactNativeModal isVisible = { isVisible } style = { styles . contentContainer } >
7399 < View style = { [ styles . datepickerContainer , datePickerContainerStyleIOS ] } >
74100 { customTitleContainerIOS || titleContainer }
75- < DatePickerIOS
76- date = { this . state . date }
77- mode = { mode }
78- onDateChange = { this . _handleDateChange }
79- { ...otherProps }
80- />
101+ < View
102+ onStartShouldSetResponderCapture = { this . _handleUserTouchInit }
103+ >
104+ < DatePickerIOS
105+ date = { this . state . date }
106+ mode = { mode }
107+ onDateChange = { this . _handleDateChange }
108+ { ...otherProps }
109+ />
110+ </ View >
81111 < View style = { styles . confirmButton } >
82- < TouchableOpacity onPress = { this . _handleConfirm } >
83- { customConfirmButtonIOS || confirmButton }
112+ < TouchableOpacity
113+ onPress = { this . _handleConfirm }
114+ disabled = { this . state . userIsInteractingWithPicker }
115+ >
116+ { confirmButton }
84117 </ TouchableOpacity >
85118 </ View >
86119 </ View >
0 commit comments