1 | import { DatePickerBase, yearProperty, monthProperty, dayProperty, dateProperty, maxDateProperty, minDateProperty } from './date-picker-common';
|
2 | import { TimePicker } from '../time-picker';
|
3 | export * from './date-picker-common';
|
4 | let DateChangedListener;
|
5 | function initializeDateChangedListener() {
|
6 | if (DateChangedListener) {
|
7 | return;
|
8 | }
|
9 | var DateChangedListenerImpl = (function (_super) {
|
10 | __extends(DateChangedListenerImpl, _super);
|
11 | function DateChangedListenerImpl(owner) {
|
12 | var _this = _super.call(this) || this;
|
13 | _this.owner = owner;
|
14 | return global.__native(_this);
|
15 | }
|
16 | DateChangedListenerImpl.prototype.onDateChanged = function (picker, year, month, day) {
|
17 | var owner = this.owner;
|
18 | var dateChanged = false;
|
19 | if (year !== owner.year) {
|
20 | yearProperty.nativeValueChange(owner, year);
|
21 | dateChanged = true;
|
22 | }
|
23 | if (month !== owner.month - 1) {
|
24 | monthProperty.nativeValueChange(owner, month + 1);
|
25 | dateChanged = true;
|
26 | }
|
27 | if (day !== owner.day) {
|
28 | dayProperty.nativeValueChange(owner, day);
|
29 | dateChanged = true;
|
30 | }
|
31 | if (dateChanged || (owner.showTime && owner.timePicker)) {
|
32 | var newDate = void 0;
|
33 | if (owner.showTime && owner.timePicker) {
|
34 | var dateTime = owner.timePicker.time;
|
35 | newDate = new Date(year, month, day, dateTime.getHours(), dateTime.getMinutes(), dateTime.getSeconds(), dateTime.getMilliseconds());
|
36 | }
|
37 | else {
|
38 | newDate = new Date(year, month, day);
|
39 | }
|
40 | dateProperty.nativeValueChange(owner, newDate);
|
41 | }
|
42 | };
|
43 | var _a;
|
44 | DateChangedListenerImpl = __decorate([
|
45 | Interfaces([android.widget.DatePicker.OnDateChangedListener]),
|
46 | __metadata("design:paramtypes", [typeof (_a = typeof DatePicker !== "undefined" && DatePicker) === "function" ? _a : Object])
|
47 | ], DateChangedListenerImpl);
|
48 | return DateChangedListenerImpl;
|
49 | }(java.lang.Object));
|
50 | DateChangedListener = DateChangedListenerImpl;
|
51 | }
|
52 | export class DatePicker extends DatePickerBase {
|
53 | createNativeView() {
|
54 | const picker = new android.widget.DatePicker(this._context);
|
55 | picker.setCalendarViewShown(false);
|
56 | return picker;
|
57 | }
|
58 | initNativeView() {
|
59 | super.initNativeView();
|
60 | initializeDateChangedListener();
|
61 | const nativeView = this.nativeViewProtected;
|
62 | const listener = new DateChangedListener(this);
|
63 | nativeView.init(this.year, this.month - 1, this.day, listener);
|
64 | nativeView.listener = listener;
|
65 | if (this.showTime) {
|
66 | this.timePicker = new TimePicker();
|
67 | this.timePicker.width = this.width;
|
68 | this.timePicker.height = this.height;
|
69 | this.timePicker.on('timeChange', (args) => {
|
70 | this.updateNativeDate();
|
71 | });
|
72 | this.parent.addChild(this.timePicker);
|
73 | }
|
74 | }
|
75 | disposeNativeView() {
|
76 | if (this.timePicker) {
|
77 | this.timePicker.disposeNativeView();
|
78 | }
|
79 | if (this.nativeViewProtected?.listener) {
|
80 | this.nativeViewProtected.listener.owner = null;
|
81 | }
|
82 | super.disposeNativeView();
|
83 | }
|
84 | updateNativeDate() {
|
85 | const nativeView = this.nativeViewProtected;
|
86 | const year = typeof this.year === 'number' ? this.year : nativeView.getYear();
|
87 | const month = typeof this.month === 'number' ? this.month - 1 : nativeView.getMonth();
|
88 | const day = typeof this.day === 'number' ? this.day : nativeView.getDayOfMonth();
|
89 | if (this.showTime && this.timePicker) {
|
90 | const time = this.timePicker.time || new Date();
|
91 | this.date = new Date(year, month, day, time.getHours(), time.getMinutes(), time.getSeconds(), time.getMilliseconds());
|
92 | }
|
93 | else {
|
94 | this.date = new Date(year, month, day);
|
95 | }
|
96 | }
|
97 | [yearProperty.setNative](value) {
|
98 | if (this.nativeViewProtected.getYear() !== value) {
|
99 | this.updateNativeDate();
|
100 | }
|
101 | }
|
102 | [monthProperty.setNative](value) {
|
103 | if (this.nativeViewProtected.getMonth() !== value - 1) {
|
104 | this.updateNativeDate();
|
105 | }
|
106 | }
|
107 | [dayProperty.setNative](value) {
|
108 | if (this.nativeViewProtected.getDayOfMonth() !== value) {
|
109 | this.updateNativeDate();
|
110 | }
|
111 | }
|
112 | [dateProperty.setNative](value) {
|
113 | const nativeView = this.nativeViewProtected;
|
114 | if (value && (nativeView.getDayOfMonth() !== value.getDate() || nativeView.getMonth() !== value.getMonth() || nativeView.getYear() !== value.getFullYear())) {
|
115 | nativeView.updateDate(value.getFullYear(), value.getMonth(), value.getDate());
|
116 | }
|
117 | }
|
118 | [maxDateProperty.getDefault]() {
|
119 | return this.nativeViewProtected.getMaxDate();
|
120 | }
|
121 | [maxDateProperty.setNative](value) {
|
122 | const newValue = value instanceof Date ? value.getTime() : value;
|
123 | this.nativeViewProtected.setMaxDate(newValue);
|
124 | }
|
125 | [minDateProperty.getDefault]() {
|
126 | return this.nativeViewProtected.getMinDate();
|
127 | }
|
128 | [minDateProperty.setNative](value) {
|
129 | const newValue = value instanceof Date ? value.getTime() : value;
|
130 | this.nativeViewProtected.setMinDate(newValue);
|
131 | }
|
132 | }
|
133 |
|
\ | No newline at end of file |