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