Skip to content

Commit

Permalink
remove onPickerChange
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Sep 7, 2016
1 parent 39081a1 commit c60ea27
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -118,7 +118,6 @@ in [RNPlayground](https://github.com/react-component/RNPlayground)
|date | The currently selected date. | moment | |
|visible | whether pop picker is visible | Boolean | false |
|onChange | exec on ok | Function(date: moment) | |
|onPickerChange | Date inside picker change handler. | Function(date: moment) | '' |
|onVisibleChange | called when pop picker visible change | Function | |
|onDismiss | exec on dismiss | function | |
|okText | ok button text | String | 'Ok' |
Expand Down
6 changes: 6 additions & 0 deletions examples/popup.tsx
Expand Up @@ -54,6 +54,11 @@ class Demo extends React.Component<any, any> {
date,
});
};

onPickerChange(date) {
console.log('onPickerChange', format(date));
}

onDismiss = () => {
console.log('onDismiss');
};
Expand All @@ -72,6 +77,7 @@ class Demo extends React.Component<any, any> {
maxDate={maxDate}
defaultDate={now}
mode={props.mode}
onDateChange={this.onPickerChange}
locale={props.locale}
/>
);
Expand Down
6 changes: 2 additions & 4 deletions examples/react-native/popup.tsx
Expand Up @@ -59,12 +59,11 @@ class Demo extends React.Component<any, any> {
date,
});
};

onDismiss = () => {
console.log('onDismiss');
};
onPickerChange = (date) => {
console.log('onPickerChange', format(date));
};

show = () => {
console.log('my click');
};
Expand All @@ -91,7 +90,6 @@ class Demo extends React.Component<any, any> {
styles={PopupStyles}
title="Date picker"
date={date}
onPickerChange={this.onPickerChange}
onDismiss={this.onDismiss}
onChange={this.onChange}
>
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "rmc-date-picker",
"version": "5.0.0",
"version": "5.0.1",
"description": "React Mobile DatePicker Component for web and react-native",
"keywords": [
"react",
Expand Down
20 changes: 10 additions & 10 deletions src/Popup.tsx
Expand Up @@ -44,7 +44,9 @@ export default class PopupDatePicker extends React.Component<PopupDatePickerProp
this.setState({
pickerDate,
});
this.props.onPickerChange(pickerDate);
if (this.props.datePicker.props.onDateChange) {
this.props.datePicker.props.onDateChange(pickerDate);
}
};

onOk = () => {
Expand All @@ -66,14 +68,6 @@ export default class PopupDatePicker extends React.Component<PopupDatePickerProp
this.datePicker = datePicker;
};

getModal() {
return React.cloneElement(this.props.datePicker, {
date: this.state.pickerDate || this.props.date,
onDateChange: this.onPickerChange,
ref: this.saveRef,
} as DatePickerProps);
}

fireVisibleChange = (visible) => {
if (this.state.visible !== visible) {
if (!('visible' in this.props)) {
Expand All @@ -84,11 +78,17 @@ export default class PopupDatePicker extends React.Component<PopupDatePickerProp
};

render() {
const dataPicker = React.cloneElement(this.props.datePicker, {
date: this.state.pickerDate || this.props.date,
onDateChange: this.onPickerChange,
ref: this.saveRef,
} as DatePickerProps);

return (<PopupPicker
{...this.props}
onVisibleChange={this.fireVisibleChange}
onOk={this.onOk}
content={this.getModal()}
content={dataPicker}
visible={this.state.visible}
/>);
}
Expand Down

0 comments on commit c60ea27

Please sign in to comment.