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 CheckboxGroupSelectAllModifier extends ModifierWithKey<boolean> { 18 constructor(value: boolean) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('checkboxgroupSelectAll'); 22 applyPeer(node: KNode, reset: boolean) { 23 if (reset) { 24 getUINativeModule().checkboxgroup.resetCheckboxGroupSelectAll(node); 25 } else { 26 getUINativeModule().checkboxgroup.setCheckboxGroupSelectAll(node, this.value); 27 } 28 } 29} 30 31class CheckboxGroupSelectedColorModifier extends ModifierWithKey<ResourceColor> { 32 constructor(value: ResourceColor) { 33 super(value); 34 } 35 static identity: Symbol = Symbol('checkboxgroupSelectedColor'); 36 applyPeer(node: KNode, reset: boolean) { 37 if (reset) { 38 getUINativeModule().checkboxgroup.resetCheckboxGroupSelectedColor(node); 39 } else { 40 getUINativeModule().checkboxgroup.setCheckboxGroupSelectedColor(node, this.value); 41 } 42 } 43 44 checkObjectDiff() { 45 return !isBaseOrResourceEqual(this.stageValue, this.value); 46 } 47} 48 49 50class CheckboxGroupUnselectedColorModifier extends ModifierWithKey<ResourceColor> { 51 constructor(value: ResourceColor) { 52 super(value); 53 } 54 static identity: Symbol = Symbol('checkboxgroupUnselectedColor'); 55 applyPeer(node: KNode, reset: boolean) { 56 if (reset) { 57 getUINativeModule().checkboxgroup.resetCheckboxGroupUnSelectedColor(node); 58 } else { 59 getUINativeModule().checkboxgroup.setCheckboxGroupUnSelectedColor(node, this.value); 60 } 61 } 62 63 checkObjectDiff() { 64 return !isBaseOrResourceEqual(this.stageValue, this.value); 65 } 66} 67class CheckboxGroupMarkModifier extends ModifierWithKey<MarkStyle> { 68 constructor(value: MarkStyle) { 69 super(value); 70 } 71 static identity: Symbol = Symbol('checkboxgroupMark'); 72 applyPeer(node: KNode, reset: boolean): void { 73 if (reset) { 74 getUINativeModule().checkboxgroup.resetCheckboxGroupMark(node); 75 } else { 76 getUINativeModule().checkboxgroup.setCheckboxGroupMark(node, this.value?.strokeColor, this.value?.size, this.value?.strokeWidth); 77 } 78 } 79 80 checkObjectDiff(): boolean { 81 let colorEQ = isBaseOrResourceEqual(this.stageValue.strokeColor, this.value.strokeColor); 82 let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size); 83 let widthEQ = isBaseOrResourceEqual(this.stageValue.strokeWidth, this.value.strokeWidth); 84 return !colorEQ || !sizeEQ || !widthEQ; 85 } 86} 87 88class CheckboxGroupWidthModifier extends ModifierWithKey<Length> { 89 constructor(value: Length) { 90 super(value); 91 } 92 static identity: Symbol = Symbol('checkboxGroupWidth'); 93 applyPeer(node: KNode, reset: boolean): void { 94 if (reset) { 95 getUINativeModule().checkboxgroup.resetCheckboxGroupWidth(node); 96 } else { 97 getUINativeModule().checkboxgroup.setCheckboxGroupWidth(node, this.value); 98 } 99 } 100 101 checkObjectDiff(): boolean { 102 return !isBaseOrResourceEqual(this.stageValue, this.value); 103 } 104} 105 106class CheckboxGroupSizeModifier extends ModifierWithKey<SizeOptions> { 107 constructor(value: SizeOptions) { 108 super(value); 109 } 110 static identity: Symbol = Symbol('checkboxGroupSize'); 111 applyPeer(node: KNode, reset: boolean): void { 112 if (reset) { 113 getUINativeModule().checkboxgroup.resetCheckboxGroupSize(node); 114 } else { 115 getUINativeModule().checkboxgroup.setCheckboxGroupSize(node, this.value.width, this.value.height); 116 } 117 } 118 119 checkObjectDiff(): boolean { 120 return !isBaseOrResourceEqual(this.stageValue.width, this.value.width) || 121 !isBaseOrResourceEqual(this.stageValue.height, this.value.height); 122 } 123} 124 125class CheckboxGroupHeightModifier extends ModifierWithKey<Length> { 126 constructor(value: Length) { 127 super(value); 128 } 129 static identity: Symbol = Symbol('checkboxGroupHeight'); 130 applyPeer(node: KNode, reset: boolean): void { 131 if (reset) { 132 getUINativeModule().checkboxgroup.resetCheckboxGroupHeight(node); 133 } else { 134 getUINativeModule().checkboxgroup.setCheckboxGroupHeight(node, this.value); 135 } 136 } 137 138 checkObjectDiff(): boolean { 139 return !isBaseOrResourceEqual(this.stageValue, this.value); 140 } 141} 142 143class ArkCheckboxGroupComponent extends ArkComponent implements CheckboxGroupAttribute { 144 constructor(nativePtr: KNode) { 145 super(nativePtr); 146 } 147 selectAll(value: boolean): this { 148 modifierWithKey(this._modifiersWithKeys, CheckboxGroupSelectAllModifier.identity, CheckboxGroupSelectAllModifier, value); 149 return this; 150 } 151 selectedColor(value: ResourceColor): this { 152 modifierWithKey(this._modifiersWithKeys, CheckboxGroupSelectedColorModifier.identity, CheckboxGroupSelectedColorModifier, value); 153 return this; 154 } 155 unselectedColor(value: ResourceColor): this { 156 modifierWithKey(this._modifiersWithKeys, CheckboxGroupUnselectedColorModifier.identity, CheckboxGroupUnselectedColorModifier, value); 157 return this; 158 } 159 mark(value: MarkStyle): this { 160 modifierWithKey( 161 this._modifiersWithKeys, CheckboxGroupMarkModifier.identity, CheckboxGroupMarkModifier, value); 162 return this; 163 } 164 onChange(callback: (event: CheckboxGroupResult) => void): CheckboxGroupAttribute { 165 throw new Error('Method not implemented.'); 166 } 167 size(value: SizeOptions): this { 168 modifierWithKey( 169 this._modifiersWithKeys, CheckboxGroupSizeModifier.identity, CheckboxGroupSizeModifier, value); 170 return this; 171 } 172 width(value: Length): this { 173 modifierWithKey(this._modifiersWithKeys, CheckboxGroupWidthModifier.identity, CheckboxGroupWidthModifier, value); 174 return this; 175 } 176 height(value: Length): this { 177 modifierWithKey(this._modifiersWithKeys, CheckboxGroupHeightModifier.identity, 178 CheckboxGroupHeightModifier, value); 179 return this; 180 } 181} 182// @ts-ignore 183globalThis.CheckboxGroup.attributeModifier = function (modifier) { 184 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 185 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 186 let component = this.createOrGetNode(elmtId, () => { 187 return new ArkCheckboxGroupComponent(nativeNode); 188 }); 189 applyUIAttributes(modifier, nativeNode, component); 190 component.applyModifierPatch(); 191}; 192 193