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 PatternLockActiveColorModifier extends ModifierWithKey<ResourceColor> { 18 constructor(value: ResourceColor) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('patternLockActiveColor'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().patternLock.resetActiveColor(node); 25 } else { 26 getUINativeModule().patternLock.setActiveColor(node, this.value!); 27 } 28 } 29 checkObjectDiff(): boolean { 30 return !isBaseOrResourceEqual(this.stageValue, this.value); 31 } 32} 33 34class PatternLockSelectedColorModifier extends ModifierWithKey<ResourceColor> { 35 constructor(value: ResourceColor) { 36 super(value); 37 } 38 static identity: Symbol = Symbol('patternLockSelectedColor'); 39 applyPeer(node: KNode, reset: boolean): void { 40 if (reset) { 41 getUINativeModule().patternLock.resetSelectedColor(node); 42 } else { 43 getUINativeModule().patternLock.setSelectedColor(node, this.value!); 44 } 45 } 46 checkObjectDiff(): boolean { 47 return !isBaseOrResourceEqual(this.stageValue, this.value); 48 } 49} 50 51class PatternLockPathColorModifier extends ModifierWithKey<ResourceColor> { 52 constructor(value: ResourceColor) { 53 super(value); 54 } 55 static identity: Symbol = Symbol('patternLockPathColor'); 56 applyPeer(node: KNode, reset: boolean): void { 57 if (reset) { 58 getUINativeModule().patternLock.resetPathColor(node); 59 } else { 60 getUINativeModule().patternLock.setPathColor(node, this.value!); 61 } 62 } 63 checkObjectDiff(): boolean { 64 return !isBaseOrResourceEqual(this.stageValue, this.value); 65 } 66} 67 68class PatternLockRegularColorModifier extends ModifierWithKey<ResourceColor> { 69 constructor(value: ResourceColor) { 70 super(value); 71 } 72 static identity: Symbol = Symbol('patternLockRegularColor'); 73 applyPeer(node: KNode, reset: boolean): void { 74 if (reset) { 75 getUINativeModule().patternLock.resetRegularColor(node); 76 } else { 77 getUINativeModule().patternLock.setRegularColor(node, this.value!); 78 } 79 } 80 checkObjectDiff(): boolean { 81 return !isBaseOrResourceEqual(this.stageValue, this.value); 82 } 83} 84 85class PatternLockSideLengthModifier extends ModifierWithKey<Length> { 86 constructor(value: Length) { 87 super(value); 88 } 89 static identity: Symbol = Symbol('patternLockSideLength'); 90 applyPeer(node: KNode, reset: boolean): void { 91 if (reset) { 92 getUINativeModule().patternLock.resetSideLength(node); 93 } else { 94 getUINativeModule().patternLock.setSideLength(node, this.value!); 95 } 96 } 97 checkObjectDiff(): boolean { 98 return !isBaseOrResourceEqual(this.stageValue, this.value); 99 } 100} 101 102class PatternLockPathStrokeModifier extends ModifierWithKey<number | string> { 103 constructor(value: number | string) { 104 super(value); 105 } 106 static identity: Symbol = Symbol('patternLockPathStroke'); 107 applyPeer(node: KNode, reset: boolean): void { 108 if (reset) { 109 getUINativeModule().patternLock.resetPathStrokeWidth(node); 110 } else { 111 getUINativeModule().patternLock.setPathStrokeWidth(node, this.value!); 112 } 113 } 114 checkObjectDiff(): boolean { 115 return this.stageValue !== this.value; 116 } 117} 118 119class PatternLockCircleRadiusModifier extends ModifierWithKey<Length> { 120 constructor(value: Length) { 121 super(value); 122 } 123 static identity: Symbol = Symbol('patternLockCircleRadius'); 124 applyPeer(node: KNode, reset: boolean): void { 125 if (reset) { 126 getUINativeModule().patternLock.resetCircleRadius(node); 127 } else { 128 getUINativeModule().patternLock.setCircleRadius(node, this.value!); 129 } 130 } 131 checkObjectDiff(): boolean { 132 return !isBaseOrResourceEqual(this.stageValue, this.value); 133 } 134} 135 136class PatternLockAutoResetModifier extends ModifierWithKey<boolean> { 137 constructor(value: boolean) { 138 super(value); 139 } 140 static identity: Symbol = Symbol('patternlockautoreset'); 141 applyPeer(node: KNode, reset: boolean): void { 142 if (reset) { 143 getUINativeModule().patternLock.resetAutoReset(node); 144 } else { 145 getUINativeModule().patternLock.setAutoReset(node, this.value!); 146 } 147 } 148 checkObjectDiff(): boolean { 149 return this.stageValue !== this.value; 150 } 151} 152 153class ArkPatternLockComponent extends ArkComponent implements PatternLockAttribute { 154 constructor(nativePtr: KNode) { 155 super(nativePtr); 156 } 157 sideLength(value: Length): PatternLockAttribute { 158 modifierWithKey(this._modifiersWithKeys, PatternLockSideLengthModifier.identity, 159 PatternLockSideLengthModifier, value); 160 return this; 161 } 162 circleRadius(value: Length): PatternLockAttribute { 163 modifierWithKey(this._modifiersWithKeys, PatternLockCircleRadiusModifier.identity, 164 PatternLockCircleRadiusModifier, value); 165 return this; 166 } 167 regularColor(value: ResourceColor): PatternLockAttribute { 168 modifierWithKey(this._modifiersWithKeys, PatternLockRegularColorModifier.identity, 169 PatternLockRegularColorModifier, value); 170 return this; 171 } 172 selectedColor(value: ResourceColor): PatternLockAttribute { 173 modifierWithKey(this._modifiersWithKeys, PatternLockSelectedColorModifier.identity, 174 PatternLockSelectedColorModifier, value); 175 return this; 176 } 177 activeColor(value: ResourceColor): PatternLockAttribute { 178 modifierWithKey(this._modifiersWithKeys, PatternLockActiveColorModifier.identity, 179 PatternLockActiveColorModifier, value); 180 return this; 181 } 182 pathColor(value: ResourceColor): PatternLockAttribute { 183 modifierWithKey(this._modifiersWithKeys, PatternLockPathColorModifier.identity, 184 PatternLockPathColorModifier, value); 185 return this; 186 } 187 pathStrokeWidth(value: number | string): PatternLockAttribute { 188 modifierWithKey(this._modifiersWithKeys, PatternLockPathStrokeModifier.identity, 189 PatternLockPathStrokeModifier, value); 190 return this; 191 } 192 autoReset(value: boolean): PatternLockAttribute { 193 modifierWithKey(this._modifiersWithKeys, PatternLockAutoResetModifier.identity, 194 PatternLockAutoResetModifier, value); 195 return this; 196 } 197 onPatternComplete(callback: (input: Array<number>) => void): PatternLockAttribute { 198 throw new Error('Method not implemented.'); 199 } 200 onDotConnect(callback: any): PatternLockAttribute { 201 throw new Error('Method not implemented.'); 202 } 203} 204// @ts-ignore 205globalThis.PatternLock.attributeModifier = function (modifier) { 206 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 207 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 208 let component = this.createOrGetNode(elmtId, () => { 209 return new ArkPatternLockComponent(nativeNode); 210 }); 211 applyUIAttributes(modifier, nativeNode, component); 212 component.applyModifierPatch(); 213};