1/* 2 * Copyright (c) 2023-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 16const REFLECT_MAX_COUNT = 3; 17const IMAGE_SIZE_WIDTH_HEIGHT = 24; 18const TEXT_MIN_SIZE = 9; 19const DISABLE_OPACITY = 0.4; 20const TEXT_MAX_LINES = 2; 21const TOOLBAR_LIST_LENGTH = 5; 22const TOOLBAR_LIST_NORMORL = 4; 23const ITEM_DISABLE_STATE = 2; 24const ITEM_DISABLE_ACTIVATE = 3; 25 26let __decorate = this && this.__decorate || function (e, t, o, r) { 27 let s; 28 let i = arguments.length; 29 let a = i < REFLECT_MAX_COUNT ? t : null === r ? r = Object.getOwnPropertyDescriptor(t, o) : r; 30 if ('object' === typeof Reflect && 'function' === typeof Reflect.decorate) { 31 a = Reflect.decorate(e, t, o, r); 32 } else { 33 for (let n = e.length - 1; n >= 0; n--) { 34 (s = e[n]) && (a = (i < REFLECT_MAX_COUNT ? s(a) : i > REFLECT_MAX_COUNT ? s(t, o, a) : s(t, o)) || a); 35 } 36 } 37 return i > REFLECT_MAX_COUNT && a && Object.defineProperty(t, o, a), a; 38}; 39export let ItemState; 40!function(e) { 41 e[e.ENABLE = 1] = 'ENABLE'; 42 e[e.DISABLE = 2] = 'DISABLE'; 43 e[e.ACTIVATE = 3] = 'ACTIVATE'; 44}(ItemState || (ItemState = {})); 45const PUBLIC_MORE = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAA' + 46 'IGNIUk0AAHomAACAhAAA+gAAAIDoAAB1MAAA6mAAADqYAAAXcJy6UTwAAAAEZ0FNQQAAsY58+1GTAAAAAXNSR0IAr' + 47 's4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAYFJREFUeNrt3CFLQ1EUB/CpCwYRo8' + 48 'G4j2IwCNrUYjH4AfwcfgBBwWZRMNgtFqPdILJgEhGDweAZvDjmJnfv3I3fD/5l3DfOfWdv23vhdDoAAAAAAAAwzxa' + 49 'm9L5rkePIdmSjee05chu5iHxXej5ar3saDdiJXDabGaYfOYg8VHbyU+peKryJvch1ZHnEmtXIYeQ+8lrJyU+re7Hg' + 50 'JtYj52Ou7Uau/thwW1LrLtmAk8jKBOsH37FHFTQgte6SDdht6ZjSUusu2YBeS8eUllr3YvLmuzP6971bYwP6/zjmpY' + 51 'KTmVp3yQbctXRMaal1l2zAaeRngvUfkbMKGpBad8kbsffIZ2RrzPX7kacKGpBad+k74cfmE7I54ur6au4obyr6UU2r' + 52 'e1oP43rNDc6wh1qDS/6t0n83s1o3AAAAAAAAAAAAAEAysyKS6zYrIrlusyKS6zYrwqyIdGZFJDMrIplZETPIrIh5qdu' + 53 'sCLMi0pkVkcysiAqYFVEJsyIAAAAAAAAAKOYXUlF8EUcdfbsAAAAASUVORK5CYII='; 54let ToolBarOption = class { 55 constructor() { 56 this.state = 1; 57 } 58}; 59ToolBarOption = __decorate([Observed], ToolBarOption); 60 61export { ToolBarOption }; 62let ToolBarOptions = class extends Array { 63}; 64ToolBarOptions = __decorate([Observed], ToolBarOptions); 65 66export { ToolBarOptions }; 67 68export class ToolBar extends ViewPU { 69 constructor(e, t, o, r = -1) { 70 super(e, o, r); 71 this.__toolBarList = new SynchedPropertyNesedObjectPU(t.toolBarList, this, 'toolBarList'); 72 this.controller = void 0; 73 this.__activateIndex = new SynchedPropertySimpleOneWayPU(t.activateIndex, this, "activateIndex"); 74 this.__moreText = new SynchedPropertySimpleOneWayPU(t.moreText, this, "moreText"); 75 this.__menuContent = new ObservedPropertyObjectPU([], this, "menuContent"); 76 this.toolBarItemBackground = []; 77 this.__itemBackground = new ObservedPropertyObjectPU({ 78 id: -1, 79 type: 10001, 80 params: ['sys.color.ohos_id_color_toolbar_bg'], 81 bundleName: '', 82 moduleName: '' 83 }, this, 'itemBackground'); 84 this.setInitiallyProvidedValue(t); 85 } 86 87 setInitiallyProvidedValue(e) { 88 this.__toolBarList.set(e.toolBarList); 89 void 0 !== e.controller && (this.controller = e.controller); 90 void 0 !== e.activateIndex ? this.__activateIndex.set(e.activateIndex) : this.__activateIndex.set(-1); 91 void 0 !== e.moreText ? this.__moreText.set(e.moreText) : this.__moreText.set("更多"); 92 void 0 !== e.menuContent && (this.menuContent = e.menuContent); 93 void 0 !== e.toolBarItemBackground && (this.toolBarItemBackground = e.toolBarItemBackground); 94 void 0 !== e.itemBackground && (this.itemBackground = e.itemBackground); 95 } 96 97 updateStateVars(e) { 98 this.__toolBarList.set(e.toolBarList); 99 this.__activateIndex.reset(e.activateIndex); 100 this.__moreText.reset(e.moreText) 101 } 102 103 purgeVariableDependenciesOnElmtId(e) { 104 this.__toolBarList.purgeDependencyOnElmtId(e); 105 this.__activateIndex.purgeDependencyOnElmtId(e); 106 this.__moreText.purgeDependencyOnElmtId(e); 107 this.__menuContent.purgeDependencyOnElmtId(e); 108 this.__itemBackground.purgeDependencyOnElmtId(e); 109 } 110 111 aboutToBeDeleted() { 112 this.__toolBarList.aboutToBeDeleted(); 113 this.__activateIndex.aboutToBeDeleted(); 114 this.__moreText.aboutToBeDeleted(); 115 this.__menuContent.aboutToBeDeleted(); 116 this.__itemBackground.aboutToBeDeleted(); 117 SubscriberManager.Get().delete(this.id__()); 118 this.aboutToBeDeletedInternal(); 119 } 120 121 get toolBarList() { 122 return this.__toolBarList.get(); 123 } 124 125 get activateIndex() { 126 return this.__activateIndex.get(); 127 } 128 129 set activateIndex(e) { 130 this.__activateIndex.set(e); 131 } 132 133 get moreText() { 134 return this.__moreText.get() 135 } 136 137 set moreText(e) { 138 this.__moreText.set(e) 139 } 140 141 get menuContent() { 142 return this.__menuContent.get(); 143 } 144 145 set menuContent(e) { 146 this.__menuContent.set(e); 147 } 148 149 get itemBackground() { 150 return this.__itemBackground.get(); 151 } 152 153 set itemBackground(e) { 154 this.__itemBackground.set(e); 155 } 156 157 MoreTabBuilder(e, t = null) { 158 this.observeComponentCreation(((e, t) => { 159 ViewStackProcessor.StartGetAccessRecordingFor(e); 160 Column.create(); 161 Column.width('100%'); 162 Column.height('100%'); 163 Column.bindMenu(ObservedObject.GetRawObject(this.menuContent), { offset: { x: 5, y: -10 } }); 164 Column.padding({ left: 4, right: 4 }); 165 Column.borderRadius({ 166 id: -1, 167 type: 10002, 168 params: ['sys.float.ohos_id_corner_radius_clicked'], 169 bundleName: '', 170 moduleName: '' 171 }); 172 t || Column.pop(); 173 ViewStackProcessor.StopGetAccessRecording(); 174 })); 175 this.observeComponentCreation(((e, t) => { 176 ViewStackProcessor.StartGetAccessRecordingFor(e); 177 Image.create(PUBLIC_MORE); 178 Image.width(IMAGE_SIZE_WIDTH_HEIGHT); 179 Image.height(IMAGE_SIZE_WIDTH_HEIGHT); 180 Image.fillColor({ 181 id: -1, 182 type: 10001, 183 params: ['sys.color.ohos_id_color_toolbar_icon'], 184 bundleName: '', 185 moduleName: '' 186 }); 187 Image.margin({ top: 8, bottom: 2 }); 188 Image.objectFit(ImageFit.Contain); 189 t || Image.pop(); 190 ViewStackProcessor.StopGetAccessRecording(); 191 })); 192 this.observeComponentCreation(((e, t) => { 193 ViewStackProcessor.StartGetAccessRecordingFor(e); 194 Text.create(this.moreText); 195 Text.fontColor({ 196 id: -1, 197 type: 10001, 198 params: ['sys.color.ohos_id_color_toolbar_text'], 199 bundleName: '', 200 moduleName: '' 201 }); 202 Text.fontSize({ 203 id: -1, 204 type: 10002, 205 params: ['sys.float.ohos_id_text_size_caption'], 206 bundleName: '', 207 moduleName: '' 208 }); 209 Text.fontWeight(FontWeight.Medium); 210 t || Text.pop(); 211 ViewStackProcessor.StopGetAccessRecording(); 212 })); 213 Text.pop(); 214 Column.pop(); 215 } 216 217 TabBuilder(e, t = null) { 218 this.observeComponentCreation(((t, o) => { 219 ViewStackProcessor.StartGetAccessRecordingFor(t); 220 Column.create(); 221 Column.width('100%'); 222 Column.height('100%'); 223 Column.focusable(!(ITEM_DISABLE_STATE === this.toolBarList[e].state)); 224 Column.focusOnTouch(!(ITEM_DISABLE_STATE === this.toolBarList[e].state)); 225 Column.padding({ left: 4, right: 4 }); 226 Column.borderRadius({ 227 id: -1, 228 type: 10002, 229 params: ['sys.float.ohos_id_corner_radius_clicked'], 230 bundleName: '', 231 moduleName: '' 232 }); 233 Column.backgroundColor(ObservedObject.GetRawObject(this.itemBackground)); 234 Column.onClick((() => { 235 ITEM_DISABLE_ACTIVATE === this.toolBarList[e].state && (this.activateIndex === e ? this.activateIndex = -1 : this.activateIndex = e); 236 ITEM_DISABLE_STATE !== this.toolBarList[e].state && this.toolBarList[e].action && this.toolBarList[e].action(); 237 })); 238 Column.onHover((t => { 239 this.toolBarItemBackground[e] = t ? ITEM_DISABLE_STATE === this.toolBarList[e].state ? { 240 id: -1, 241 type: 10001, 242 params: ['sys.color.ohos_id_color_toolbar_bg'], 243 bundleName: '', 244 moduleName: '' 245 } : { 246 id: -1, 247 type: 10001, 248 params: ['sys.color.ohos_id_color_hover'], 249 bundleName: '', 250 moduleName: '' 251 } : { 252 id: -1, 253 type: 10001, 254 params: ['sys.color.ohos_id_color_toolbar_bg'], 255 bundleName: '', 256 moduleName: '' 257 }; 258 this.itemBackground = this.toolBarItemBackground[e]; 259 })); 260 ViewStackProcessor.visualState('pressed'); 261 Column.backgroundColor(ITEM_DISABLE_STATE === this.toolBarList[e].state ? this.toolBarItemBackground[e] : { 262 id: -1, 263 type: 10001, 264 params: ['sys.color.ohos_id_color_click_effect'], 265 bundleName: '', 266 moduleName: '' 267 }); 268 ViewStackProcessor.visualState('normal'); 269 Column.backgroundColor(this.toolBarItemBackground[e]); 270 ViewStackProcessor.visualState(); 271 o || Column.pop(); 272 ViewStackProcessor.StopGetAccessRecording(); 273 })); 274 this.observeComponentCreation(((t, o) => { 275 ViewStackProcessor.StartGetAccessRecordingFor(t); 276 Image.create(this.toolBarList[e].icon); 277 Image.width(IMAGE_SIZE_WIDTH_HEIGHT); 278 Image.height(IMAGE_SIZE_WIDTH_HEIGHT); 279 Image.fillColor(this.activateIndex === e && ITEM_DISABLE_STATE !== this.toolBarList[e].state ? { 280 id: -1, 281 type: 10001, 282 params: ['sys.color.ohos_id_color_text_primary_activated'], 283 bundleName: '', 284 moduleName: '' 285 } : { 286 id: -1, 287 type: 10001, 288 params: ['sys.color.ohos_id_color_primary'], 289 bundleName: '', 290 moduleName: '' 291 }); 292 Image.opacity(ITEM_DISABLE_STATE === this.toolBarList[e].state ? DISABLE_OPACITY : 1); 293 Image.margin({ top: 8, bottom: 2 }); 294 Image.objectFit(ImageFit.Contain); 295 o || Image.pop(); 296 ViewStackProcessor.StopGetAccessRecording(); 297 })); 298 this.observeComponentCreation(((t, o) => { 299 ViewStackProcessor.StartGetAccessRecordingFor(t); 300 Text.create(this.toolBarList[e].content); 301 Text.fontColor(this.activateIndex === e && ITEM_DISABLE_STATE !== this.toolBarList[e].state ? { 302 id: -1, 303 type: 10001, 304 params: ['sys.color.ohos_id_color_toolbar_text_actived'], 305 bundleName: '', 306 moduleName: '' 307 } : { 308 id: -1, 309 type: 10001, 310 params: ['sys.color.ohos_id_color_toolbar_text'], 311 bundleName: '', 312 moduleName: '' 313 }); 314 Text.fontSize({ 315 id: -1, 316 type: 10002, 317 params: ['sys.float.ohos_id_text_size_caption'], 318 bundleName: '', 319 moduleName: '' 320 }); 321 Text.maxFontSize({ 322 id: -1, 323 type: 10002, 324 params: ['sys.float.ohos_id_text_size_caption'], 325 bundleName: '', 326 moduleName: '' 327 }); 328 Text.minFontSize(TEXT_MIN_SIZE); 329 Text.fontWeight(FontWeight.Medium); 330 Text.maxLines(TEXT_MAX_LINES); 331 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 332 Text.opacity(ITEM_DISABLE_STATE === this.toolBarList[e].state ? DISABLE_OPACITY : 1); 333 o || Text.pop(); 334 ViewStackProcessor.StopGetAccessRecording(); 335 })); 336 Text.pop(); 337 Column.pop(); 338 } 339 340 refreshData() { 341 this.menuContent = []; 342 for (let e = 0; e < this.toolBarList.length; e++) { 343 if (e >= TOOLBAR_LIST_NORMORL && this.toolBarList.length > TOOLBAR_LIST_LENGTH) { 344 this.menuContent[e - TOOLBAR_LIST_NORMORL] = { 345 value: this.toolBarList[e].content, 346 action: this.toolBarList[e].action 347 }; 348 } else { 349 this.toolBarItemBackground[e] = { 350 id: -1, 351 type: 10001, 352 params: ['sys.color.ohos_id_color_toolbar_bg'], 353 bundleName: '', 354 moduleName: '' 355 }; 356 this.menuContent = []; 357 } 358 } 359 return !0; 360 } 361 362 aboutToAppear() { 363 this.refreshData(); 364 } 365 366 initialRender() { 367 this.observeComponentCreation(((e, t) => { 368 ViewStackProcessor.StartGetAccessRecordingFor(e); 369 Column.create(); 370 t || Column.pop(); 371 ViewStackProcessor.StopGetAccessRecording(); 372 })); 373 this.observeComponentCreation(((e, t) => { 374 ViewStackProcessor.StartGetAccessRecordingFor(e); 375 Divider.create(); 376 Divider.width('100%'); 377 Divider.height(1); 378 t || Divider.pop(); 379 ViewStackProcessor.StopGetAccessRecording(); 380 })); 381 this.observeComponentCreation(((e, t) => { 382 ViewStackProcessor.StartGetAccessRecordingFor(e); 383 Column.create(); 384 Column.width('100%'); 385 t || Column.pop(); 386 ViewStackProcessor.StopGetAccessRecording(); 387 })); 388 this.observeComponentCreation(((e, t) => { 389 ViewStackProcessor.StartGetAccessRecordingFor(e); 390 Tabs.create({ barPosition: BarPosition.End, controller: this.controller }); 391 Tabs.vertical(!1); 392 Tabs.constraintSize({ minHeight: 56, maxHeight: 56 }); 393 Tabs.barMode(BarMode.Fixed); 394 Tabs.onChange((e => { 395 })); 396 Tabs.width('100%'); 397 Tabs.padding({ left: this.toolBarList.length < 5 ? 24: 0, right: this.toolBarList.length < 5 ? 24: 0}) 398 Tabs.backgroundColor({ 399 id: -1, 400 type: 10001, 401 params: ['sys.color.ohos_id_color_toolbar_bg'], 402 bundleName: '', 403 moduleName: '' 404 }); 405 t || Tabs.pop(); 406 ViewStackProcessor.StopGetAccessRecording(); 407 })); 408 this.observeComponentCreation(((e, t) => { 409 ViewStackProcessor.StartGetAccessRecordingFor(e); 410 ForEach.create(); 411 this.forEachUpdateFunction(e, this.toolBarList, ((e, t) => { 412 this.observeComponentCreation(((e, o) => { 413 ViewStackProcessor.StartGetAccessRecordingFor(e); 414 If.create(); 415 this.toolBarList.length <= TOOLBAR_LIST_LENGTH ? this.ifElseBranchUpdateFunction(0, (() => { 416 this.observeComponentCreation(((e, o) => { 417 ViewStackProcessor.StartGetAccessRecordingFor(e); 418 TabContent.create(); 419 TabContent.tabBar({ 420 builder: () => { 421 this.TabBuilder.call(this, t); 422 } 423 }); 424 TabContent.enabled(!(ITEM_DISABLE_STATE === this.toolBarList[t].state)); 425 TabContent.focusOnTouch(!(ITEM_DISABLE_STATE === this.toolBarList[t].state)); 426 o || TabContent.pop(); 427 ViewStackProcessor.StopGetAccessRecording(); 428 })); 429 TabContent.pop(); 430 })) : t < TOOLBAR_LIST_NORMORL && this.ifElseBranchUpdateFunction(1, (() => { 431 this.observeComponentCreation(((e, o) => { 432 ViewStackProcessor.StartGetAccessRecordingFor(e); 433 TabContent.create(); 434 TabContent.tabBar({ 435 builder: () => { 436 this.TabBuilder.call(this, t); 437 } 438 }); 439 TabContent.enabled(!(ITEM_DISABLE_STATE === this.toolBarList[t].state)); 440 TabContent.focusOnTouch(!(ITEM_DISABLE_STATE === this.toolBarList[t].state)); 441 o || TabContent.pop(); 442 ViewStackProcessor.StopGetAccessRecording(); 443 })); 444 TabContent.pop(); 445 })); 446 o || If.pop(); 447 ViewStackProcessor.StopGetAccessRecording(); 448 })); 449 If.pop(); 450 }), void 0, !0, !1); 451 t || ForEach.pop(); 452 ViewStackProcessor.StopGetAccessRecording(); 453 })); 454 ForEach.pop(); 455 this.observeComponentCreation(((e, t) => { 456 ViewStackProcessor.StartGetAccessRecordingFor(e); 457 If.create(); 458 this.refreshData() && this.toolBarList.length > TOOLBAR_LIST_LENGTH ? this.ifElseBranchUpdateFunction(0, (() => { 459 this.observeComponentCreation(((e, t) => { 460 ViewStackProcessor.StartGetAccessRecordingFor(e); 461 TabContent.create(); 462 TabContent.tabBar({ 463 builder: () => { 464 this.MoreTabBuilder.call(this, TOOLBAR_LIST_NORMORL); 465 } 466 }); 467 t || TabContent.pop(); 468 ViewStackProcessor.StopGetAccessRecording(); 469 })); 470 TabContent.pop(); 471 })) : If.branchId(1); 472 t || If.pop(); 473 ViewStackProcessor.StopGetAccessRecording(); 474 })); 475 If.pop(); 476 Tabs.pop(); 477 Column.pop(); 478 Column.pop(); 479 } 480 481 rerender() { 482 this.updateDirtyElements(); 483 } 484} 485export default { ToolBarOptions, ToolBar };