• 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) {
20    super(nativePtr);
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  constructor(value: ResourceColor) {
34    super(value);
35  }
36  static identity: Symbol = Symbol('hyperlinkColor');
37  applyPeer(node: KNode, reset: boolean): void {
38    if (reset) {
39      getUINativeModule().hyperlink.resetColor(node);
40    } else {
41      getUINativeModule().hyperlink.setColor(node, this.value!);
42    }
43  }
44
45  checkObjectDiff(): boolean {
46    return !isBaseOrResourceEqual(this.stageValue, this.value);
47  }
48}
49
50class HyperlinkDraggableModifier extends ModifierWithKey<boolean> {
51  constructor(value: boolean) {
52    super(value);
53  }
54  static identity: Symbol = Symbol('hyperlinkDraggable');
55  applyPeer(node: KNode, reset: boolean): void {
56    if (reset) {
57      getUINativeModule().hyperlink.resetDraggable(node);
58    } else {
59      getUINativeModule().hyperlink.setDraggable(node, this.value);
60    }
61  }
62}
63
64// @ts-ignore
65globalThis.Hyperlink.attributeModifier = function (modifier) {
66  const elmtId = ViewStackProcessor.GetElmtIdToAccountFor();
67  let nativeNode = getUINativeModule().getFrameNodeById(elmtId);
68  let component = this.createOrGetNode(elmtId, () => {
69    return new ArkHyperlinkComponent(nativeNode);
70  });
71  applyUIAttributes(modifier, nativeNode, component);
72  component.applyModifierPatch();
73};
74