• 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 ArkQRCodeComponent extends ArkComponent implements QRCodeAttribute {
18  constructor(nativePtr: KNode, classType?: ModifierType) {
19    super(nativePtr, classType);
20  }
21  color(value: ResourceColor): this {
22    modifierWithKey(this._modifiersWithKeys, QRColorModifier.identity, QRColorModifier, value);
23    return this;
24  }
25  backgroundColor(value: ResourceColor): this {
26    modifierWithKey(this._modifiersWithKeys, QRBackgroundColorModifier.identity, QRBackgroundColorModifier, value);
27    return this;
28  }
29  contentOpacity(value: number | Resource): this {
30    modifierWithKey(this._modifiersWithKeys, QRContentOpacityModifier.identity, QRContentOpacityModifier, value);
31    return this;
32  }
33}
34
35class QRColorModifier extends ModifierWithKey<ResourceColor> {
36  static identity: Symbol = Symbol('color');
37  applyPeer(node: KNode, reset: boolean): void {
38    if (reset) {
39      getUINativeModule().qrcode.resetQRColor(node);
40    } else {
41      getUINativeModule().qrcode.setQRColor(node, this.value);
42    }
43  }
44
45  checkObjectDiff(): boolean {
46    if (isResource(this.stageValue) && isResource(this.value)) {
47      return !isResourceEqual(this.stageValue, this.value);
48    } else {
49      return true;
50    }
51  }
52}
53
54class QRBackgroundColorModifier extends ModifierWithKey<ResourceColor> {
55  static identity: Symbol = Symbol('qrBackgroundColor');
56  applyPeer(node: KNode, reset: boolean): void {
57    if (reset) {
58      getUINativeModule().qrcode.resetQRBackgroundColor(node);
59    } else {
60      getUINativeModule().qrcode.setQRBackgroundColor(node, this.value);
61    }
62  }
63
64  checkObjectDiff(): boolean {
65    if (isResource(this.stageValue) && isResource(this.value)) {
66      return !isResourceEqual(this.stageValue, this.value);
67    } else {
68      return true;
69    }
70  }
71}
72
73class QRContentOpacityModifier extends ModifierWithKey<number | Resource> {
74  static identity: Symbol = Symbol('qrContentOpacity');
75  applyPeer(node: KNode, reset: boolean): void {
76    if (reset) {
77      getUINativeModule().qrcode.resetContentOpacity(node);
78    } else {
79      getUINativeModule().qrcode.setContentOpacity(node, this.value);
80    }
81  }
82
83  checkObjectDiff(): boolean {
84    return !isBaseOrResourceEqual(this.stageValue, this.value);
85  }
86}
87
88// @ts-ignore
89globalThis.QRCode.attributeModifier = function (modifier: ArkComponent): void {
90  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
91    return new ArkQRCodeComponent(nativePtr);
92  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
93    return new modifierJS.QRCodeModifier(nativePtr, classType);
94  });
95};
96