1/* 2 * Copyright (c) 2024 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 Chip = requireNapi('arkui.advanced.Chip').Chip; 17const ChipSize = requireNapi('arkui.advanced.Chip').ChipSize; 18const SymbolGlyphModifier = requireNapi('arkui.modifier').SymbolGlyphModifier; 19 20if (!("finalizeConstruction" in ViewPU.prototype)) { 21 Reflect.set(ViewPU.prototype, "finalizeConstruction", () => { }); 22} 23if (PUV2ViewBase.contextStack === undefined) { 24 Reflect.set(PUV2ViewBase, "contextStack", []); 25} 26 27const noop = (selectedIndexes) => { 28}; 29const colorStops = [['rgba(0, 0, 0, 1)', 0], ['rgba(0, 0, 0, 0)', 1]]; 30const defaultTheme = { 31 itemStyle: { 32 size: ChipSize.NORMAL, 33 backgroundColor: { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_button_normal'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }, 34 fontColor: { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_text_primary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }, 35 selectedFontColor: { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_text_primary_contrary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }, 36 selectedBackgroundColor: { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_emphasize'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }, 37 fillColor: { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_secondary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }, 38 selectedFillColor: { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_text_primary_contrary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }, 39 }, 40 chipGroupSpace: { itemSpace: 8, startSpace: 16, endSpace: 16 }, 41 chipGroupPadding: { top: 14, bottom: 14 } 42}; 43const iconGroupSuffixTheme = { 44 backgroundColor: { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_button_normal'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }, 45 borderRadius: { "id": -1, "type": 10002, params: ['sys.float.ohos_id_corner_radius_tips_instant_tip'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }, 46 smallIconSize: 16, 47 normalIconSize: 24, 48 smallBackgroundSize: 28, 49 normalBackgroundSize: 36, 50 marginLeft: 8, 51 marginRight: 16, 52 fillColor: { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_primary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }, 53 defaultEffect: -1 54}; 55var ChipGroupHeight; 56(function (ChipGroupHeight) { 57 ChipGroupHeight[ChipGroupHeight["NORMAL"] = 36] = "NORMAL"; 58 ChipGroupHeight[ChipGroupHeight["SMALL"] = 28] = "SMALL"; 59})(ChipGroupHeight || (ChipGroupHeight = {})); 60function parseDimension(uiContext, value, isValid, defaultValue) { 61 if (value === void (0) || value === null) { 62 return defaultValue; 63 } 64 const resourceManager = uiContext.getHostContext()?.resourceManager; 65 if (typeof value === "object") { 66 let temp = value; 67 if (temp.type === 10002 || temp.type === 10007) { 68 if (resourceManager.getNumber(temp.id) >= 0) { 69 return value; 70 } 71 } 72 else if (temp.type === 10003) { 73 if (isValidDimensionString(resourceManager.getStringSync(temp.id))) { 74 return value; 75 } 76 } 77 } 78 else if (typeof value === "number") { 79 if (value >= 0) { 80 return value; 81 } 82 } 83 else if (typeof value === "string") { 84 if (isValid(value)) { 85 return value; 86 } 87 } 88 return defaultValue; 89} 90function isValidString(dimension, regex) { 91 const matches = dimension.match(regex); 92 if (!matches || matches.length < 3) { 93 return false; 94 } 95 const value = Number.parseFloat(matches[1]); 96 return value >= 0; 97} 98function isValidDimensionString(dimension) { 99 return isValidString(dimension, new RegExp("(-?\\d+(?:\\.\\d+)?)_?(fp|vp|px|lpx|%)?$", "i")); 100} 101function isValidDimensionNoPercentageString(dimension) { 102 return isValidString(dimension, new RegExp("(-?\\d+(?:\\.\\d+)?)_?(fp|vp|px|lpx)?$", "i")); 103} 104export class IconGroupSuffix extends ViewPU { 105 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 106 super(parent, __localStorage, elmtId, extraInfo); 107 if (typeof paramsLambda === "function") { 108 this.paramsGenerator_ = paramsLambda; 109 } 110 this.__chipSize = this.initializeConsume("chipSize", "chipSize"); 111 this.__items = new SynchedPropertyObjectOneWayPU(params.items, this, "items"); 112 this.symbolEffect = new SymbolEffect(); 113 this.setInitiallyProvidedValue(params); 114 this.finalizeConstruction(); 115 } 116 setInitiallyProvidedValue(params) { 117 if (params.items === undefined) { 118 this.__items.set([]); 119 } 120 if (params.symbolEffect !== undefined) { 121 this.symbolEffect = params.symbolEffect; 122 } 123 } 124 updateStateVars(params) { 125 this.__items.reset(params.items); 126 } 127 purgeVariableDependenciesOnElmtId(rmElmtId) { 128 this.__chipSize.purgeDependencyOnElmtId(rmElmtId); 129 this.__items.purgeDependencyOnElmtId(rmElmtId); 130 } 131 aboutToBeDeleted() { 132 this.__chipSize.aboutToBeDeleted(); 133 this.__items.aboutToBeDeleted(); 134 SubscriberManager.Get().delete(this.id__()); 135 this.aboutToBeDeletedInternal(); 136 } 137 get chipSize() { 138 return this.__chipSize.get(); 139 } 140 set chipSize(newValue) { 141 this.__chipSize.set(newValue); 142 } 143 get items() { 144 return this.__items.get(); 145 } 146 set items(newValue) { 147 this.__items.set(newValue); 148 } 149 getBackgroundSize() { 150 if (this.chipSize === ChipSize.SMALL) { 151 return iconGroupSuffixTheme.smallBackgroundSize; 152 } 153 else { 154 return iconGroupSuffixTheme.normalBackgroundSize; 155 } 156 } 157 getIconSize(val) { 158 if (val === undefined) { 159 return this.chipSize === ChipSize.SMALL ? 160 iconGroupSuffixTheme.smallIconSize : 161 iconGroupSuffixTheme.normalIconSize; 162 } 163 let value; 164 if (this.chipSize === ChipSize.SMALL) { 165 value = parseDimension(this.getUIContext(), val, isValidDimensionString, iconGroupSuffixTheme.smallIconSize); 166 } 167 else { 168 value = parseDimension(this.getUIContext(), val, isValidDimensionString, iconGroupSuffixTheme.normalIconSize); 169 } 170 return value; 171 } 172 initialRender() { 173 PUV2ViewBase.contextStack && PUV2ViewBase.contextStack.push(this); 174 this.observeComponentCreation2((elmtId, isInitialRender) => { 175 Row.create(); 176 }, Row); 177 this.observeComponentCreation2((elmtId, isInitialRender) => { 178 ForEach.create(); 179 const forEachItemGenFunction = _item => { 180 const suffixItem = _item; 181 this.observeComponentCreation2((elmtId, isInitialRender) => { 182 Button.createWithChild(); 183 Button.size({ 184 width: this.getBackgroundSize(), 185 height: this.getBackgroundSize() 186 }); 187 Button.backgroundColor(iconGroupSuffixTheme.backgroundColor); 188 Button.borderRadius(iconGroupSuffixTheme.borderRadius); 189 Button.onClick(() => { 190 if (!(suffixItem instanceof SymbolGlyphModifier)) { 191 suffixItem.action(); 192 } 193 }); 194 Button.borderRadius(iconGroupSuffixTheme.borderRadius); 195 }, Button); 196 this.observeComponentCreation2((elmtId, isInitialRender) => { 197 If.create(); 198 if (suffixItem instanceof SymbolGlyphModifier) { 199 this.ifElseBranchUpdateFunction(0, () => { 200 this.observeComponentCreation2((elmtId, isInitialRender) => { 201 SymbolGlyph.create(); 202 SymbolGlyph.fontColor([iconGroupSuffixTheme.fillColor]); 203 SymbolGlyph.fontSize(this.getIconSize()); 204 SymbolGlyph.attributeModifier.bind(this)(suffixItem); 205 SymbolGlyph.focusable(true); 206 SymbolGlyph.effectStrategy(SymbolEffectStrategy.NONE); 207 SymbolGlyph.symbolEffect(this.symbolEffect, false); 208 SymbolGlyph.symbolEffect(this.symbolEffect, iconGroupSuffixTheme.defaultEffect); 209 }, SymbolGlyph); 210 }); 211 } 212 else { 213 this.ifElseBranchUpdateFunction(1, () => { 214 this.observeComponentCreation2((elmtId, isInitialRender) => { 215 Image.create(suffixItem.icon.src); 216 Image.fillColor(iconGroupSuffixTheme.fillColor); 217 Image.size({ 218 width: this.getIconSize(suffixItem.icon?.size?.width), 219 height: this.getIconSize(suffixItem.icon?.size?.height) 220 }); 221 Image.focusable(true); 222 }, Image); 223 }); 224 } 225 }, If); 226 If.pop(); 227 Button.pop(); 228 }; 229 this.forEachUpdateFunction(elmtId, this.items || [], forEachItemGenFunction); 230 }, ForEach); 231 ForEach.pop(); 232 Row.pop(); 233 PUV2ViewBase.contextStack && PUV2ViewBase.contextStack.pop(); 234 } 235 rerender() { 236 PUV2ViewBase.contextStack && PUV2ViewBase.contextStack.push(this); 237 this.updateDirtyElements(); 238 PUV2ViewBase.contextStack && PUV2ViewBase.contextStack.pop(); 239 } 240} 241export class ChipGroup extends ViewPU { 242 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 243 super(parent, __localStorage, elmtId, extraInfo); 244 if (typeof paramsLambda === "function") { 245 this.paramsGenerator_ = paramsLambda; 246 } 247 this.__items = new SynchedPropertyObjectOneWayPU(params.items, this, "items"); 248 this.__itemStyle = new SynchedPropertyObjectOneWayPU(params.itemStyle, this, "itemStyle"); 249 this.__chipSize = new ObservedPropertyObjectPU(defaultTheme.itemStyle.size, this, "chipSize"); 250 this.addProvidedVar("chipSize", this.__chipSize, false); 251 this.__selectedIndexes = new SynchedPropertyObjectOneWayPU(params.selectedIndexes, this, "selectedIndexes"); 252 this.__multiple = new SynchedPropertySimpleOneWayPU(params.multiple, this, "multiple"); 253 this.__chipGroupSpace = new SynchedPropertyObjectOneWayPU(params.chipGroupSpace, this, "chipGroupSpace"); 254 this.suffix = undefined; 255 this.onChange = noop; 256 this.scroller = new Scroller(); 257 this.__isReachEnd = new ObservedPropertySimplePU(this.scroller.isAtEnd(), this, "isReachEnd"); 258 this.__chipGroupPadding = new SynchedPropertyObjectOneWayPU(params.chipGroupPadding, this, "chipGroupPadding"); 259 this.__isRefresh = new ObservedPropertySimplePU(true, this, "isRefresh"); 260 this.setInitiallyProvidedValue(params); 261 this.declareWatch("items", this.onItemsChange); 262 this.declareWatch("itemStyle", this.itemStyleOnChange); 263 this.declareWatch("multiple", this.onMultipleChange); 264 this.finalizeConstruction(); 265 } 266 setInitiallyProvidedValue(params) { 267 if (params.items === undefined) { 268 this.__items.set([]); 269 } 270 if (params.itemStyle === undefined) { 271 this.__itemStyle.set(defaultTheme.itemStyle); 272 } 273 if (params.chipSize !== undefined) { 274 this.chipSize = params.chipSize; 275 } 276 if (params.selectedIndexes === undefined) { 277 this.__selectedIndexes.set([0]); 278 } 279 if (params.multiple === undefined) { 280 this.__multiple.set(false); 281 } 282 if (params.chipGroupSpace === undefined) { 283 this.__chipGroupSpace.set(defaultTheme.chipGroupSpace); 284 } 285 if (params.suffix !== undefined) { 286 this.suffix = params.suffix; 287 } 288 if (params.onChange !== undefined) { 289 this.onChange = params.onChange; 290 } 291 if (params.scroller !== undefined) { 292 this.scroller = params.scroller; 293 } 294 if (params.isReachEnd !== undefined) { 295 this.isReachEnd = params.isReachEnd; 296 } 297 if (params.chipGroupPadding === undefined) { 298 this.__chipGroupPadding.set(defaultTheme.chipGroupPadding); 299 } 300 if (params.isRefresh !== undefined) { 301 this.isRefresh = params.isRefresh; 302 } 303 } 304 updateStateVars(params) { 305 this.__items.reset(params.items); 306 this.__itemStyle.reset(params.itemStyle); 307 this.__selectedIndexes.reset(params.selectedIndexes); 308 this.__multiple.reset(params.multiple); 309 this.__chipGroupSpace.reset(params.chipGroupSpace); 310 this.__chipGroupPadding.reset(params.chipGroupPadding); 311 } 312 purgeVariableDependenciesOnElmtId(rmElmtId) { 313 this.__items.purgeDependencyOnElmtId(rmElmtId); 314 this.__itemStyle.purgeDependencyOnElmtId(rmElmtId); 315 this.__chipSize.purgeDependencyOnElmtId(rmElmtId); 316 this.__selectedIndexes.purgeDependencyOnElmtId(rmElmtId); 317 this.__multiple.purgeDependencyOnElmtId(rmElmtId); 318 this.__chipGroupSpace.purgeDependencyOnElmtId(rmElmtId); 319 this.__isReachEnd.purgeDependencyOnElmtId(rmElmtId); 320 this.__chipGroupPadding.purgeDependencyOnElmtId(rmElmtId); 321 this.__isRefresh.purgeDependencyOnElmtId(rmElmtId); 322 } 323 aboutToBeDeleted() { 324 this.__items.aboutToBeDeleted(); 325 this.__itemStyle.aboutToBeDeleted(); 326 this.__chipSize.aboutToBeDeleted(); 327 this.__selectedIndexes.aboutToBeDeleted(); 328 this.__multiple.aboutToBeDeleted(); 329 this.__chipGroupSpace.aboutToBeDeleted(); 330 this.__isReachEnd.aboutToBeDeleted(); 331 this.__chipGroupPadding.aboutToBeDeleted(); 332 this.__isRefresh.aboutToBeDeleted(); 333 SubscriberManager.Get().delete(this.id__()); 334 this.aboutToBeDeletedInternal(); 335 } 336 get items() { 337 return this.__items.get(); 338 } 339 set items(newValue) { 340 this.__items.set(newValue); 341 } 342 get itemStyle() { 343 return this.__itemStyle.get(); 344 } 345 set itemStyle(newValue) { 346 this.__itemStyle.set(newValue); 347 } 348 get chipSize() { 349 return this.__chipSize.get(); 350 } 351 set chipSize(newValue) { 352 this.__chipSize.set(newValue); 353 } 354 get selectedIndexes() { 355 return this.__selectedIndexes.get(); 356 } 357 set selectedIndexes(newValue) { 358 this.__selectedIndexes.set(newValue); 359 } 360 get multiple() { 361 return this.__multiple.get(); 362 } 363 set multiple(newValue) { 364 this.__multiple.set(newValue); 365 } 366 get chipGroupSpace() { 367 return this.__chipGroupSpace.get(); 368 } 369 set chipGroupSpace(newValue) { 370 this.__chipGroupSpace.set(newValue); 371 } 372 get isReachEnd() { 373 return this.__isReachEnd.get(); 374 } 375 set isReachEnd(newValue) { 376 this.__isReachEnd.set(newValue); 377 } 378 get chipGroupPadding() { 379 return this.__chipGroupPadding.get(); 380 } 381 set chipGroupPadding(newValue) { 382 this.__chipGroupPadding.set(newValue); 383 } 384 get isRefresh() { 385 return this.__isRefresh.get(); 386 } 387 set isRefresh(newValue) { 388 this.__isRefresh.set(newValue); 389 } 390 onItemsChange() { 391 this.isRefresh = !this.isRefresh; 392 } 393 onMultipleChange() { 394 this.selectedIndexes = this.getSelectedIndexes(); 395 } 396 itemStyleOnChange() { 397 this.chipSize = this.getChipSize(); 398 } 399 aboutToAppear() { 400 this.itemStyleOnChange(); 401 } 402 getChipSize() { 403 if (this.itemStyle && this.itemStyle.size) { 404 if (typeof this.itemStyle.size === 'object') { 405 if (!this.itemStyle.size.width || !this.itemStyle.size.height || !this.itemStyle.size) { 406 return defaultTheme.itemStyle.size; 407 } 408 } 409 return this.itemStyle.size; 410 } 411 return defaultTheme.itemStyle.size; 412 } 413 getFontColor() { 414 if (this.itemStyle && this.itemStyle.fontColor) { 415 if (typeof this.itemStyle.fontColor === 'object') { 416 let temp = this.itemStyle.fontColor; 417 if (temp == undefined || temp == null) { 418 return defaultTheme.itemStyle.fontColor; 419 } 420 if (temp.type === 10001) { 421 return this.itemStyle.fontColor; 422 } 423 return defaultTheme.itemStyle.fontColor; 424 } 425 return this.itemStyle.fontColor; 426 } 427 return defaultTheme.itemStyle.fontColor; 428 } 429 getSelectedFontColor() { 430 if (this.itemStyle && this.itemStyle.selectedFontColor) { 431 if (typeof this.itemStyle.selectedFontColor === 'object') { 432 let temp = this.itemStyle.selectedFontColor; 433 if (temp == undefined || temp == null) { 434 return defaultTheme.itemStyle.selectedFontColor; 435 } 436 if (temp.type === 10001) { 437 return this.itemStyle.selectedFontColor; 438 } 439 return defaultTheme.itemStyle.selectedFontColor; 440 } 441 return this.itemStyle.selectedFontColor; 442 } 443 return defaultTheme.itemStyle.selectedFontColor; 444 } 445 getFillColor() { 446 if (this.itemStyle && this.itemStyle.fontColor) { 447 return this.itemStyle.fontColor; 448 } 449 return defaultTheme.itemStyle.fillColor; 450 } 451 getSelectedFillColor() { 452 if (this.itemStyle && this.itemStyle.selectedFontColor) { 453 return this.itemStyle.selectedFontColor; 454 } 455 return defaultTheme.itemStyle.selectedFillColor; 456 } 457 getBackgroundColor() { 458 if (this.itemStyle && this.itemStyle.backgroundColor) { 459 if (typeof this.itemStyle.backgroundColor === 'object') { 460 let temp = this.itemStyle.backgroundColor; 461 if (temp == undefined || temp == null) { 462 return defaultTheme.itemStyle.backgroundColor; 463 } 464 if (temp.type === 10001) { 465 return this.itemStyle.backgroundColor; 466 } 467 return defaultTheme.itemStyle.backgroundColor; 468 } 469 return this.itemStyle.backgroundColor; 470 } 471 return defaultTheme.itemStyle.backgroundColor; 472 } 473 getSelectedBackgroundColor() { 474 if (this.itemStyle && this.itemStyle.selectedBackgroundColor) { 475 if (typeof this.itemStyle.selectedBackgroundColor === 'object') { 476 let temp = this.itemStyle.selectedBackgroundColor; 477 if (temp == undefined || temp == null) { 478 return defaultTheme.itemStyle.selectedBackgroundColor; 479 } 480 if (temp.type === 10001) { 481 return this.itemStyle.selectedBackgroundColor; 482 } 483 return defaultTheme.itemStyle.selectedBackgroundColor; 484 } 485 return this.itemStyle.selectedBackgroundColor; 486 } 487 return defaultTheme.itemStyle.selectedBackgroundColor; 488 } 489 getSelectedIndexes() { 490 let temp = []; 491 temp = (this.selectedIndexes ?? [0]).filter((element, index, array) => { 492 return (element >= 0 && 493 element % 1 == 0 && 494 element != null && 495 element != undefined && 496 array.indexOf(element) === index && 497 element < (this.items || []).length); 498 }); 499 if (temp.length == 0) { 500 temp = [0]; 501 } 502 return temp; 503 } 504 isMultiple() { 505 return this.multiple ?? false; 506 } 507 getChipGroupItemSpace() { 508 if (this.chipGroupSpace == undefined) { 509 return defaultTheme.chipGroupSpace.itemSpace; 510 } 511 return parseDimension(this.getUIContext(), this.chipGroupSpace.itemSpace, isValidDimensionNoPercentageString, defaultTheme.chipGroupSpace.itemSpace); 512 } 513 getChipGroupStartSpace() { 514 if (this.chipGroupSpace == undefined) { 515 return defaultTheme.chipGroupSpace.startSpace; 516 } 517 return parseDimension(this.getUIContext(), this.chipGroupSpace.startSpace, isValidDimensionNoPercentageString, defaultTheme.chipGroupSpace.startSpace); 518 } 519 getChipGroupEndSpace() { 520 if (this.chipGroupSpace == undefined) { 521 return defaultTheme.chipGroupSpace.endSpace; 522 } 523 return parseDimension(this.getUIContext(), this.chipGroupSpace.endSpace, isValidDimensionNoPercentageString, defaultTheme.chipGroupSpace.endSpace); 524 } 525 getOnChange() { 526 return this.onChange ?? noop; 527 } 528 isSelected(itemIndex) { 529 if (!this.isMultiple()) { 530 return itemIndex == this.getSelectedIndexes()[0]; 531 } 532 else { 533 return this.getSelectedIndexes().some((element, index, array) => { 534 return (element == itemIndex); 535 }); 536 } 537 } 538 getChipGroupHeight() { 539 if (typeof this.chipSize === 'string') { 540 if (this.chipSize === ChipSize.NORMAL) { 541 return ChipGroupHeight.NORMAL; 542 } 543 else { 544 return ChipGroupHeight.SMALL; 545 } 546 } 547 else if (typeof this.chipSize === 'object') { 548 return this.chipSize.height; 549 } 550 else { 551 return ChipGroupHeight.NORMAL; 552 } 553 } 554 getPaddingTop() { 555 if (!this.chipGroupPadding || !this.chipGroupPadding.top) { 556 return defaultTheme.chipGroupPadding.top; 557 } 558 return parseDimension(this.getUIContext(), this.chipGroupPadding.top, isValidDimensionNoPercentageString, defaultTheme.chipGroupPadding.top); 559 } 560 getPaddingBottom() { 561 if (!this.chipGroupPadding || !this.chipGroupPadding.bottom) { 562 return defaultTheme.chipGroupPadding.bottom; 563 } 564 return parseDimension(this.getUIContext(), this.chipGroupPadding.bottom, isValidDimensionNoPercentageString, defaultTheme.chipGroupPadding.bottom); 565 } 566 initialRender() { 567 PUV2ViewBase.contextStack && PUV2ViewBase.contextStack.push(this); 568 this.observeComponentCreation2((elmtId, isInitialRender) => { 569 Row.create(); 570 Row.align(Alignment.End); 571 Row.width("100%"); 572 Row.height(this.getChipGroupHeight() + this.getPaddingTop() + this.getPaddingBottom()); 573 Row.padding({ top: this.getPaddingTop(), bottom: this.getPaddingBottom() }); 574 }, Row); 575 this.observeComponentCreation2((elmtId, isInitialRender) => { 576 Stack.create(); 577 Stack.height(this.getChipGroupHeight() + this.getPaddingTop() + this.getPaddingBottom()); 578 Stack.layoutWeight(1); 579 Stack.blendMode(BlendMode.SRC_OVER, BlendApplyType.OFFSCREEN); 580 Stack.alignContent(Alignment.End); 581 }, Stack); 582 this.observeComponentCreation2((elmtId, isInitialRender) => { 583 Scroll.create(this.scroller); 584 Scroll.scrollable(ScrollDirection.Horizontal); 585 Scroll.scrollBar(BarState.Off); 586 Scroll.align(Alignment.Start); 587 Scroll.width('100%'); 588 Scroll.clip(false); 589 Scroll.onScroll(() => { 590 this.isReachEnd = this.scroller.isAtEnd(); 591 }); 592 }, Scroll); 593 this.observeComponentCreation2((elmtId, isInitialRender) => { 594 Row.create({ space: this.getChipGroupItemSpace() }); 595 Row.padding({ left: this.getChipGroupStartSpace(), 596 right: this.getChipGroupEndSpace() }); 597 Row.constraintSize({ minWidth: '100%' }); 598 }, Row); 599 this.observeComponentCreation2((elmtId, isInitialRender) => { 600 ForEach.create(); 601 const forEachItemGenFunction = (_item, index) => { 602 const chipItem = _item; 603 this.observeComponentCreation2((elmtId, isInitialRender) => { 604 If.create(); 605 if (chipItem) { 606 this.ifElseBranchUpdateFunction(0, () => { 607 Chip.bind(this)(makeBuilderParameterProxy("Chip", { prefixIcon: () => ({ 608 src: chipItem.prefixIcon?.src ?? "", 609 size: chipItem.prefixIcon?.size ?? undefined, 610 fillColor: this.getFillColor(), 611 activatedFillColor: this.getSelectedFillColor() 612 }), prefixSymbol: () => chipItem?.prefixSymbol, label: () => ({ 613 text: chipItem?.label?.text ?? " ", 614 fontColor: this.getFontColor(), 615 activatedFontColor: this.getSelectedFontColor(), 616 }), suffixIcon: () => ({ 617 src: chipItem.suffixIcon?.src ?? "", 618 size: chipItem.suffixIcon?.size ?? undefined, 619 fillColor: this.getFillColor(), 620 activatedFillColor: this.getSelectedFillColor() 621 }), suffixSymbol: () => chipItem?.suffixSymbol, allowClose: () => chipItem.allowClose ?? false, enabled: () => true, activated: () => this.isSelected(index), backgroundColor: () => this.getBackgroundColor(), size: () => this.getChipSize(), activatedBackgroundColor: () => this.getSelectedBackgroundColor(), onClicked: () => () => { 622 if (this.isSelected(index)) { 623 if (!(!this.isMultiple())) { 624 if (this.getSelectedIndexes().length > 1) { 625 this.selectedIndexes.splice(this.selectedIndexes.indexOf(index), 1); 626 } 627 } 628 } 629 else { 630 if (!this.selectedIndexes || this.selectedIndexes.length === 0) { 631 this.selectedIndexes = this.getSelectedIndexes(); 632 } 633 if (!this.isMultiple()) { 634 this.selectedIndexes = []; 635 } 636 this.selectedIndexes.push(index); 637 } 638 this.getOnChange()(this.getSelectedIndexes()); 639 } })); 640 }); 641 } 642 else { 643 this.ifElseBranchUpdateFunction(1, () => { 644 }); 645 } 646 }, If); 647 If.pop(); 648 }; 649 this.forEachUpdateFunction(elmtId, this.items || [], forEachItemGenFunction, () => { 650 return JSON.stringify(this.isRefresh); 651 }, true, false); 652 }, ForEach); 653 ForEach.pop(); 654 Row.pop(); 655 Scroll.pop(); 656 this.observeComponentCreation2((elmtId, isInitialRender) => { 657 If.create(); 658 if (this.suffix && !this.isReachEnd) { 659 this.ifElseBranchUpdateFunction(0, () => { 660 this.observeComponentCreation2((elmtId, isInitialRender) => { 661 Stack.create(); 662 Stack.width(iconGroupSuffixTheme.normalBackgroundSize); 663 Stack.height(this.getChipGroupHeight()); 664 Stack.linearGradient({ angle: 90, colors: colorStops }); 665 Stack.blendMode(BlendMode.DST_IN, BlendApplyType.OFFSCREEN); 666 Stack.hitTestBehavior(HitTestMode.None); 667 }, Stack); 668 Stack.pop(); 669 }); 670 } 671 else { 672 this.ifElseBranchUpdateFunction(1, () => { 673 }); 674 } 675 }, If); 676 If.pop(); 677 Stack.pop(); 678 this.observeComponentCreation2((elmtId, isInitialRender) => { 679 If.create(); 680 if (this.suffix) { 681 this.ifElseBranchUpdateFunction(0, () => { 682 this.observeComponentCreation2((elmtId, isInitialRender) => { 683 Row.create(); 684 Row.padding({ left: iconGroupSuffixTheme.marginLeft, 685 right: iconGroupSuffixTheme.marginRight 686 }); 687 }, Row); 688 this.suffix.bind(this)(); 689 Row.pop(); 690 }); 691 } 692 else { 693 this.ifElseBranchUpdateFunction(1, () => { 694 }); 695 } 696 }, If); 697 If.pop(); 698 Row.pop(); 699 PUV2ViewBase.contextStack && PUV2ViewBase.contextStack.pop(); 700 } 701 rerender() { 702 PUV2ViewBase.contextStack && PUV2ViewBase.contextStack.push(this); 703 this.updateDirtyElements(); 704 PUV2ViewBase.contextStack && PUV2ViewBase.contextStack.pop(); 705 } 706} 707 708export default { 709 ChipGroup, 710 IconGroupSuffix 711} 712