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