Skip to content

Commit

Permalink
refactor: forward ref to datepicker instance
Browse files Browse the repository at this point in the history
  • Loading branch information
ArekChr committed Mar 31, 2023
1 parent 618d14e commit 4cdc921
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
13 changes: 2 additions & 11 deletions src/components/NewDatePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,7 @@ class NewDatePicker extends React.Component {
<View style={[this.props.isSmallScreenWidth ? styles.flex2 : {}]}>
<TextInput
forceActiveLabel
ref={(el) => {
this.textInputRef = el;
if (!_.isFunction(this.props.innerRef)) {
return;
}
this.props.innerRef(el);
}}
ref={el => this.textInputRef = el}
icon={Expensicons.Calendar}
onPress={this.showPicker}
label={this.props.label}
Expand Down Expand Up @@ -177,7 +171,4 @@ class NewDatePicker extends React.Component {
NewDatePicker.propTypes = propTypes;
NewDatePicker.defaultProps = datePickerDefaultProps;

export default withLocalize(React.forwardRef((props, ref) => (
/* eslint-disable-next-line react/jsx-props-no-spreading */
<NewDatePicker {...props} innerRef={ref} />
)));
export default withLocalize(NewDatePicker);
12 changes: 8 additions & 4 deletions src/pages/settings/Profile/PersonalDetails/DateOfBirthPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class DateOfBirthPage extends Component {

componentDidMount() {
this.props.navigation.addListener('focus', this.getYearFromRouteParams);

setTimeout(() => {
if (!this.datePicker) {
return;
}
this.datePicker.showPicker();
}, 1);
}

componentWillUnmount() {
Expand All @@ -67,10 +74,7 @@ class DateOfBirthPage extends Component {
if (params && params.year) {
this.setState({selectedYear: params.year});
if (this.datePicker) {
this.datePicker.focus();
if (_.isFunction(this.datePicker.click)) {
this.datePicker.click();
}
this.datePicker.showPicker();
}
}
}
Expand Down

0 comments on commit 4cdc921

Please sign in to comment.