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 ArkDatePickerComponent extends ArkComponent implements DatePickerAttribute { 18 constructor(nativePtr: KNode, classType?: ModifierType) { 19 super(nativePtr, classType); 20 } 21 lunar(value: boolean): DatePickerAttribute { 22 modifierWithKey(this._modifiersWithKeys, DatePickerLunarModifier.identity, DatePickerLunarModifier, value); 23 return this; 24 } 25 digitalCrownSensitivity(value: Optional<CrownSensitivity>): DatePickerAttribute { 26 modifierWithKey(this._modifiersWithKeys, DatePickerDigitalCrownSensitivityModifier.identity, DatePickerDigitalCrownSensitivityModifier, value); 27 return this; 28 } 29 disappearTextStyle(value: PickerTextStyle): DatePickerAttribute { 30 modifierWithKey(this._modifiersWithKeys, DatePickerDisappearTextStyleModifier.identity, 31 DatePickerDisappearTextStyleModifier, value); 32 return this; 33 } 34 textStyle(value: PickerTextStyle): DatePickerAttribute { 35 modifierWithKey(this._modifiersWithKeys, DatePickerTextStyleModifier.identity, 36 DatePickerTextStyleModifier, value); 37 return this; 38 } 39 selectedTextStyle(value: PickerTextStyle): DatePickerAttribute { 40 modifierWithKey(this._modifiersWithKeys, DatePickerSelectedTextStyleModifier.identity, 41 DatePickerSelectedTextStyleModifier, value); 42 return this; 43 } 44 onChange(callback: (value: DatePickerResult) => void): DatePickerAttribute { 45 modifierWithKey(this._modifiersWithKeys,DatePickerOnChangeModifier.identity,DatePickerOnChangeModifier,callback); 46 return this; 47 } 48 onDateChange(callback: Callback<Date>): this { 49 modifierWithKey(this._modifiersWithKeys,DatePickerOnDateChangeModifier.identity,DatePickerOnDateChangeModifier,callback); 50 return this; 51 } 52 backgroundColor(value: ResourceColor): this { 53 modifierWithKey(this._modifiersWithKeys, DatePickerBackgroundColorModifier.identity, DatePickerBackgroundColorModifier, value); 54 return this; 55 } 56 enableHapticFeedback(value: boolean): this { 57 modifierWithKey(this._modifiersWithKeys, DatePickerEnableHapticFeedbackModifier.identity, DatePickerEnableHapticFeedbackModifier, value); 58 return this; 59 } 60} 61 62class DatePickerLunarModifier extends ModifierWithKey<boolean> { 63 constructor(value: boolean) { 64 super(value); 65 } 66 static identity: Symbol = Symbol('lunar'); 67 applyPeer(node: KNode, reset: boolean) { 68 if (reset) { 69 getUINativeModule().datePicker.resetLunar(node); 70 } else { 71 getUINativeModule().datePicker.setLunar(node, this.value); 72 } 73 } 74} 75 76class DatePickerDigitalCrownSensitivityModifier extends ModifierWithKey<Optional<CrownSensitivity>> { 77 constructor(value: Optional<CrownSensitivity>) { 78 super(value); 79 } 80 static identity: Symbol = Symbol('digitalCrownSensitivity'); 81 applyPeer(node: KNode, reset: boolean) { 82 if (reset) { 83 getUINativeModule().datePicker.resetDigitalCrownSensitivity(node); 84 } else { 85 getUINativeModule().datePicker.setDigitalCrownSensitivity(node, this.value); 86 } 87 } 88} 89 90class DatePickerTextStyleModifier extends ModifierWithKey<PickerTextStyle> { 91 constructor(value: PickerTextStyle) { 92 super(value); 93 } 94 static identity: Symbol = Symbol('textStyle'); 95 applyPeer(node: KNode, reset: boolean) { 96 if (reset) { 97 getUINativeModule().datePicker.resetTextStyle(node); 98 } else { 99 getUINativeModule().datePicker.setTextStyle(node, this.value?.color ?? undefined, 100 this.value?.font?.size ?? undefined, 101 this.value?.font?.weight ?? undefined, 102 this.value?.font?.family ?? undefined, 103 this.value?.font?.style ?? undefined); 104 } 105 } 106 107 checkObjectDiff(): boolean { 108 if (!(this.stageValue?.font?.weight === this.value?.font?.weight && 109 this.stageValue?.font?.style === this.value?.font?.style)) { 110 return true; 111 } else { 112 return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) || 113 !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) || 114 !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family); 115 } 116 } 117} 118 119class DatePickerSelectedTextStyleModifier extends ModifierWithKey<PickerTextStyle> { 120 constructor(value: PickerTextStyle) { 121 super(value); 122 } 123 static identity: Symbol = Symbol('selectedTextStyle'); 124 applyPeer(node: KNode, reset: boolean) { 125 if (reset) { 126 getUINativeModule().datePicker.resetSelectedTextStyle(node); 127 } else { 128 getUINativeModule().datePicker.setSelectedTextStyle(node, this.value?.color ?? undefined, 129 this.value?.font?.size ?? undefined, 130 this.value?.font?.weight ?? undefined, 131 this.value?.font?.family ?? undefined, 132 this.value?.font?.style ?? undefined); 133 } 134 } 135 136 checkObjectDiff(): boolean { 137 if (!(this.stageValue?.font?.weight === this.value?.font?.weight && 138 this.stageValue?.font?.style === this.value?.font?.style)) { 139 return true; 140 } else { 141 return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) || 142 !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) || 143 !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family); 144 } 145 } 146} 147 148class DatePickerDisappearTextStyleModifier extends ModifierWithKey<PickerTextStyle> { 149 constructor(value: PickerTextStyle) { 150 super(value); 151 } 152 static identity: Symbol = Symbol('disappearTextStyle'); 153 applyPeer(node: KNode, reset: boolean) { 154 if (reset) { 155 getUINativeModule().datePicker.resetDisappearTextStyle(node); 156 } else { 157 getUINativeModule().datePicker.setDisappearTextStyle(node, this.value?.color ?? undefined, 158 this.value?.font?.size ?? undefined, 159 this.value?.font?.weight ?? undefined, 160 this.value?.font?.family ?? undefined, 161 this.value?.font?.style ?? undefined); 162 } 163 } 164 165 checkObjectDiff(): boolean { 166 if (!(this.stageValue?.font?.weight === this.value?.font?.weight && 167 this.stageValue?.font?.style === this.value?.font?.style)) { 168 return true; 169 } else { 170 return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) || 171 !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size) || 172 !isBaseOrResourceEqual(this.stageValue?.font?.family, this.value?.font?.family); 173 } 174 } 175} 176class DatePickerOnChangeModifier extends ModifierWithKey<(value: DatePickerResult) => void>{ 177 constructor(value: (value: DatePickerResult) => void) { 178 super(value); 179 } 180 static identity: Symbol = Symbol('datePickerOnChange'); 181 applyPeer(node: KNode, reset: boolean): void { 182 if (reset) { 183 getUINativeModule().datePicker.resetDatePickerOnChange(node); 184 } else { 185 getUINativeModule().datePicker.setDatePickerOnChange(node, this.value); 186 } 187 } 188} 189class DatePickerOnDateChangeModifier extends ModifierWithKey<Callback<Date>>{ 190 constructor(value: Callback<Date>) { 191 super(value); 192 } 193 static identity: Symbol = Symbol('datePickerOnDateChange'); 194 applyPeer(node: KNode, reset: boolean): void { 195 if (reset) { 196 getUINativeModule().datePicker.resetDatePickerOnDateChange(node); 197 } else { 198 getUINativeModule().datePicker.setDatePickerOnDateChange(node, this.value); 199 } 200 } 201} 202 203class DatePickerBackgroundColorModifier extends ModifierWithKey<ResourceColor> { 204 constructor(value: ResourceColor) { 205 super(value); 206 } 207 static identity: Symbol = Symbol('datePickerBackgroundColor'); 208 applyPeer(node: KNode, reset: boolean): void { 209 if (reset) { 210 getUINativeModule().datePicker.resetBackgroundColor(node); 211 } else { 212 getUINativeModule().datePicker.setBackgroundColor(node, this.value); 213 } 214 } 215 216 checkObjectDiff(): boolean { 217 return !isBaseOrResourceEqual(this.stageValue, this.value); 218 } 219} 220class DatePickerEnableHapticFeedbackModifier extends ModifierWithKey<boolean> { 221 constructor(value: boolean) { 222 super(value); 223 } 224 static identity: Symbol = Symbol('datePickerEnableHapticFeedback'); 225 applyPeer(node: KNode, reset: boolean): void { 226 if (reset) { 227 getUINativeModule().datePicker.resetEnableHapticFeedback(node); 228 } else { 229 getUINativeModule().datePicker.setEnableHapticFeedback(node, this.value); 230 } 231 } 232} 233 234//@ts-ignore 235globalThis.DatePicker.attributeModifier = function (modifier: ArkComponent): void { 236 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 237 return new ArkDatePickerComponent(nativePtr); 238 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 239 return new modifierJS.DatePickerModifier(nativePtr, classType); 240 }); 241}; 242