• 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  static identity: Symbol = Symbol('color');
58  applyPeer(node: KNode, reset: boolean): void {
59    if (reset) {
60      getUINativeModule().qrcode.resetQRColor(node);
61    } else {
62      getUINativeModule().qrcode.setQRColor(node, this.value);
63    }
64  }
65
66  checkObjectDiff(): boolean {
67    if (isResource(this.stageValue) && isResource(this.value)) {
68      return !isResourceEqual(this.stageValue, this.value);
69    } else {
70      return true;
71    }
72  }
73}
74
75class QRBackgroundColorModifier extends ModifierWithKey<ResourceColor> {
76  static identity: Symbol = Symbol('qrBackgroundColor');
77  applyPeer(node: KNode, reset: boolean): void {
78    if (reset) {
79      getUINativeModule().qrcode.resetQRBackgroundColor(node);
80    } else {
81      getUINativeModule().qrcode.setQRBackgroundColor(node, this.value);
82    }
83  }
84
85  checkObjectDiff(): boolean {
86    if (isResource(this.stageValue) && isResource(this.value)) {
87      return !isResourceEqual(this.stageValue, this.value);
88    } else {
89      return true;
90    }
91  }
92}
93
94class QRContentOpacityModifier extends ModifierWithKey<number | Resource> {
95  static identity: Symbol = Symbol('qrContentOpacity');
96  applyPeer(node: KNode, reset: boolean): void {
97    if (reset) {
98      getUINativeModule().qrcode.resetContentOpacity(node);
99    } else {
100      getUINativeModule().qrcode.setContentOpacity(node, this.value);
101    }
102  }
103
104  checkObjectDiff(): boolean {
105    return !isBaseOrResourceEqual(this.stageValue, this.value);
106  }
107}
108
109// @ts-ignore
110globalThis.QRCode.attributeModifier = function (modifier: ArkComponent): void {
111  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
112    return new ArkQRCodeComponent(nativePtr);
113  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
114    return new modifierJS.QRCodeModifier(nativePtr, classType);
115  });
116};
117