123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the 'License'); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an 'AS IS' BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ciif (!('finalizeConstruction' in ViewPU.prototype)) { 1723b3eb3cSopenharmony_ci Reflect.set(ViewPU.prototype, 'finalizeConstruction', () => { }); 1823b3eb3cSopenharmony_ci} 1923b3eb3cSopenharmony_ciif (PUV2ViewBase.contextStack === undefined) { 2023b3eb3cSopenharmony_ci Reflect.set(PUV2ViewBase, 'contextStack', []); 2123b3eb3cSopenharmony_ci} 2223b3eb3cSopenharmony_ciconst LengthMetrics = requireNapi('arkui.node').LengthMetrics; 2323b3eb3cSopenharmony_ciconst hilog = requireNapi('ohos.hilog'); 2423b3eb3cSopenharmony_ciconst DEFAULT_MARGIN = 16; 2523b3eb3cSopenharmony_ciconst ITEM_SPACE = 4; 2623b3eb3cSopenharmony_ciconst MIN_SIZE = 24; 2723b3eb3cSopenharmony_ciconst MID_SIZE = 40; 2823b3eb3cSopenharmony_ciconst MAX_SIZE = 48; 2923b3eb3cSopenharmony_ciconst MAX_FONT_SIZE = 2; 3023b3eb3cSopenharmony_ciexport class SwipeRefresher extends ViewPU { 3123b3eb3cSopenharmony_ci constructor(u11, v11, w11, x11 = -1, y11 = undefined, z11) { 3223b3eb3cSopenharmony_ci super(u11, w11, x11, z11); 3323b3eb3cSopenharmony_ci if (typeof y11 === 'function') { 3423b3eb3cSopenharmony_ci this.paramsGenerator_ = y11; 3523b3eb3cSopenharmony_ci } 3623b3eb3cSopenharmony_ci this.__content = new SynchedPropertySimpleOneWayPU(v11.content, this, 'content'); 3723b3eb3cSopenharmony_ci this.__isLoading = new SynchedPropertySimpleOneWayPU(v11.isLoading, this, 'isLoading'); 3823b3eb3cSopenharmony_ci this.maxAppFontScale = 1; 3923b3eb3cSopenharmony_ci this.isFollowingSystemFontScale = false; 4023b3eb3cSopenharmony_ci this.minFontSize = 1.75; 4123b3eb3cSopenharmony_ci this.maxFontSize = 2; 4223b3eb3cSopenharmony_ci this.setInitiallyProvidedValue(v11); 4323b3eb3cSopenharmony_ci this.finalizeConstruction(); 4423b3eb3cSopenharmony_ci } 4523b3eb3cSopenharmony_ci setInitiallyProvidedValue(t11) { 4623b3eb3cSopenharmony_ci if (t11.content === undefined) { 4723b3eb3cSopenharmony_ci this.__content.set(''); 4823b3eb3cSopenharmony_ci } 4923b3eb3cSopenharmony_ci if (t11.isLoading === undefined) { 5023b3eb3cSopenharmony_ci this.__isLoading.set(false); 5123b3eb3cSopenharmony_ci } 5223b3eb3cSopenharmony_ci if (t11.maxAppFontScale !== undefined) { 5323b3eb3cSopenharmony_ci this.maxAppFontScale = t11.maxAppFontScale; 5423b3eb3cSopenharmony_ci } 5523b3eb3cSopenharmony_ci if (t11.isFollowingSystemFontScale !== undefined) { 5623b3eb3cSopenharmony_ci this.isFollowingSystemFontScale = t11.isFollowingSystemFontScale; 5723b3eb3cSopenharmony_ci } 5823b3eb3cSopenharmony_ci if (t11.minFontSize !== undefined) { 5923b3eb3cSopenharmony_ci this.minFontSize = t11.minFontSize; 6023b3eb3cSopenharmony_ci } 6123b3eb3cSopenharmony_ci if (t11.maxFontSize !== undefined) { 6223b3eb3cSopenharmony_ci this.maxFontSize = t11.maxFontSize; 6323b3eb3cSopenharmony_ci } 6423b3eb3cSopenharmony_ci } 6523b3eb3cSopenharmony_ci updateStateVars(s11) { 6623b3eb3cSopenharmony_ci this.__content.reset(s11.content); 6723b3eb3cSopenharmony_ci this.__isLoading.reset(s11.isLoading); 6823b3eb3cSopenharmony_ci } 6923b3eb3cSopenharmony_ci purgeVariableDependenciesOnElmtId(r11) { 7023b3eb3cSopenharmony_ci this.__content.purgeDependencyOnElmtId(r11); 7123b3eb3cSopenharmony_ci this.__isLoading.purgeDependencyOnElmtId(r11); 7223b3eb3cSopenharmony_ci } 7323b3eb3cSopenharmony_ci aboutToBeDeleted() { 7423b3eb3cSopenharmony_ci this.__content.aboutToBeDeleted(); 7523b3eb3cSopenharmony_ci this.__isLoading.aboutToBeDeleted(); 7623b3eb3cSopenharmony_ci SubscriberManager.Get().delete(this.id__()); 7723b3eb3cSopenharmony_ci this.aboutToBeDeletedInternal(); 7823b3eb3cSopenharmony_ci } 7923b3eb3cSopenharmony_ci get content() { 8023b3eb3cSopenharmony_ci return this.__content.get(); 8123b3eb3cSopenharmony_ci } 8223b3eb3cSopenharmony_ci set content(q11) { 8323b3eb3cSopenharmony_ci this.__content.set(q11); 8423b3eb3cSopenharmony_ci } 8523b3eb3cSopenharmony_ci get isLoading() { 8623b3eb3cSopenharmony_ci return this.__isLoading.get(); 8723b3eb3cSopenharmony_ci } 8823b3eb3cSopenharmony_ci set isLoading(p11) { 8923b3eb3cSopenharmony_ci this.__isLoading.set(p11); 9023b3eb3cSopenharmony_ci } 9123b3eb3cSopenharmony_ci aboutToAppear() { 9223b3eb3cSopenharmony_ci try { 9323b3eb3cSopenharmony_ci let o11 = this.getUIContext(); 9423b3eb3cSopenharmony_ci this.isFollowingSystemFontScale = o11.isFollowingSystemFontScale(); 9523b3eb3cSopenharmony_ci this.maxAppFontScale = o11.getMaxFontScale(); 9623b3eb3cSopenharmony_ci } 9723b3eb3cSopenharmony_ci catch (l11) { 9823b3eb3cSopenharmony_ci let m11 = l11.code; 9923b3eb3cSopenharmony_ci let n11 = l11.message; 10023b3eb3cSopenharmony_ci hilog.error(0x3900, 'SwipeRefresher', `Failed to init fontsizescale info, cause, code: ${m11}, message: ${n11}`); 10123b3eb3cSopenharmony_ci } 10223b3eb3cSopenharmony_ci } 10323b3eb3cSopenharmony_ci updateFontScale() { 10423b3eb3cSopenharmony_ci let j11 = this.getUIContext(); 10523b3eb3cSopenharmony_ci let k11 = j11.getHostContext()?.config?.fontSizeScale ?? 1; 10623b3eb3cSopenharmony_ci if (!this.isFollowingSystemFontScale) { 10723b3eb3cSopenharmony_ci return 1; 10823b3eb3cSopenharmony_ci } 10923b3eb3cSopenharmony_ci return Math.min(k11, this.maxAppFontScale); 11023b3eb3cSopenharmony_ci } 11123b3eb3cSopenharmony_ci initialRender() { 11223b3eb3cSopenharmony_ci PUV2ViewBase.contextStack && PUV2ViewBase.contextStack.push(this); 11323b3eb3cSopenharmony_ci this.observeComponentCreation((h11, i11) => { 11423b3eb3cSopenharmony_ci ViewStackProcessor.StartGetAccessRecordingFor(h11); 11523b3eb3cSopenharmony_ci Flex.create({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }); 11623b3eb3cSopenharmony_ci if (!i11) { 11723b3eb3cSopenharmony_ci Flex.pop(); 11823b3eb3cSopenharmony_ci } 11923b3eb3cSopenharmony_ci ViewStackProcessor.StopGetAccessRecording(); 12023b3eb3cSopenharmony_ci }); 12123b3eb3cSopenharmony_ci this.observeComponentCreation((a11, b11) => { 12223b3eb3cSopenharmony_ci ViewStackProcessor.StartGetAccessRecordingFor(a11); 12323b3eb3cSopenharmony_ci If.create(); 12423b3eb3cSopenharmony_ci if (this.isLoading) { 12523b3eb3cSopenharmony_ci this.ifElseBranchUpdateFunction(0, () => { 12623b3eb3cSopenharmony_ci this.observeComponentCreation((f11, g11) => { 12723b3eb3cSopenharmony_ci ViewStackProcessor.StartGetAccessRecordingFor(f11); 12823b3eb3cSopenharmony_ci LoadingProgress.create(); 12923b3eb3cSopenharmony_ci LoadingProgress.height(Math.min(this.updateFontScale(), MAX_FONT_SIZE) === this.maxFontSize ? MAX_SIZE : 13023b3eb3cSopenharmony_ci (Math.min(this.updateFontScale(), MAX_FONT_SIZE) === this.minFontSize ? MID_SIZE : MIN_SIZE)); 13123b3eb3cSopenharmony_ci LoadingProgress.width(Math.min(this.updateFontScale(), MAX_FONT_SIZE) === this.maxFontSize ? MAX_SIZE : 13223b3eb3cSopenharmony_ci (Math.min(this.updateFontScale(), MAX_FONT_SIZE) === this.minFontSize ? MID_SIZE : MIN_SIZE)); 13323b3eb3cSopenharmony_ci LoadingProgress.margin({ 13423b3eb3cSopenharmony_ci end: LengthMetrics.vp(ITEM_SPACE) 13523b3eb3cSopenharmony_ci }); 13623b3eb3cSopenharmony_ci if (!g11) { 13723b3eb3cSopenharmony_ci LoadingProgress.pop(); 13823b3eb3cSopenharmony_ci } 13923b3eb3cSopenharmony_ci ViewStackProcessor.StopGetAccessRecording(); 14023b3eb3cSopenharmony_ci }); 14123b3eb3cSopenharmony_ci }); 14223b3eb3cSopenharmony_ci } 14323b3eb3cSopenharmony_ci else { 14423b3eb3cSopenharmony_ci this.ifElseBranchUpdateFunction(1, () => { 14523b3eb3cSopenharmony_ci }); 14623b3eb3cSopenharmony_ci } 14723b3eb3cSopenharmony_ci if (!b11) { 14823b3eb3cSopenharmony_ci If.pop(); 14923b3eb3cSopenharmony_ci } 15023b3eb3cSopenharmony_ci ViewStackProcessor.StopGetAccessRecording(); 15123b3eb3cSopenharmony_ci }); 15223b3eb3cSopenharmony_ci If.pop(); 15323b3eb3cSopenharmony_ci this.observeComponentCreation((y10, z10) => { 15423b3eb3cSopenharmony_ci ViewStackProcessor.StartGetAccessRecordingFor(y10); 15523b3eb3cSopenharmony_ci Text.create(this.content); 15623b3eb3cSopenharmony_ci Text.fontColor({ 'id': -1, 'type': 10001, params: ['sys.color.ohos_id_color_text_secondary'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 15723b3eb3cSopenharmony_ci Text.fontSize({ 'id': -1, 'type': 10002, params: ['sys.float.ohos_id_text_size_body2'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 15823b3eb3cSopenharmony_ci Text.minFontScale(1); 15923b3eb3cSopenharmony_ci Text.maxFontScale(Math.min(this.updateFontScale(), 2)); 16023b3eb3cSopenharmony_ci Text.padding({ 16123b3eb3cSopenharmony_ci top: DEFAULT_MARGIN, 16223b3eb3cSopenharmony_ci bottom: DEFAULT_MARGIN 16323b3eb3cSopenharmony_ci }); 16423b3eb3cSopenharmony_ci if (!z10) { 16523b3eb3cSopenharmony_ci Text.pop(); 16623b3eb3cSopenharmony_ci } 16723b3eb3cSopenharmony_ci ViewStackProcessor.StopGetAccessRecording(); 16823b3eb3cSopenharmony_ci }); 16923b3eb3cSopenharmony_ci Text.pop(); 17023b3eb3cSopenharmony_ci Flex.pop(); 17123b3eb3cSopenharmony_ci PUV2ViewBase.contextStack && PUV2ViewBase.contextStack.pop(); 17223b3eb3cSopenharmony_ci } 17323b3eb3cSopenharmony_ci rerender() { 17423b3eb3cSopenharmony_ci PUV2ViewBase.contextStack && PUV2ViewBase.contextStack.push(this); 17523b3eb3cSopenharmony_ci this.updateDirtyElements(); 17623b3eb3cSopenharmony_ci PUV2ViewBase.contextStack && PUV2ViewBase.contextStack.pop(); 17723b3eb3cSopenharmony_ci } 17823b3eb3cSopenharmony_ci} 17923b3eb3cSopenharmony_ciexport default { SwipeRefresher };