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 SideBarContainerPositionModifier extends ModifierWithKey<number> { 18 constructor(value: number) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('sideBarContainerPosition'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().sideBarContainer.resetSideBarPosition(node); 25 } else { 26 getUINativeModule().sideBarContainer.setSideBarPosition(node, this.value); 27 } 28 } 29 checkObjectDiff(): boolean { 30 return !isBaseOrResourceEqual(this.stageValue, this.value); 31 } 32} 33 34class SideBarContainerOnChangeModifier extends ModifierWithKey<((value: boolean) => void)> { 35 constructor(value: (value: boolean) => void) { 36 super(value); 37 } 38 static identity: Symbol = Symbol('sideBarContainerOnChange'); 39 applyPeer(node: KNode, reset: boolean): void { 40 if (reset) { 41 getUINativeModule().sideBarContainer.resetOnChange(node); 42 } else { 43 getUINativeModule().sideBarContainer.setOnChange(node, this.value); 44 } 45 } 46} 47 48class SideBarContainerAutoHideModifier extends ModifierWithKey<boolean> { 49 constructor(value: boolean) { 50 super(value); 51 } 52 static identity: Symbol = Symbol('sideBarContainerautoHide'); 53 applyPeer(node: KNode, reset: boolean): void { 54 if (reset) { 55 getUINativeModule().sideBarContainer.resetAutoHide(node); 56 } else { 57 getUINativeModule().sideBarContainer.setAutoHide(node, this.value!); 58 } 59 } 60 checkObjectDiff(): boolean { 61 return !isBaseOrResourceEqual(this.stageValue, this.value); 62 } 63} 64 65class SideBarContainerShowSideBarModifier extends ModifierWithKey<boolean> { 66 constructor(value: boolean) { 67 super(value); 68 } 69 static identity: Symbol = Symbol('sideBarContainerShowSideBar'); 70 applyPeer(node: KNode, reset: boolean): void { 71 if (reset) { 72 getUINativeModule().sideBarContainer.resetShowSideBar(node); 73 } else { 74 getUINativeModule().sideBarContainer.setShowSideBar(node, this.value!); 75 } 76 } 77 checkObjectDiff(): boolean { 78 return !isBaseOrResourceEqual(this.stageValue, this.value); 79 } 80} 81 82class SideBarContainerMaxSideBarWidthModifier extends ModifierWithKey<number | Length> { 83 constructor(value: number | Length) { 84 super(value); 85 } 86 static identity: Symbol = Symbol('sideBarContainerMaxSideBarWidth'); 87 applyPeer(node: KNode, reset: boolean): void { 88 if (reset) { 89 getUINativeModule().sideBarContainer.resetMaxSideBarWidth(node); 90 } else { 91 getUINativeModule().sideBarContainer.setMaxSideBarWidth(node, this.value!); 92 } 93 } 94 checkObjectDiff(): boolean { 95 return !isBaseOrResourceEqual(this.stageValue, this.value); 96 } 97} 98 99class SideBarContainerWidthModifier extends ModifierWithKey<number | Length> { 100 constructor(value: number | Length) { 101 super(value); 102 } 103 static identity: Symbol = Symbol('sideBarContainerWidth'); 104 applyPeer(node: KNode, reset: boolean): void { 105 if (reset) { 106 getUINativeModule().sideBarContainer.resetSideBarWidth(node); 107 } else { 108 getUINativeModule().sideBarContainer.setSideBarWidth(node, this.value!); 109 } 110 } 111 checkObjectDiff(): boolean { 112 return !isBaseOrResourceEqual(this.stageValue, this.value); 113 } 114} 115 116class SideBarContainerMinContentWidthModifier extends ModifierWithKey<Dimension> { 117 constructor(value: Dimension) { 118 super(value); 119 } 120 static identity: Symbol = Symbol('sideBarContainerMinContentWidth'); 121 applyPeer(node: KNode, reset: boolean): void { 122 if (reset) { 123 getUINativeModule().sideBarContainer.resetMinContentWidth(node); 124 } else { 125 getUINativeModule().sideBarContainer.setMinContentWidth(node, this.value!); 126 } 127 } 128 checkObjectDiff(): boolean { 129 return !isBaseOrResourceEqual(this.stageValue, this.value); 130 } 131} 132 133class SideBarContainerShowControlButtonModifier extends ModifierWithKey<boolean> { 134 constructor(value: boolean) { 135 super(value); 136 } 137 static identity: Symbol = Symbol('sideBarContainerShowControlButton'); 138 applyPeer(node: KNode, reset: boolean): void { 139 if (reset) { 140 getUINativeModule().sideBarContainer.resetShowControlButton(node); 141 } else { 142 getUINativeModule().sideBarContainer.setShowControlButton(node, this.value!); 143 } 144 } 145 checkObjectDiff(): boolean { 146 return !isBaseOrResourceEqual(this.stageValue, this.value); 147 } 148} 149 150class SideBarContainerMinSideBarWidthModifier extends ModifierWithKey<number | Length> { 151 constructor(value: number | Length) { 152 super(value); 153 } 154 static identity: Symbol = Symbol('sideBarContainerMinSideBarWidth'); 155 applyPeer(node: KNode, reset: boolean): void { 156 if (reset) { 157 getUINativeModule().sideBarContainer.resetMinSideBarWidth(node); 158 } else { 159 getUINativeModule().sideBarContainer.setMinSideBarWidth(node, this.value!); 160 } 161 } 162 checkObjectDiff(): boolean { 163 return !isBaseOrResourceEqual(this.stageValue, this.value); 164 } 165} 166 167class SideBarContainerControlButtonModifier extends ModifierWithKey<ButtonStyle> { 168 constructor(value: ButtonStyle) { 169 super(value); 170 } 171 static identity: Symbol = Symbol('sideBarContainercontrolButton'); 172 applyPeer(node: KNode, reset: boolean): void { 173 if (reset) { 174 getUINativeModule().sideBarContainer.resetControlButton(node); 175 } else { 176 getUINativeModule().sideBarContainer.setControlButton(node, this.value.left, 177 this.value.top, this.value.width, this.value.height, this.value.icons?.shown, 178 this.value.icons?.hidden, this.value.icons?.switching); 179 } 180 } 181 182 checkObjectDiff(): boolean { 183 if (!(this.stageValue.left === this.value.left && 184 this.stageValue.top === this.value.top && 185 this.stageValue.width === this.value.width && 186 this.stageValue.height === this.value.height)) { 187 return true; 188 } else { 189 return !isBaseOrResourceEqual(this.stageValue.icons?.shown, this.value.icons?.shown) || 190 !isBaseOrResourceEqual(this.stageValue.icons?.hidden, this.value.icons?.hidden) || 191 !isBaseOrResourceEqual(this.stageValue.icons?.switching, this.value.icons?.switching); 192 } 193 } 194} 195 196class SideBarContainerDividerModifier extends ModifierWithKey<DividerStyle> { 197 constructor(value: DividerStyle) { 198 super(value); 199 } 200 static identity: Symbol = Symbol('sideBarContainerdivider'); 201 applyPeer(node: KNode, reset: boolean): void { 202 if (reset) { 203 getUINativeModule().sideBarContainer.resetDivider(node); 204 } else { 205 if (!this.value || !isObject(this.value) || !this.value.strokeWidth) { 206 getUINativeModule().sideBarContainer.resetDivider(node); 207 } else { 208 getUINativeModule().sideBarContainer.setDivider(node, this.value.strokeWidth, 209 this.value.color, this.value.startMargin, this.value.endMargin); 210 } 211 } 212 } 213 214 checkObjectDiff(): boolean { 215 return !isBaseOrResourceEqual(this.stageValue.strokeWidth, this.value.strokeWidth) || 216 !isBaseOrResourceEqual(this.stageValue.color, this.value.color) || 217 !isBaseOrResourceEqual(this.stageValue.startMargin, this.value.startMargin) || 218 !isBaseOrResourceEqual(this.stageValue.endMargin, this.value.endMargin); 219 } 220} 221 222class ArkSideBarContainerComponent extends ArkComponent implements SideBarContainerAttribute { 223 constructor(nativePtr: KNode, classType?: ModifierType) { 224 super(nativePtr, classType); 225 } 226 onChange(callback: (value: boolean) => void): SideBarContainerAttribute { 227 modifierWithKey(this._modifiersWithKeys, SideBarContainerOnChangeModifier.identity, 228 SideBarContainerOnChangeModifier, callback); 229 return this; 230 } 231 autoHide(value: boolean): SideBarContainerAttribute { 232 modifierWithKey(this._modifiersWithKeys, SideBarContainerAutoHideModifier.identity, SideBarContainerAutoHideModifier, value); 233 return this; 234 } 235 showSideBar(value: boolean): SideBarContainerAttribute { 236 modifierWithKey(this._modifiersWithKeys, SideBarContainerShowSideBarModifier.identity, SideBarContainerShowSideBarModifier, value); 237 return this; 238 } 239 240 maxSideBarWidth(value: number | Length): SideBarContainerAttribute { 241 modifierWithKey(this._modifiersWithKeys, SideBarContainerMaxSideBarWidthModifier.identity, SideBarContainerMaxSideBarWidthModifier, value); 242 return this; 243 } 244 245 minSideBarWidth(value: number | Length): SideBarContainerAttribute { 246 modifierWithKey(this._modifiersWithKeys, SideBarContainerMinSideBarWidthModifier.identity, SideBarContainerMinSideBarWidthModifier, value); 247 return this; 248 } 249 minContentWidth(value: Dimension): SideBarContainerAttribute { 250 modifierWithKey(this._modifiersWithKeys, SideBarContainerMinContentWidthModifier.identity, SideBarContainerMinContentWidthModifier, value); 251 return this; 252 } 253 controlButton(value: ButtonStyle): SideBarContainerAttribute { 254 modifierWithKey(this._modifiersWithKeys, SideBarContainerControlButtonModifier.identity, SideBarContainerControlButtonModifier, value); 255 return this; 256 } 257 258 divider(value: DividerStyle | null): SideBarContainerAttribute { 259 modifierWithKey(this._modifiersWithKeys, SideBarContainerDividerModifier.identity, SideBarContainerDividerModifier, value); 260 return this; 261 } 262 263 sideBarPosition(value: SideBarPosition): SideBarContainerAttribute { 264 modifierWithKey(this._modifiersWithKeys, SideBarContainerPositionModifier.identity, SideBarContainerPositionModifier, value); 265 return this; 266 } 267 268 sideBarWidth(value: number | Length): SideBarContainerAttribute { 269 modifierWithKey(this._modifiersWithKeys, SideBarContainerWidthModifier.identity, SideBarContainerWidthModifier, value); 270 return this; 271 } 272 273 showControlButton(value: boolean): SideBarContainerAttribute { 274 modifierWithKey(this._modifiersWithKeys, SideBarContainerShowControlButtonModifier.identity, SideBarContainerShowControlButtonModifier, value); 275 return this; 276 } 277} 278// @ts-ignore 279globalThis.SideBarContainer.attributeModifier = function (modifier: ArkComponent): void { 280 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 281 return new ArkSideBarContainerComponent(nativePtr); 282 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 283 return new modifierJS.SideBarContainerModifier(nativePtr, classType); 284 }); 285};