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 LOADINGPROGRESS_SIZE = 24; 17const DEFAULT_MARGIN = 16; 18const ITEM_SPACE = 4; 19 20export class SwipeRefresher extends ViewPU { 21 constructor(e, t, o, s = -1) { 22 super(e, o, s); 23 this.__content = new SynchedPropertySimpleOneWayPU(t.content, this, "content"); 24 this.__isLoading = new SynchedPropertySimpleOneWayPU(t.isLoading, this, "isLoading"); 25 this.setInitiallyProvidedValue(t) 26 } 27 28 setInitiallyProvidedValue(e) { 29 void 0 !== e.content ? this.__content.set(e.content) : this.__content.set(null); 30 void 0 !== e.isLoading ? this.__isLoading.set(e.isLoading) : this.__isLoading.set(!1) 31 } 32 33 updateStateVars(e) { 34 this.__content.reset(e.content); 35 this.__isLoading.reset(e.isLoading) 36 } 37 38 purgeVariableDependenciesOnElmtId(e) { 39 this.__content.purgeDependencyOnElmtId(e); 40 this.__isLoading.purgeDependencyOnElmtId(e) 41 } 42 43 aboutToBeDeleted() { 44 this.__content.aboutToBeDeleted(); 45 this.__isLoading.aboutToBeDeleted(); 46 SubscriberManager.Get().delete(this.id__()); 47 this.aboutToBeDeletedInternal() 48 } 49 50 get content() { 51 return this.__content.get() 52 } 53 54 set content(e) { 55 this.__content.set(e) 56 } 57 58 get isLoading() { 59 return this.__isLoading.get() 60 } 61 62 set isLoading(e) { 63 this.__isLoading.set(e) 64 } 65 66 initialRender() { 67 this.observeComponentCreation(((e, t) => { 68 ViewStackProcessor.StartGetAccessRecordingFor(e); 69 Flex.create({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }); 70 Flex.margin({ top: 16, bottom: 16 }); 71 t || Flex.pop(); 72 ViewStackProcessor.StopGetAccessRecording() 73 })); 74 this.observeComponentCreation(((e, t) => { 75 ViewStackProcessor.StartGetAccessRecordingFor(e); 76 If.create(); 77 this.isLoading ? this.ifElseBranchUpdateFunction(0, (() => { 78 this.observeComponentCreation(((e, t) => { 79 ViewStackProcessor.StartGetAccessRecordingFor(e); 80 LoadingProgress.create(); 81 LoadingProgress.height(24); 82 LoadingProgress.width(24); 83 LoadingProgress.margin({ right: 4 }); 84 t || LoadingProgress.pop(); 85 ViewStackProcessor.StopGetAccessRecording() 86 })) 87 })) : If.branchId(1); 88 t || If.pop(); 89 ViewStackProcessor.StopGetAccessRecording() 90 })); 91 If.pop(); 92 this.observeComponentCreation(((e, t) => { 93 ViewStackProcessor.StartGetAccessRecordingFor(e); 94 Text.create(this.content); 95 Text.fontColor({ 96 id: -1, 97 type: 10001, 98 params: ["sys.color.ohos_id_color_text_secondary"], 99 bundleName: "", 100 moduleName: "" 101 }); 102 Text.fontSize({ 103 id: -1, 104 type: 10002, 105 params: ["sys.float.ohos_id_text_size_body2"], 106 bundleName: "", 107 moduleName: "" 108 }); 109 t || Text.pop(); 110 ViewStackProcessor.StopGetAccessRecording() 111 })); 112 Text.pop(); 113 Flex.pop() 114 } 115 116 rerender() { 117 this.updateDirtyElements() 118 } 119}