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 TextStyleModifier extends ModifierWithKey<PickerTextStyle> { 18 constructor(value: PickerTextStyle) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('textStyle'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().calendarPicker.resetTextStyle(node); 25 } else { 26 getUINativeModule().calendarPicker.setTextStyle(node, 27 this.value?.color ?? undefined, 28 this.value?.font?.size ?? undefined, 29 this.value?.font?.weight ?? undefined); 30 } 31 } 32 33 checkObjectDiff(): boolean { 34 if (!(this.stageValue?.font?.weight === this.value?.font?.weight)) { 35 return true; 36 } else { 37 return !isBaseOrResourceEqual(this.stageValue?.color, this.value?.color) || 38 !isBaseOrResourceEqual(this.stageValue?.font?.size, this.value?.font?.size); 39 } 40 } 41} 42 43class EdgeAlignModifier extends ModifierWithKey<ArkEdgeAlign> { 44 constructor(value: ArkEdgeAlign) { 45 super(value); 46 } 47 static identity: Symbol = Symbol('edgeAlign'); 48 applyPeer(node: KNode, reset: boolean): void { 49 if (reset) { 50 getUINativeModule().calendarPicker.resetEdgeAlign(node); 51 } else { 52 getUINativeModule().calendarPicker.setEdgeAlign(node, 53 this.value?.alignType ?? undefined, 54 this.value?.offset?.dx ?? undefined, 55 this.value?.offset?.dy ?? undefined); 56 } 57 } 58 59 checkObjectDiff(): boolean { 60 if (!(this.stageValue.alignType === this.value.alignType)) { 61 return true; 62 } else { 63 return !isBaseOrResourceEqual(this.stageValue?.offset?.dx, this.value?.offset?.dx) || 64 !isBaseOrResourceEqual(this.stageValue?.offset?.dy, this.value?.offset?.dy); 65 } 66 } 67} 68 69class CalendarPickerPaddingModifier extends ModifierWithKey<ArkPadding> { 70 constructor(value: ArkPadding) { 71 super(value); 72 } 73 static identity: Symbol = Symbol('calendarPickerPadding'); 74 applyPeer(node: KNode, reset: boolean): void { 75 if (reset) { 76 getUINativeModule().calendarPicker.resetCalendarPickerPadding(node); 77 } else { 78 getUINativeModule().calendarPicker.setCalendarPickerPadding(node, this.value.top, 79 this.value.right, this.value.bottom, this.value.left); 80 } 81 } 82 83 checkObjectDiff(): boolean { 84 return !isBaseOrResourceEqual(this.stageValue.top, this.value.top) || 85 !isBaseOrResourceEqual(this.stageValue.right, this.value.right) || 86 !isBaseOrResourceEqual(this.stageValue.bottom, this.value.bottom) || 87 !isBaseOrResourceEqual(this.stageValue.left, this.value.left); 88 } 89} 90 91class CalendarPickerBorderModifier extends ModifierWithKey<ArkBorder> { 92 constructor(value: ArkBorder) { 93 super(value); 94 } 95 static identity: Symbol = Symbol('calendarPickerBorder'); 96 applyPeer(node: KNode, reset: boolean): void { 97 if (reset) { 98 getUINativeModule().calendarPicker.resetCalendarPickerBorder(node); 99 } else { 100 getUINativeModule().calendarPicker.setCalendarPickerBorder(node, 101 this.value.arkWidth.left, this.value.arkWidth.right, this.value.arkWidth.top, this.value.arkWidth.bottom, 102 this.value.arkColor.leftColor, this.value.arkColor.rightColor, this.value.arkColor.topColor, this.value.arkColor.bottomColor, 103 this.value.arkRadius.topLeft, this.value.arkRadius.topRight, this.value.arkRadius.bottomLeft, this.value.arkRadius.bottomRight, 104 this.value.arkStyle.top, this.value.arkStyle.right, this.value.arkStyle.bottom, this.value.arkStyle.left); 105 } 106 } 107 108 checkObjectDiff(): boolean { 109 return this.value.checkObjectDiff(this.stageValue); 110 } 111} 112 113class CalendarPickerHeightModifier extends ModifierWithKey<Length> { 114 constructor(value: Length) { 115 super(value); 116 } 117 static identity: Symbol = Symbol('calendarPickerHeight'); 118 applyPeer(node: KNode, reset: boolean): void { 119 if (reset) { 120 getUINativeModule().calendarPicker.resetCalendarPickerHeight(node); 121 } else { 122 getUINativeModule().calendarPicker.setCalendarPickerHeight(node, this.value); 123 } 124 } 125 126 checkObjectDiff(): boolean { 127 return !isBaseOrResourceEqual(this.stageValue, this.value); 128 } 129} 130 131class CalendarPickerBorderRadiusModifier extends ModifierWithKey<Length | BorderRadiuses | LocalizedBorderRadius> { 132 constructor(value: Length | BorderRadiuses | LocalizedBorderRadius) { 133 super(value); 134 } 135 static identity: Symbol = Symbol('calendarPickerBorderRadius'); 136 applyPeer(node: KNode, reset: boolean): void { 137 if (reset) { 138 getUINativeModule().calendarPicker.resetCalendarPickerBorderRadius(node); 139 } else { 140 if (isNumber(this.value) || isString(this.value) || isResource(this.value)) { 141 getUINativeModule().calendarPicker.setCalendarPickerBorderRadius(node, this.value, this.value, this.value, this.value); 142 } else { 143 if ((Object.keys(this.value).indexOf('topStart') >= 0) || 144 (Object.keys(this.value).indexOf('topEnd') >= 0) || 145 (Object.keys(this.value).indexOf('bottomStart') >= 0) || 146 (Object.keys(this.value).indexOf('bottomEnd') >= 0)) { 147 getUINativeModule().calendarPicker.setCalendarPickerBorderRadius(node, 148 (this.value as LocalizedBorderRadius).topStart, 149 (this.value as LocalizedBorderRadius).topEnd, 150 (this.value as LocalizedBorderRadius).bottomStart, 151 (this.value as LocalizedBorderRadius).bottomEnd); 152 } else { 153 getUINativeModule().calendarPicker.setCalendarPickerBorderRadius(node, 154 (this.value as BorderRadiuses).topLeft, 155 (this.value as BorderRadiuses).topRight, 156 (this.value as BorderRadiuses).bottomLeft, 157 (this.value as BorderRadiuses).bottomRight); 158 } 159 } 160 } 161 } 162 163 checkObjectDiff(): boolean { 164 if (isResource(this.stageValue) && isResource(this.value)) { 165 return !isResourceEqual(this.stageValue, this.value); 166 } else if (!isResource(this.stageValue) && !isResource(this.value)) { 167 if ((Object.keys(this.value).indexOf('topStart') >= 0) || 168 (Object.keys(this.value).indexOf('topEnd') >= 0) || 169 (Object.keys(this.value).indexOf('bottomStart') >= 0) || 170 (Object.keys(this.value).indexOf('bottomEnd') >= 0)) { 171 return !((this.stageValue as LocalizedBorderRadius).topStart === (this.value as LocalizedBorderRadius).topStart && 172 (this.stageValue as LocalizedBorderRadius).topEnd === (this.value as LocalizedBorderRadius).topEnd && 173 (this.stageValue as LocalizedBorderRadius).bottomStart === (this.value as LocalizedBorderRadius).bottomStart && 174 (this.stageValue as LocalizedBorderRadius).bottomEnd === (this.value as LocalizedBorderRadius).bottomEnd); 175 } 176 return !((this.stageValue as BorderRadiuses).topLeft === (this.value as BorderRadiuses).topLeft && 177 (this.stageValue as BorderRadiuses).topRight === (this.value as BorderRadiuses).topRight && 178 (this.stageValue as BorderRadiuses).bottomLeft === (this.value as BorderRadiuses).bottomLeft && 179 (this.stageValue as BorderRadiuses).bottomRight === (this.value as BorderRadiuses).bottomRight); 180 } else { 181 return true; 182 } 183 } 184} 185 186class CalendarPickerBorderColorModifier extends ModifierWithKey<ResourceColor | EdgeColors | LocalizedEdgeColors> { 187 constructor(value: ResourceColor | EdgeColors | LocalizedEdgeColors) { 188 super(value); 189 } 190 static identity: Symbol = Symbol('calendarPickerBorderColor'); 191 applyPeer(node: KNode, reset: boolean): void { 192 if (reset) { 193 getUINativeModule().calendarPicker.resetCalendarPickerBorderColor(node); 194 } else { 195 const valueType: string = typeof this.value; 196 if (valueType === 'number' || valueType === 'string' || isResource(this.value)) { 197 getUINativeModule().calendarPicker.setCalendarPickerBorderColor(node, this.value, this.value, this.value, this.value); 198 } else { 199 if ((Object.keys(this.value).indexOf('start') >= 0) || 200 (Object.keys(this.value).indexOf('end') >= 0)) { 201 getUINativeModule().calendarPicker.setCalendarPickerBorderColor(node, 202 (this.value as LocalizedEdgeColors).top, 203 (this.value as LocalizedEdgeColors).end, 204 (this.value as LocalizedEdgeColors).bottom, 205 (this.value as LocalizedEdgeColors).start, 206 true); 207 } else { 208 getUINativeModule().calendarPicker.setCalendarPickerBorderColor(node, 209 (this.value as EdgeColors).top, 210 (this.value as EdgeColors).right, 211 (this.value as EdgeColors).bottom, 212 (this.value as EdgeColors).left, 213 false); 214 } 215 } 216 217 } 218 } 219 220 checkObjectDiff(): boolean { 221 if (isResource(this.stageValue) && isResource(this.value)) { 222 return !isResourceEqual(this.stageValue, this.value); 223 } else if (!isResource(this.stageValue) && !isResource(this.value)) { 224 if ((Object.keys(this.value).indexOf('start') >= 0) || 225 (Object.keys(this.value).indexOf('end') >= 0)) { 226 return !((this.stageValue as LocalizedEdgeColors).start === (this.value as LocalizedEdgeColors).start && 227 (this.stageValue as LocalizedEdgeColors).end === (this.value as LocalizedEdgeColors).end && 228 (this.stageValue as LocalizedEdgeColors).top === (this.value as LocalizedEdgeColors).top && 229 (this.stageValue as LocalizedEdgeColors).bottom === (this.value as LocalizedEdgeColors).bottom); 230 } 231 return !((this.stageValue as EdgeColors).left === (this.value as EdgeColors).left && 232 (this.stageValue as EdgeColors).right === (this.value as EdgeColors).right && 233 (this.stageValue as EdgeColors).top === (this.value as EdgeColors).top && 234 (this.stageValue as EdgeColors).bottom === (this.value as EdgeColors).bottom); 235 } else { 236 return true; 237 } 238 } 239} 240 241class ArkCalendarPickerComponent extends ArkComponent implements CalendarPickerAttribute { 242 constructor(nativePtr: KNode, classType?: ModifierType) { 243 super(nativePtr, classType); 244 } 245 edgeAlign(alignType: CalendarAlign, offset?: Offset | undefined): this { 246 let arkEdgeAlign = new ArkEdgeAlign(); 247 arkEdgeAlign.alignType = alignType; 248 arkEdgeAlign.offset = offset; 249 modifierWithKey(this._modifiersWithKeys, EdgeAlignModifier.identity, EdgeAlignModifier, arkEdgeAlign); 250 return this; 251 } 252 textStyle(value: PickerTextStyle): this { 253 modifierWithKey(this._modifiersWithKeys, TextStyleModifier.identity, TextStyleModifier, value); 254 return this; 255 } 256 onChange(callback: (value: Date) => void): this { 257 throw new Error('Method not implemented.'); 258 } 259 padding(value: Padding | Length): this { 260 let arkValue = new ArkPadding(); 261 if (value !== null && value !== undefined) { 262 if (isLengthType(value) || isResource(value)) { 263 arkValue.top = <Length>value; 264 arkValue.right = <Length>value; 265 arkValue.bottom = <Length>value; 266 arkValue.left = <Length>value; 267 } else { 268 arkValue.top = (<Margin>value).top; 269 arkValue.right = (<Margin>value).right; 270 arkValue.bottom = (<Margin>value).bottom; 271 arkValue.left = (<Margin>value).left; 272 } 273 modifierWithKey(this._modifiersWithKeys, CalendarPickerPaddingModifier.identity, 274 CalendarPickerPaddingModifier, arkValue); 275 } else { 276 modifierWithKey(this._modifiersWithKeys, CalendarPickerPaddingModifier.identity, 277 CalendarPickerPaddingModifier, undefined); 278 } 279 return this; 280 } 281 border(value: BorderOptions): this { 282 let arkBorder = new ArkBorder(); 283 if (isUndefined(value)) { 284 arkBorder = undefined; 285 } 286 287 if (!isUndefined(value?.width) && value?.width !== null) { 288 if (isNumber(value.width) || isString(value.width) || isResource(value.width)) { 289 arkBorder.arkWidth.left = value.width; 290 arkBorder.arkWidth.right = value.width; 291 arkBorder.arkWidth.top = value.width; 292 arkBorder.arkWidth.bottom = value.width; 293 } else { 294 arkBorder.arkWidth.left = (value.width as EdgeWidths).left; 295 arkBorder.arkWidth.right = (value.width as EdgeWidths).right; 296 arkBorder.arkWidth.top = (value.width as EdgeWidths).top; 297 arkBorder.arkWidth.bottom = (value.width as EdgeWidths).bottom; 298 } 299 } 300 if (!isUndefined(value?.color) && value?.color !== null) { 301 if (isNumber(value.color) || isString(value.color) || isResource(value.color)) { 302 arkBorder.arkColor.leftColor = value.color; 303 arkBorder.arkColor.rightColor = value.color; 304 arkBorder.arkColor.topColor = value.color; 305 arkBorder.arkColor.bottomColor = value.color; 306 } else { 307 arkBorder.arkColor.leftColor = (value.color as EdgeColors).left; 308 arkBorder.arkColor.rightColor = (value.color as EdgeColors).right; 309 arkBorder.arkColor.topColor = (value.color as EdgeColors).top; 310 arkBorder.arkColor.bottomColor = (value.color as EdgeColors).bottom; 311 } 312 } 313 if (!isUndefined(value?.radius) && value?.radius !== null) { 314 if (isNumber(value.radius) || isString(value.radius) || isResource(value.radius)) { 315 arkBorder.arkRadius.topLeft = value.radius; 316 arkBorder.arkRadius.topRight = value.radius; 317 arkBorder.arkRadius.bottomLeft = value.radius; 318 arkBorder.arkRadius.bottomRight = value.radius; 319 } else { 320 arkBorder.arkRadius.topLeft = (value.radius as BorderRadiuses)?.topLeft; 321 arkBorder.arkRadius.topRight = (value.radius as BorderRadiuses)?.topRight; 322 arkBorder.arkRadius.bottomLeft = (value.radius as BorderRadiuses)?.bottomLeft; 323 arkBorder.arkRadius.bottomRight = (value.radius as BorderRadiuses)?.bottomRight; 324 } 325 } 326 if (!isUndefined(value?.style) && value?.style !== null) { 327 let arkBorderStyle = new ArkBorderStyle(); 328 if (arkBorderStyle.parseBorderStyle(value.style)) { 329 if (!isUndefined(arkBorderStyle.style)) { 330 arkBorder.arkStyle.top = arkBorderStyle.style; 331 arkBorder.arkStyle.left = arkBorderStyle.style; 332 arkBorder.arkStyle.bottom = arkBorderStyle.style; 333 arkBorder.arkStyle.right = arkBorderStyle.style; 334 } else { 335 arkBorder.arkStyle.top = arkBorderStyle.top; 336 arkBorder.arkStyle.left = arkBorderStyle.left; 337 arkBorder.arkStyle.bottom = arkBorderStyle.bottom; 338 arkBorder.arkStyle.right = arkBorderStyle.right; 339 } 340 } 341 } 342 modifierWithKey(this._modifiersWithKeys, CalendarPickerBorderModifier.identity, CalendarPickerBorderModifier, arkBorder); 343 return this; 344 } 345 height(value: Length): this { 346 modifierWithKey(this._modifiersWithKeys, CalendarPickerHeightModifier.identity, CalendarPickerHeightModifier, value); 347 return this; 348 } 349 borderRadius(value: Length | BorderRadiuses): this { 350 modifierWithKey(this._modifiersWithKeys, CalendarPickerBorderRadiusModifier.identity, CalendarPickerBorderRadiusModifier, value); 351 return this; 352 } 353 borderColor(value: ResourceColor | EdgeColors): this { 354 modifierWithKey(this._modifiersWithKeys, CalendarPickerBorderColorModifier.identity, CalendarPickerBorderColorModifier, value); 355 return this; 356 } 357} 358// @ts-ignore 359globalThis.CalendarPicker.attributeModifier = function (modifier: ArkComponent): void { 360 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 361 return new ArkCalendarPickerComponent(nativePtr); 362 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 363 return new modifierJS.CalendarPickerModifier(nativePtr, classType); 364 }); 365}; 366