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 ArkTextClockComponent extends ArkComponent implements TextClockAttribute { 18 constructor(nativePtr: KNode) { 19 super(nativePtr); 20 } 21 format(value: string): this { 22 modifierWithKey(this._modifiersWithKeys, TextClockFormatModifier.identity, TextClockFormatModifier, value); 23 return this; 24 } 25 onDateChange(event: (value: number) => void): this { 26 throw new Error('Method not implemented.'); 27 } 28 fontColor(value: ResourceColor): this { 29 modifierWithKey(this._modifiersWithKeys, TextClockFontColorModifier.identity, TextClockFontColorModifier, value); 30 return this; 31 } 32 fontSize(value: Length): this { 33 modifierWithKey(this._modifiersWithKeys, TextClockFontSizeModifier.identity, TextClockFontSizeModifier, value); 34 return this; 35 } 36 fontStyle(value: FontStyle): this { 37 modifierWithKey(this._modifiersWithKeys, TextClockFontStyleModifier.identity, TextClockFontStyleModifier, value); 38 return this; 39 } 40 fontWeight(value: string | number | FontWeight): this { 41 modifierWithKey(this._modifiersWithKeys, TextClockFontWeightModifier.identity, TextClockFontWeightModifier, value); 42 return this; 43 } 44 fontFamily(value: ResourceStr): this { 45 modifierWithKey(this._modifiersWithKeys, TextClockFontFamilyModifier.identity, TextClockFontFamilyModifier, value); 46 return this; 47 } 48 textShadow(value: ShadowOptions): this { 49 throw new Error('Method not implemented.'); 50 } 51 fontFeature(value: string): this { 52 throw new Error('Method not implemented.'); 53 } 54} 55 56class TextClockFormatModifier extends ModifierWithKey<string> { 57 constructor(value: string) { 58 super(value); 59 } 60 static identity: Symbol = Symbol('textClockFormat'); 61 applyPeer(node: KNode, reset: boolean): void { 62 if (reset) { 63 getUINativeModule().textClock.resetFormat(node); 64 } else { 65 getUINativeModule().textClock.setFormat(node, this.value); 66 } 67 } 68} 69 70class TextClockFontColorModifier extends ModifierWithKey<ResourceColor> { 71 constructor(value: ResourceColor) { 72 super(value); 73 } 74 static identity: Symbol = Symbol('textClockFontColor'); 75 applyPeer(node: KNode, reset: boolean): void { 76 if (reset) { 77 getUINativeModule().textClock.resetFontColor(node); 78 } else { 79 getUINativeModule().textClock.setFontColor(node, this.value); 80 } 81 } 82 83 checkObjectDiff(): boolean { 84 return !isBaseOrResourceEqual(this.stageValue, this.value); 85 } 86} 87 88class TextClockFontSizeModifier extends ModifierWithKey<Length> { 89 constructor(value: Length) { 90 super(value); 91 } 92 static identity: Symbol = Symbol('textClockFontSize'); 93 applyPeer(node: KNode, reset: boolean): void { 94 if (reset) { 95 getUINativeModule().textClock.resetFontSize(node); 96 } else { 97 getUINativeModule().textClock.setFontSize(node, this.value); 98 } 99 } 100 checkObjectDiff(): boolean { 101 return !isBaseOrResourceEqual(this.stageValue, this.value); 102 } 103} 104 105class TextClockFontStyleModifier extends ModifierWithKey<FontStyle> { 106 constructor(value: FontStyle) { 107 super(value); 108 } 109 static identity: Symbol = Symbol('textClockFontStyle'); 110 applyPeer(node: KNode, reset: boolean): void { 111 if (reset) { 112 getUINativeModule().textClock.resetFontStyle(node); 113 } else { 114 getUINativeModule().textClock.setFontStyle(node, this.value!); 115 } 116 } 117} 118 119class TextClockFontWeightModifier extends ModifierWithKey<number | FontWeight | string> { 120 constructor(value: number | FontWeight | string) { 121 super(value); 122 } 123 static identity: Symbol = Symbol('textClockFontWeight'); 124 applyPeer(node: KNode, reset: boolean): void { 125 if (reset) { 126 getUINativeModule().textClock.resetFontWeight(node); 127 } else { 128 getUINativeModule().textClock.setFontWeight(node, this.value!); 129 } 130 } 131} 132 133class TextClockFontFamilyModifier extends ModifierWithKey<ResourceStr> { 134 constructor(value: ResourceStr) { 135 super(value); 136 } 137 static identity: Symbol = Symbol('textClockFontFamily'); 138 applyPeer(node: KNode, reset: boolean): void { 139 if (reset) { 140 getUINativeModule().textClock.resetFontFamily(node); 141 } else { 142 getUINativeModule().textClock.setFontFamily(node, this.value!); 143 } 144 } 145 146 checkObjectDiff(): boolean { 147 return !isBaseOrResourceEqual(this.stageValue, this.value); 148 } 149} 150 151// @ts-ignore 152globalThis.TextClock.attributeModifier = function (modifier) { 153 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 154 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 155 let component = this.createOrGetNode(elmtId, () => { 156 return new ArkTextClockComponent(nativeNode); 157 }); 158 applyUIAttributes(modifier, nativeNode, component); 159 component.applyModifierPatch(); 160}; 161