secullum-react-native-ui 4.16.2-beta.3 → 4.16.2-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,10 +17,10 @@ export interface RangeDatePickerState {
17
17
  showStartDateModal: boolean;
18
18
  count: number;
19
19
  }
20
- export declare class RangeDatePicker extends React.PureComponent<RangeDatePickerProperties, RangeDatePickerState> {
20
+ export declare class RangeDatePicker extends React.Component<RangeDatePickerProperties, RangeDatePickerState> {
21
21
  state: RangeDatePickerState;
22
22
  private calendarRef;
23
- componentWillMount(): void;
23
+ componentDidMount(): void;
24
24
  componentWillUnmount(): void;
25
25
  handleClick: (event: MouseEvent) => void;
26
26
  handleDatePickerPress: () => void;
@@ -11,7 +11,39 @@ const layout_1 = require("../modules/layout");
11
11
  require("react-date-range/dist/styles.css");
12
12
  const react_native_1 = require("react-native");
13
13
  require("../../styles/RangeDatePicker.css");
14
- class RangeDatePicker extends React.PureComponent {
14
+ function compareDates(date1, date2) {
15
+ if (date1 instanceof Date && date2 instanceof Date) {
16
+ return date1.getTime() === date2.getTime();
17
+ }
18
+ return date1 === date2;
19
+ }
20
+ class PureDateRange extends React.Component {
21
+ // Without this check, every time the parent re-renders it would
22
+ // recreate the DateRange with the initial startDate value,
23
+ // even if the date hasn't actually changed.
24
+ // This causes the calendar to reset and the user loses the current
25
+ // selection while interacting.
26
+ // Related issue on GitLab 12293
27
+ shouldComponentUpdate(nextProps) {
28
+ if (nextProps.onChange !== this.props.onChange) {
29
+ return true;
30
+ }
31
+ return (!compareDates(nextProps.startDate, this.props.startDate) ||
32
+ !compareDates(nextProps.endDate, this.props.endDate));
33
+ }
34
+ render() {
35
+ const { startDate, endDate, onChange } = this.props;
36
+ const theme = (0, theme_1.getTheme)();
37
+ return (React.createElement(react_date_range_1.DateRange, { locale: (0, format_1.getDateFnsLocale)(), showDateDisplay: false, ranges: [
38
+ {
39
+ startDate,
40
+ endDate,
41
+ key: 'selection'
42
+ }
43
+ ], rangeColors: [theme.backgroundColor3], onChange: onChange, weekdayDisplayFormat: (0, format_1.getLocale)() === 'pt' ? 'EEEEEE' : 'E' }));
44
+ }
45
+ }
46
+ class RangeDatePicker extends React.Component {
15
47
  constructor() {
16
48
  super(...arguments);
17
49
  this.state = {
@@ -79,7 +111,7 @@ class RangeDatePicker extends React.PureComponent {
79
111
  return styles;
80
112
  };
81
113
  }
82
- componentWillMount() {
114
+ componentDidMount() {
83
115
  document.addEventListener('mousedown', this.handleClick, false);
84
116
  }
85
117
  componentWillUnmount() {
@@ -108,13 +140,7 @@ class RangeDatePicker extends React.PureComponent {
108
140
  marginTop: '-150px',
109
141
  fontFamily: theme.fontFamily1
110
142
  } },
111
- React.createElement(react_date_range_1.DateRange, { locale: (0, format_1.getDateFnsLocale)(), showDateDisplay: false, ranges: [
112
- {
113
- startDate: startDate,
114
- endDate: endDate,
115
- key: 'selection'
116
- }
117
- ], rangeColors: [theme.backgroundColor3], onChange: this.handleRangeDateConfirm, weekdayDisplayFormat: (0, format_1.getLocale)() === 'pt' ? 'EEEEEE' : 'E' }))))));
143
+ React.createElement(PureDateRange, { startDate: startDate, endDate: endDate, onChange: this.handleRangeDateConfirm }))))));
118
144
  }
119
145
  }
120
146
  exports.RangeDatePicker = RangeDatePicker;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "secullum-react-native-ui",
3
- "version": "4.16.2-beta.3",
3
+ "version": "4.16.2-beta.5",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "files": [