• 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  allowChildCount(): number {
22    return 0;
23  }
24  initialize(value: Object[]): this {
25    modifierWithKey(this._modifiersWithKeys, QRValueModifier.identity, QRValueModifier, value[0]);
26    return this;
27  }
28  color(value: ResourceColor): this {
29    modifierWithKey(this._modifiersWithKeys, QRColorModifier.identity, QRColorModifier, value);
30    return this;
31  }
32  backgroundColor(value: ResourceColor): this {
33    modifierWithKey(this._modifiersWithKeys, QRBackgroundColorModifier.identity, QRBackgroundColorModifier, value);
34    return this;
35  }
36  contentOpacity(value: number | Resource): this {
37    modifierWithKey(this._modifiersWithKeys, QRContentOpacityModifier.identity, QRContentOpacityModifier, value);
38    return this;
39  }
40}
41
42class QRValueModifier extends ModifierWithKey<string> {
43  constructor(value: string) {
44    super(value);
45  }
46  static identity: Symbol = Symbol('QRCodeValue');
47  applyPeer(node: KNode, reset: boolean): void {
48    getUINativeModule().qrcode.setQRValue(node, this.value);
49  }
50
51  checkObjectDiff(): boolean {
52    return !isBaseOrResourceEqual(this.stageValue, this.value);
53  }
54}
55
56class QRColorModifier extends ModifierWithKey<ResourceColor> {
57  constructor(value: ResourceColor) {
58    super(value);
59  }
60  static identity: Symbol = Symbol('color');
61  applyPeer(node: KNode, reset: boolean): void {
62    if (reset) {
63      getUINativeModule().qrcode.resetQRColor(node);
64    } else {
65      getUINativeModule().qrcode.setQRColor(node, this.value);
66    }
67  }
68
69  checkObjectDiff(): boolean {
70    return !isBaseOrResourceEqual(this.stageValue, this.value);
71  }
72}
73
74class QRBackgroundColorModifier extends ModifierWithKey<ResourceColor> {
75  constructor(value: ResourceColor) {
76    super(value);
77  }
78  static identity: Symbol = Symbol('qrBackgroundColor');
79  applyPeer(node: KNode, reset: boolean): void {
80    if (reset) {
81      getUINativeModule().qrcode.resetQRBackgroundColor(node);
82    } else {
83      getUINativeModule().qrcode.setQRBackgroundColor(node, this.value);
84    }
85  }
86
87  checkObjectDiff(): boolean {
88    return !isBaseOrResourceEqual(this.stageValue, this.value);
89  }
90}
91
92class QRContentOpacityModifier extends ModifierWithKey<number | Resource> {
93  constructor(value: number | Resource) {
94    super(value);
95  }
96  static identity: Symbol = Symbol('qrContentOpacity');
97  applyPeer(node: KNode, reset: boolean): void {
98    if (reset) {
99      getUINativeModule().qrcode.resetContentOpacity(node);
100    } else {
101      getUINativeModule().qrcode.setContentOpacity(node, this.value);
102    }
103  }
104
105  checkObjectDiff(): boolean {
106    return !isBaseOrResourceEqual(this.stageValue, this.value);
107  }
108}
109
110// @ts-ignore
111globalThis.QRCode.attributeModifier = function (modifier: ArkComponent): void {
112  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
113    return new ArkQRCodeComponent(nativePtr);
114  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
115    return new modifierJS.QRCodeModifier(nativePtr, classType);
116  });
117};
118