1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/// <reference path='./import.ts' /> 17class ArkTimePickerComponent extends ArkComponent implements TimePickerAttribute { 18 constructor(nativePtr: KNode, classType?: ModifierType) { 19 super(nativePtr, classType); 20 } 21 loop(value: boolean): this { 22 modifierWithKey(this._modifiersWithKeys, TimepickerLoopModifier.identity, TimepickerLoopModifier, value); 23 return this; 24 } 25 useMilitaryTime(value: boolean): this { 26 modifierWithKey(this._modifiersWithKeys, TimepickerUseMilitaryTimeModifier.identity, 27 TimepickerUseMilitaryTimeModifier, value); 28 return this; 29 } 30 disappearTextStyle(value: PickerTextStyle): this { 31 modifierWithKey(this._modifiersWithKeys, TimepickerDisappearTextStyleModifier.identity, 32 TimepickerDisappearTextStyleModifier, value); 33 return this; 34 } 35 textStyle(value: PickerTextStyle): this { 36 modifierWithKey(this._modifiersWithKeys, TimepickerTextStyleModifier.identity, 37 TimepickerTextStyleModifier, value); 38 return this; 39 } 40 selectedTextStyle(value: PickerTextStyle): this { 41 modifierWithKey(this._modifiersWithKeys, TimepickerSelectedTextStyleModifier.identity, 42 TimepickerSelectedTextStyleModifier, value); 43 return this; 44 } 45 onChange(callback: (value: TimePickerResult) => void): this { 46 throw new Error('Method not implemented.'); 47 } 48 dateTimeOptions(value: DateTimeOptions): this { 49 modifierWithKey(this._modifiersWithKeys, TimepickerDateTimeOptionsModifier.identity, 50 TimepickerDateTimeOptionsModifier, value); 51 return this; 52 } 53} 54 55class TimepickerTextStyleModifier extends ModifierWithKey<PickerTextStyle> { 56 constructor(value: PickerTextStyle) { 57 super(value); 58 } 59 static identity: Symbol = Symbol('textStyle'); 60 61 applyPeer(node: KNode, reset: boolean): void { 62 if (reset) { 63 getUINativeModule().timepicker.resetTextStyle(node); 64 } else { 65 getUINativeModule().timepicker.setTextStyle(node, this.value?.color ?? undefined, 66 this.value?.font?.size ?? undefined, 67 this.value?.font?.weight ?? undefined, 68 this.value?.font?.family ?? undefined, 69 this.value?.font?.style ?? undefined); 70 } 71 } 72 73 checkObjectDiff(): boolean { 74 if (!(this.stageValue?.font?.weight === this.value?.font?.weight && 75 this.stageValue?.font?.style === this.value?.font?.style)) { 76 return true; 77 } else { 78 return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) || 79 !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) || 80 !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family); 81 } 82 } 83} 84 85class TimepickerSelectedTextStyleModifier extends ModifierWithKey<PickerTextStyle> { 86 constructor(value: PickerTextStyle) { 87 super(value); 88 } 89 static identity: Symbol = Symbol('selectedTextStyle'); 90 91 applyPeer(node: KNode, reset: boolean): void { 92 if (reset) { 93 getUINativeModule().timepicker.resetSelectedTextStyle(node); 94 } else { 95 getUINativeModule().timepicker.setSelectedTextStyle(node, this.value?.color ?? undefined, 96 this.value?.font?.size ?? undefined, 97 this.value?.font?.weight ?? undefined, 98 this.value?.font?.family ?? undefined, 99 this.value?.font?.style ?? undefined); 100 } 101 } 102 103 checkObjectDiff(): boolean { 104 if (!(this.stageValue?.font?.weight === this.value?.font?.weight && 105 this.stageValue?.font?.style === this.value?.font?.style)) { 106 return true; 107 } else { 108 return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) || 109 !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) || 110 !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family); 111 } 112 } 113} 114 115class TimepickerDisappearTextStyleModifier extends ModifierWithKey<PickerTextStyle> { 116 constructor(value: PickerTextStyle) { 117 super(value); 118 } 119 static identity: Symbol = Symbol('disappearTextStyle'); 120 121 applyPeer(node: KNode, reset: boolean): void { 122 if (reset) { 123 getUINativeModule().timepicker.resetDisappearTextStyle(node); 124 } else { 125 getUINativeModule().timepicker.setDisappearTextStyle(node, this.value?.color ?? undefined, 126 this.value?.font?.size ?? undefined, 127 this.value?.font?.weight ?? undefined, 128 this.value?.font?.family ?? undefined, 129 this.value?.font?.style ?? undefined); 130 } 131 } 132 133 checkObjectDiff(): boolean { 134 if (!(this.stageValue?.font?.weight === this.value?.font?.weight && 135 this.stageValue?.font?.style === this.value?.font?.style)) { 136 return true; 137 } else { 138 return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) || 139 !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) || 140 !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family); 141 } 142 } 143} 144 145class TimepickerUseMilitaryTimeModifier extends ModifierWithKey<boolean> { 146 constructor(value: boolean) { 147 super(value); 148 } 149 static identity: Symbol = Symbol('timepickerUseMilitaryTime'); 150 applyPeer(node: KNode, reset: boolean): void { 151 if (reset) { 152 getUINativeModule().timepicker.resetTimepickerUseMilitaryTime(node); 153 } else { 154 getUINativeModule().timepicker.setTimepickerUseMilitaryTime(node, this.value); 155 } 156 } 157} 158 159class TimepickerLoopModifier extends ModifierWithKey<boolean> { 160 constructor(value: boolean) { 161 super(value); 162 } 163 static identity: Symbol = Symbol('timepickerLoop'); 164 applyPeer(node: KNode, reset: boolean): void { 165 if (reset) { 166 getUINativeModule().timepicker.resetTimepickerLoop(node); 167 } else { 168 getUINativeModule().timepicker.setTimepickerLoop(node, this.value); 169 } 170 } 171} 172 173class TimepickerDateTimeOptionsModifier extends ModifierWithKey<DateTimeOptions> { 174 constructor(value: DateTimeOptions) { 175 super(value); 176 } 177 static identity: Symbol = Symbol('timepickerDateTimeOptions'); 178 applyPeer(node: KNode, reset: boolean): void { 179 if (reset) { 180 getUINativeModule().timepicker.resetTimepickerDateTimeOptions(node); 181 } else { 182 getUINativeModule().timepicker.setTimepickerDateTimeOptions(node, this.value.hour, this.value.minute, this.value.second); 183 } 184 } 185} 186 187// @ts-ignore 188globalThis.TimePicker.attributeModifier = function (modifier: ArkComponent): void { 189 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 190 return new ArkTimePickerComponent(nativePtr); 191 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 192 return new modifierJS.TimePickerModifier(nativePtr, classType); 193 }); 194}; 195