1 | import { TimePickerBase, timeProperty, minuteIntervalProperty, minuteProperty, minMinuteProperty, maxMinuteProperty, hourProperty, minHourProperty, maxHourProperty } from './time-picker-common';
|
2 | import { Color } from '../../color';
|
3 | import { colorProperty } from '../styling/style-properties';
|
4 | import { Device } from '../../platform';
|
5 | export * from './time-picker-common';
|
6 | const SUPPORT_DATE_PICKER_STYLE = __VISIONOS__ || parseFloat(Device.osVersion) >= 13.4;
|
7 | const SUPPORT_TEXT_COLOR = !__VISIONOS__ && parseFloat(Device.osVersion) < 14.0;
|
8 | function getDate(hour, minute) {
|
9 | const components = NSDateComponents.alloc().init();
|
10 | components.hour = hour;
|
11 | components.minute = minute;
|
12 | return NSCalendar.currentCalendar.dateFromComponents(components);
|
13 | }
|
14 | function getComponents(date) {
|
15 | return NSCalendar.currentCalendar.componentsFromDate(32 | 64 , date);
|
16 | }
|
17 | export class TimePicker extends TimePickerBase {
|
18 | constructor() {
|
19 | super();
|
20 | const components = getComponents(NSDate.date());
|
21 | this.hour = components.hour;
|
22 | this.minute = components.minute;
|
23 | }
|
24 | createNativeView() {
|
25 | const picker = UIDatePicker.new();
|
26 | picker.datePickerMode = 0 ;
|
27 | if (SUPPORT_DATE_PICKER_STYLE) {
|
28 | picker.preferredDatePickerStyle = this.iosPreferredDatePickerStyle;
|
29 | }
|
30 | return picker;
|
31 | }
|
32 | initNativeView() {
|
33 | super.initNativeView();
|
34 | this._changeHandler = UITimePickerChangeHandlerImpl.initWithOwner(new WeakRef(this));
|
35 | this.nativeViewProtected.addTargetActionForControlEvents(this._changeHandler, 'valueChanged', 4096 );
|
36 | }
|
37 | disposeNativeView() {
|
38 | this._changeHandler = null;
|
39 | super.disposeNativeView();
|
40 | }
|
41 |
|
42 | get ios() {
|
43 | return this.nativeViewProtected;
|
44 | }
|
45 | [timeProperty.getDefault]() {
|
46 | return this.nativeViewProtected.date;
|
47 | }
|
48 | [timeProperty.setNative](value) {
|
49 | this.nativeViewProtected.date = getDate(this.hour, this.minute);
|
50 | }
|
51 | [minuteProperty.getDefault]() {
|
52 | return this.nativeViewProtected.date.getMinutes();
|
53 | }
|
54 | [minuteProperty.setNative](value) {
|
55 | this.nativeViewProtected.date = getDate(this.hour, value);
|
56 | }
|
57 | [hourProperty.getDefault]() {
|
58 | return this.nativeViewProtected.date.getHours();
|
59 | }
|
60 | [hourProperty.setNative](value) {
|
61 | this.nativeViewProtected.date = getDate(value, this.minute);
|
62 | }
|
63 | [minHourProperty.getDefault]() {
|
64 | return this.nativeViewProtected.minimumDate ? this.nativeViewProtected.minimumDate.getHours() : 0;
|
65 | }
|
66 | [minHourProperty.setNative](value) {
|
67 | this.nativeViewProtected.minimumDate = getDate(value, this.minute);
|
68 | }
|
69 | [maxHourProperty.getDefault]() {
|
70 | return this.nativeViewProtected.maximumDate ? this.nativeViewProtected.maximumDate.getHours() : 24;
|
71 | }
|
72 | [maxHourProperty.setNative](value) {
|
73 | this.nativeViewProtected.maximumDate = getDate(value, this.minute);
|
74 | }
|
75 | [minMinuteProperty.getDefault]() {
|
76 | return this.nativeViewProtected.minimumDate ? this.nativeViewProtected.minimumDate.getMinutes() : 0;
|
77 | }
|
78 | [minMinuteProperty.setNative](value) {
|
79 | this.nativeViewProtected.minimumDate = getDate(this.hour, value);
|
80 | }
|
81 | [maxMinuteProperty.getDefault]() {
|
82 | return this.nativeViewProtected.maximumDate ? this.nativeViewProtected.maximumDate.getMinutes() : 60;
|
83 | }
|
84 | [maxMinuteProperty.setNative](value) {
|
85 | this.nativeViewProtected.maximumDate = getDate(this.hour, value);
|
86 | }
|
87 | [minuteIntervalProperty.getDefault]() {
|
88 | return this.nativeViewProtected.minuteInterval;
|
89 | }
|
90 | [minuteIntervalProperty.setNative](value) {
|
91 | this.nativeViewProtected.minuteInterval = value;
|
92 | }
|
93 | [colorProperty.getDefault]() {
|
94 | return SUPPORT_TEXT_COLOR ? this.nativeViewProtected.valueForKey('textColor') : UIColor.new();
|
95 | }
|
96 | [colorProperty.setNative](value) {
|
97 | if (SUPPORT_TEXT_COLOR) {
|
98 | const color = value instanceof Color ? value.ios : value;
|
99 | this.nativeViewProtected.setValueForKey(color, 'textColor');
|
100 | }
|
101 | }
|
102 | }
|
103 | var UITimePickerChangeHandlerImpl = (function (_super) {
|
104 | __extends(UITimePickerChangeHandlerImpl, _super);
|
105 | function UITimePickerChangeHandlerImpl() {
|
106 | return _super !== null && _super.apply(this, arguments) || this;
|
107 | }
|
108 | UITimePickerChangeHandlerImpl.initWithOwner = function (owner) {
|
109 | var handler = UITimePickerChangeHandlerImpl.new();
|
110 | handler._owner = owner;
|
111 | return handler;
|
112 | };
|
113 | UITimePickerChangeHandlerImpl.prototype.valueChanged = function (sender) {
|
114 | var _a;
|
115 | var owner = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.deref();
|
116 | if (!owner) {
|
117 | return;
|
118 | }
|
119 | var components = getComponents(sender.date);
|
120 | var timeChanged = false;
|
121 | if (components.hour !== owner.hour) {
|
122 | hourProperty.nativeValueChange(owner, components.hour);
|
123 | timeChanged = true;
|
124 | }
|
125 | if (components.minute !== owner.minute) {
|
126 | minuteProperty.nativeValueChange(owner, components.minute);
|
127 | timeChanged = true;
|
128 | }
|
129 | if (timeChanged) {
|
130 | timeProperty.nativeValueChange(owner, new Date(0, 0, 0, components.hour, components.minute));
|
131 | }
|
132 | };
|
133 | UITimePickerChangeHandlerImpl.ObjCExposedMethods = {
|
134 | valueChanged: { returns: interop.types.void, params: [UIDatePicker] },
|
135 | };
|
136 | return UITimePickerChangeHandlerImpl;
|
137 | }(NSObject));
|
138 |
|
\ | No newline at end of file |