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 PatternLockActivateCircleStyleModifier extends ModifierWithKey<CircleStyleOptions> { 154 constructor(value: CircleStyleOptions) { 155 super(value); 156 } 157 static identity: Symbol = Symbol('patternLockActivateCircleStyle'); 158 applyPeer(node: KNode, reset: boolean): void { 159 if (reset) { 160 getUINativeModule().patternLock.resetActivateCircleStyle(node); 161 } else { 162 getUINativeModule().patternLock.setActivateCircleStyle(node, this.value!); 163 } 164 } 165 checkObjectDiff(): boolean { 166 return !isBaseOrResourceEqual(this.stageValue, this.value); 167 } 168} 169 170class PatternLockBackgroundColorModifier extends ModifierWithKey<ResourceColor> { 171 constructor(value: ResourceColor) { 172 super(value); 173 } 174 static identity: Symbol = Symbol('patternLockBackgroundColor'); 175 applyPeer(node: KNode, reset: boolean): void { 176 if (reset) { 177 getUINativeModule().common.resetBackgroundColor(node); 178 } else { 179 getUINativeModule().common.setBackgroundColor(node, this.value); 180 } 181 } 182 checkObjectDiff(): boolean { 183 return !isBaseOrResourceEqual(this.stageValue, this.value); 184 } 185} 186 187declare type OnPatternCompleteFunc = (input: Array<number>) => void 188class PatternLockOnPatternCompleteModifer extends ModifierWithKey<OnPatternCompleteFunc> { 189 constructor(value: OnPatternCompleteFunc) { 190 super(value); 191 } 192 static identity: Symbol = Symbol('patternLockOnPatternComplete'); 193 applyPeer(node: KNode, reset: boolean): void { 194 if (reset) { 195 getUINativeModule().patternLock.resetPatternLockOnPatternComplete(node); 196 } else { 197 getUINativeModule().patternLock.setPatternLockOnPatternComplete(node, this.value); 198 } 199 } 200} 201 202declare type OnDotConnectFunc = (input: Array<number>) => void 203class PatternLockOnDotConnectModifer extends ModifierWithKey<OnDotConnectFunc> { 204 constructor(value: OnDotConnectFunc) { 205 super(value); 206 } 207 static identity: Symbol = Symbol('patternLockOnDotConnect'); 208 applyPeer(node: KNode, reset: boolean): void { 209 if (reset) { 210 getUINativeModule().patternLock.resetPatternLockOnDotConnect(node); 211 } else { 212 getUINativeModule().patternLock.setPatternLockOnDotConnect(node, this.value); 213 } 214 } 215} 216 217class ArkPatternLockComponent extends ArkComponent implements PatternLockAttribute { 218 constructor(nativePtr: KNode, classType?: ModifierType) { 219 super(nativePtr, classType); 220 } 221 sideLength(value: Length): PatternLockAttribute { 222 modifierWithKey(this._modifiersWithKeys, PatternLockSideLengthModifier.identity, 223 PatternLockSideLengthModifier, value); 224 return this; 225 } 226 circleRadius(value: Length): PatternLockAttribute { 227 modifierWithKey(this._modifiersWithKeys, PatternLockCircleRadiusModifier.identity, 228 PatternLockCircleRadiusModifier, value); 229 return this; 230 } 231 regularColor(value: ResourceColor): PatternLockAttribute { 232 modifierWithKey(this._modifiersWithKeys, PatternLockRegularColorModifier.identity, 233 PatternLockRegularColorModifier, value); 234 return this; 235 } 236 selectedColor(value: ResourceColor): PatternLockAttribute { 237 modifierWithKey(this._modifiersWithKeys, PatternLockSelectedColorModifier.identity, 238 PatternLockSelectedColorModifier, value); 239 return this; 240 } 241 activeColor(value: ResourceColor): PatternLockAttribute { 242 modifierWithKey(this._modifiersWithKeys, PatternLockActiveColorModifier.identity, 243 PatternLockActiveColorModifier, value); 244 return this; 245 } 246 pathColor(value: ResourceColor): PatternLockAttribute { 247 modifierWithKey(this._modifiersWithKeys, PatternLockPathColorModifier.identity, 248 PatternLockPathColorModifier, value); 249 return this; 250 } 251 pathStrokeWidth(value: number | string): PatternLockAttribute { 252 modifierWithKey(this._modifiersWithKeys, PatternLockPathStrokeModifier.identity, 253 PatternLockPathStrokeModifier, value); 254 return this; 255 } 256 autoReset(value: boolean): PatternLockAttribute { 257 modifierWithKey(this._modifiersWithKeys, PatternLockAutoResetModifier.identity, 258 PatternLockAutoResetModifier, value); 259 return this; 260 } 261 activateCircleStyle(value: CircleStyleOptions): PatternLockAttribute { 262 modifierWithKey(this._modifiersWithKeys, PatternLockActivateCircleStyleModifier.identity, 263 PatternLockActivateCircleStyleModifier, value); 264 return this; 265 } 266 onPatternComplete(callback: (input: Array<number>) => void): this { 267 modifierWithKey(this._modifiersWithKeys, PatternLockOnPatternCompleteModifer.identity, 268 PatternLockOnDotConnectModifer, callback); 269 return this; 270 } 271 onDotConnect(callback: any): this { 272 modifierWithKey(this._modifiersWithKeys, PatternLockOnDotConnectModifer.identity, 273 PatternLockOnDotConnectModifer, callback); 274 return this; 275 } 276 backgroundColor(value: ResourceColor): PatternLockAttribute { 277 modifierWithKey(this._modifiersWithKeys, PatternLockBackgroundColorModifier.identity, 278 PatternLockBackgroundColorModifier, value); 279 return this; 280 } 281} 282// @ts-ignore 283globalThis.PatternLock.attributeModifier = function (modifier: ArkComponent): void { 284 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 285 return new ArkPatternLockComponent(nativePtr); 286 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 287 return new modifierJS.PatternLockModifier(nativePtr, classType); 288 }); 289}; 290