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) { 19 super(nativePtr); 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 constructor(value: ResourceColor) { 37 super(value); 38 } 39 static identity: Symbol = Symbol('color'); 40 applyPeer(node: KNode, reset: boolean): void { 41 if (reset) { 42 getUINativeModule().qrcode.resetQRColor(node); 43 } else { 44 getUINativeModule().qrcode.setQRColor(node, this.value); 45 } 46 } 47 48 checkObjectDiff(): boolean { 49 return !isBaseOrResourceEqual(this.stageValue, this.value); 50 } 51} 52 53class QRBackgroundColorModifier extends ModifierWithKey<ResourceColor> { 54 constructor(value: ResourceColor) { 55 super(value); 56 } 57 static identity: Symbol = Symbol('qrBackgroundColor'); 58 applyPeer(node: KNode, reset: boolean): void { 59 if (reset) { 60 getUINativeModule().qrcode.resetQRBackgroundColor(node); 61 } else { 62 getUINativeModule().qrcode.setQRBackgroundColor(node, this.value); 63 } 64 } 65 66 checkObjectDiff(): boolean { 67 return !isBaseOrResourceEqual(this.stageValue, this.value); 68 } 69} 70 71class QRContentOpacityModifier extends ModifierWithKey<number | Resource> { 72 constructor(value: number | Resource) { 73 super(value); 74 } 75 static identity: Symbol = Symbol('qrContentOpacity'); 76 applyPeer(node: KNode, reset: boolean): void { 77 if (reset) { 78 getUINativeModule().qrcode.resetContentOpacity(node); 79 } else { 80 getUINativeModule().qrcode.setContentOpacity(node, this.value); 81 } 82 } 83 84 checkObjectDiff(): boolean { 85 return !isBaseOrResourceEqual(this.stageValue, this.value); 86 } 87} 88 89// @ts-ignore 90globalThis.QRCode.attributeModifier = function (modifier) { 91 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 92 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 93 let component = this.createOrGetNode(elmtId, () => { 94 return new ArkQRCodeComponent(nativeNode); 95 }); 96 applyUIAttributes(modifier, nativeNode, component); 97 component.applyModifierPatch(); 98}; 99