• 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 ArkHyperlinkComponent extends ArkComponent implements HyperlinkAttribute {
19  constructor(nativePtr: KNode, classType?: ModifierType) {
20    super(nativePtr, classType);
21  }
22  color(value: ResourceColor): this {
23    modifierWithKey(this._modifiersWithKeys, HyperlinkColorModifier.identity, HyperlinkColorModifier, value);
24    return this;
25  }
26  draggable(value: boolean): this {
27    modifierWithKey(this._modifiersWithKeys, HyperlinkDraggableModifier.identity, HyperlinkDraggableModifier, value);
28    return this;
29  }
30}
31
32class HyperlinkColorModifier extends ModifierWithKey<ResourceColor> {
33  static identity: Symbol = Symbol('hyperlinkColor');
34  applyPeer(node: KNode, reset: boolean): void {
35    if (reset) {
36      getUINativeModule().hyperlink.resetColor(node);
37    } else {
38      getUINativeModule().hyperlink.setColor(node, this.value!);
39    }
40  }
41
42  checkObjectDiff(): boolean {
43    return !isBaseOrResourceEqual(this.stageValue, this.value);
44  }
45}
46
47class HyperlinkDraggableModifier extends ModifierWithKey<boolean> {
48  constructor(value: boolean) {
49    super(value);
50  }
51  static identity: Symbol = Symbol('hyperlinkDraggable');
52  applyPeer(node: KNode, reset: boolean): void {
53    if (reset) {
54      getUINativeModule().hyperlink.resetDraggable(node);
55    } else {
56      getUINativeModule().hyperlink.setDraggable(node, this.value);
57    }
58  }
59}
60
61// @ts-ignore
62globalThis.Hyperlink.attributeModifier = function (modifier: ArkComponent): void {
63  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
64    return new ArkHyperlinkComponent(nativePtr);
65  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
66    return new modifierJS.HyperlinkModifier(nativePtr, classType);
67  });
68};
69