Skip to content

Commit

Permalink
HF for DateTimePicker not passing the user the chosen date
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanshar committed Jan 28, 2020
1 parent 0c2d7d7 commit be42c44
Showing 1 changed file with 41 additions and 29 deletions.
70 changes: 41 additions & 29 deletions src/components/dateTimePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Dialog from '../dialog';
import View from '../view';
import Button from '../button';


const MODES = {
DATE: 'date',
TIME: 'time'
Expand Down Expand Up @@ -66,7 +65,7 @@ class DateTimePicker extends BaseComponent {
* Props to pass the Dialog component
*/
dialogProps: PropTypes.object
}
};

static defaultProps = {
...TextField.defaultProps,
Expand All @@ -89,29 +88,30 @@ class DateTimePicker extends BaseComponent {
this.styles = createStyles(this.props);
}

setDate = (event, date) => {
if (date !== undefined) {
handleChange = (event = {}, date) => {
if (event.type !== 'dismissed' && date !== undefined) {
this.chosenDate = date;

if (Constants.isAndroid) {
this.setState({chosenDate: this.chosenDate, showExpandableOverlay: false});
this.onDonePressed();
}
}
};

_.invoke(this.props, 'onChange');
}

toggleExpandableOverlay = (callback) => {
this.setState({showExpandableOverlay: !this.state.showExpandableOverlay}, () => {
if (_.isFunction(callback)) {
callback();
}
});
toggleExpandableOverlay = callback => {
this.setState({showExpandableOverlay: !this.state.showExpandableOverlay},
() => {
if (_.isFunction(callback)) {
callback();
}
});
};

onDonePressed = () => {
this.toggleExpandableOverlay(() => this.setState({chosenDate: this.chosenDate}));
}
onDonePressed = () =>
this.toggleExpandableOverlay(() => {
_.invoke(this.props, 'onChange', this.chosenDate);
this.setState({chosenDate: this.chosenDate});
});

renderExpandableOverlay = () => {
const {testID, dialogProps} = this.getThemeProps();
Expand All @@ -128,7 +128,12 @@ class DateTimePicker extends BaseComponent {
onDismiss={this.toggleExpandableOverlay}
containerStyle={this.styles.dialog}
testID={`${testID}.dialog`}
supportedOrientations={['portrait', 'landscape', 'landscape-left', 'landscape-right']} // iOS only
supportedOrientations={[
'portrait',
'landscape',
'landscape-left',
'landscape-right'
]} // iOS only
{...dialogProps}
>
<View useSafeArea>
Expand Down Expand Up @@ -166,32 +171,39 @@ class DateTimePicker extends BaseComponent {

if (showExpandableOverlay) {
return (
<RNDateTimePicker
<RNDateTimePicker
mode={mode}
value={chosenDate}
onChange={this.setDate}
onChange={this.handleChange}
minimumDate={minimumDate}
maximumDate={maximumDate}
/>
);
}
}

renderExpandable = () => {
return Constants.isAndroid ? this.renderDateTimePicker() : this.renderExpandableOverlay();
}
renderExpandable = () => {
return Constants.isAndroid
? this.renderDateTimePicker()
: this.renderExpandableOverlay();
};

render() {
const {chosenDate} = this.state;
const {mode, dateFormat, timeFormat} = this.getThemeProps();
const textInputProps = TextField.extractOwnProps(this.getThemeProps());
const dateString = mode === MODES.DATE ?
(dateFormat ? moment(chosenDate).format(dateFormat) : chosenDate.toLocaleDateString()) :
(timeFormat ? moment(chosenDate).format(timeFormat) : chosenDate.toLocaleTimeString());

const dateString =
mode === MODES.DATE
? dateFormat
? moment(chosenDate).format(dateFormat)
: chosenDate.toLocaleDateString()
: timeFormat
? moment(chosenDate).format(timeFormat)
: chosenDate.toLocaleTimeString();

return (
<TextField
{...textInputProps}
<TextField
{...textInputProps}
value={dateString}
expandable
renderExpandable={this.renderExpandable}
Expand Down

0 comments on commit be42c44

Please sign in to comment.