• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ArkTextTimerComponent extends ArkComponent implements TextTimerAttribute {
18  constructor(nativePtr: KNode) {
19    super(nativePtr);
20  }
21  fontColor(value: any): this {
22    modifierWithKey(this._modifiersWithKeys, TextTimerFontColorModifier.identity, TextTimerFontColorModifier, value);
23    return this;
24  }
25
26  fontSize(value: any): this {
27    modifierWithKey(this._modifiersWithKeys, TextTimerFontSizeModifier.identity, TextTimerFontSizeModifier, value);
28    return this;
29  }
30
31  fontWeight(value: number | FontWeight | string): this {
32    modifierWithKey(this._modifiersWithKeys, TextTimerFontWeightModifier.identity, TextTimerFontWeightModifier, value);
33    return this;
34  }
35
36  fontStyle(value: FontStyle): this {
37    modifierWithKey(this._modifiersWithKeys, TextTimerFontStyleModifier.identity, TextTimerFontStyleModifier, value);
38    return this;
39  }
40
41  fontFamily(value: string | Resource): this {
42    modifierWithKey(this._modifiersWithKeys, TextTimerFontFamilyModifier.identity, TextTimerFontFamilyModifier, value);
43    return this;
44  }
45
46  format(value: string): this {
47    modifierWithKey(this._modifiersWithKeys, TextTimerFormatModifier.identity, TextTimerFormatModifier, value);
48    return this;
49  }
50
51  onTimer(event: (utc: number, elapsedTime: number) => void): this {
52    throw new Error('Method not implemented.');
53  }
54}
55
56class TextTimerFontColorModifier extends ModifierWithKey<ResourceColor> {
57  static identity: Symbol = Symbol('fontColor');
58  applyPeer(node: KNode, reset: boolean): void {
59    if (reset) {
60      getUINativeModule().textTimer.resetFontColor(node);
61    } else {
62      getUINativeModule().textTimer.setFontColor(node, this.value);
63    }
64  }
65  checkObjectDiff(): boolean {
66    return !isBaseOrResourceEqual(this.stageValue, this.value);
67  }
68}
69
70class TextTimerFontSizeModifier extends ModifierWithKey<Length> {
71  static identity: Symbol = Symbol('fontSize');
72  applyPeer(node: KNode, reset: boolean): void {
73    if (reset) {
74      getUINativeModule().textTimer.resetFontSize(node);
75    } else {
76      getUINativeModule().textTimer.setFontSize(node, this.value);
77    }
78  }
79  checkObjectDiff(): boolean {
80    return !isBaseOrResourceEqual(this.stageValue, this.value);
81  }
82}
83
84class TextTimerFontWeightModifier extends ModifierWithKey<number | FontWeight | string> {
85  static identity: Symbol = Symbol('fontWeight');
86  applyPeer(node: KNode, reset: boolean): void {
87    if (reset) {
88      getUINativeModule().textTimer.resetFontWeight(node);
89    } else {
90      getUINativeModule().textTimer.setFontWeight(node, this.value);
91    }
92  }
93}
94
95class TextTimerFontStyleModifier extends ModifierWithKey<FontStyle> {
96  static identity: Symbol = Symbol('fontStyle');
97  applyPeer(node: KNode, reset: boolean): void {
98    if (reset) {
99      getUINativeModule().textTimer.resetFontStyle(node);
100    } else {
101      getUINativeModule().textTimer.setFontStyle(node, this.value);
102    }
103  }
104  checkObjectDiff(): boolean {
105    return !isBaseOrResourceEqual(this.stageValue, this.value);
106  }
107}
108
109class TextTimerFontFamilyModifier extends ModifierWithKey<string | Resource> {
110  static identity: Symbol = Symbol('fontFamily');
111  applyPeer(node: KNode, reset: boolean): void {
112    if (reset) {
113      getUINativeModule().textTimer.resetFontFamily(node);
114    } else {
115      getUINativeModule().textTimer.setFontFamily(node, this.value);
116    }
117  }
118  checkObjectDiff(): boolean {
119    return !isBaseOrResourceEqual(this.stageValue, this.value);
120  }
121}
122
123class TextTimerFormatModifier extends ModifierWithKey<string> {
124  static identity: Symbol = Symbol('textTimerFormat');
125  applyPeer(node: KNode, reset: boolean): void {
126    if (reset) {
127      getUINativeModule().textTimer.resetFormat(node);
128    } else {
129      getUINativeModule().textTimer.setFormat(node, this.value);
130    }
131  }
132}
133
134// @ts-ignore
135globalThis.TextTimer.attributeModifier = function (modifier) {
136  const elmtId = ViewStackProcessor.GetElmtIdToAccountFor();
137  let nativeNode = getUINativeModule().getFrameNodeById(elmtId);
138  let component = this.createOrGetNode(elmtId, () => {
139    return new ArkTextTimerComponent(nativeNode);
140  });
141  applyUIAttributes(modifier, nativeNode, component);
142  component.applyModifierPatch();
143};
144